Last active
September 23, 2024 06:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
import Part | |
import math as mt | |
from FreeCAD import Base | |
from FreeCAD import Gui | |
def PerfSheet(L,H,W,R,Type="circle", s=1/5): | |
HoleSK=App.ActiveDocument.addObject('Sketcher::SketchObject','SheetPerforationHoles') | |
HoleSK.Placement = App.Placement(App.Vector(0.000000,0.000000,0.000000),App.Rotation(0.000000,0.000000,0.000000,1.000000)) | |
SheetSK=App.ActiveDocument.addObject('Sketcher::SketchObject','SheetBase') | |
SheetSK.Placement = App.Placement(App.Vector(0.000000,0.000000,0.000000),App.Rotation(0.000000,0.000000,0.000000,1.000000)) | |
SheetSK.addGeometry(Part.Line(App.Vector(0,0,0),App.Vector(0,H,0))) | |
SheetSK.addGeometry(Part.Line(App.Vector(0,H,0),App.Vector(L,H,0))) | |
SheetSK.addGeometry(Part.Line(App.Vector(L,H,0),App.Vector(L,0,0))) | |
SheetSK.addGeometry(Part.Line(App.Vector(L,0,0),App.Vector(0,0,0))) | |
e = R*s | |
X_number = int( mt.ceil(L / (e+2*R) )) | |
Y_number = int( mt.ceil(H / (e+2*R) )) | |
if Type=="circle": | |
Step_X =( e + 2*R ) | |
Step_Y = Step_X | |
for i in range( X_number+1): | |
PositionX = Step_X*i | |
if i % 2 != 0: #This creates zig-zag pattern | |
Y_Zero = Step_Y*0.5 | |
else: | |
Y_Zero = 0 | |
for n in range( Y_number+1): | |
PositionY = Step_Y*n+Y_Zero | |
HoleSK.addGeometry(Part.Circle(App.Vector(PositionX, PositionY, 0), App.Vector(0,0,1),R)) | |
if Type=="square": | |
Step_X =( e + 2*R ) | |
Step_Y = Step_X | |
Cosine = mt.cos(mt.radians(45)) | |
Sine = mt.cos(mt.radians(45)) | |
for i in range( X_number + 1 ): | |
PositionX = Step_X*i | |
for n in range( Y_number + 1): | |
PositionY = Step_Y*n | |
A = App.Vector(PositionX + R, PositionY - R, 0) | |
B = App.Vector(PositionX + R, PositionY + R, 0) | |
C = App.Vector(PositionX - R, PositionY + R, 0) | |
D = App.Vector(PositionX - R, PositionY - R, 0) | |
HoleSK.addGeometry(Part.Line(A,B)) | |
HoleSK.addGeometry(Part.Line(B,C)) | |
HoleSK.addGeometry(Part.Line(C,D)) | |
HoleSK.addGeometry(Part.Line(D,A)) | |
if Type=="hexagon": | |
Step_X =( e + 2*mt.cos(mt.radians(30))*R ) | |
Step_Y = ( e + 2*R ) | |
for i in range( X_number+1): | |
PositionX = Step_X*i | |
if i % 2 != 0: #This creates zig-zag pattern | |
Y_Zero = Step_Y*0.5 | |
else: | |
Y_Zero = 0 | |
for n in range( Y_number+1): | |
PositionY = Step_Y*n+Y_Zero | |
#build hexagon | |
#Points | |
Cosine = mt.cos(mt.radians(60)) | |
Sine = mt.sin(mt.radians(60)) | |
A = App.Vector(PositionX + R, PositionY, 0) | |
B = App.Vector(PositionX + R*Cosine, PositionY + R*Sine, 0) | |
C = App.Vector(PositionX - R*Cosine, PositionY + R*Sine, 0) | |
D = App.Vector(PositionX - R, PositionY, 0) | |
E = App.Vector(PositionX - R*Cosine, PositionY - R*Sine, 0) | |
F = App.Vector(PositionX + R*Cosine, PositionY - R*Sine, 0) | |
HoleSK.addGeometry(Part.Line(A,B)) | |
HoleSK.addGeometry(Part.Line(B,C)) | |
HoleSK.addGeometry(Part.Line(C,D)) | |
HoleSK.addGeometry(Part.Line(D,E)) | |
HoleSK.addGeometry(Part.Line(E,F)) | |
HoleSK.addGeometry(Part.Line(F,A)) | |
PerfS = App.ActiveDocument.addObject("PartDesign::Pad","holes") | |
PerfS.Sketch = HoleSK | |
PerfS.Length = W | |
SheetS = App.ActiveDocument.addObject("PartDesign::Pad","BaseSheet") | |
SheetS.Sketch = SheetSK | |
SheetS.Length = W | |
PerforatedSheet = App.ActiveDocument.addObject("Part::Cut", "PerforatedSheet") | |
PerforatedSheet.Base = SheetS | |
PerforatedSheet.Tool = PerfS | |
HoleSKguiname = HoleSK.Label | |
Gui.ActiveDocument.getObject(HoleSKguiname).Visibility = False | |
SheetSKguiname = SheetSK.Label | |
Gui.ActiveDocument.getObject(SheetSKguiname).Visibility = False | |
App.ActiveDocument.recompute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment