This is more your line of expertise, but I wonder if it is worth linking this tutorial to pages with scripts that will create the object?
This purely topological:
Code: Select all
import Part
from FreeCAD import Vector as V3
doc = App.ActiveDocument
length = 53
width = 26
height = 26
topoffset = 5
notchdepth = 5
notchlength = 11
side_height = 16.7
side_length = 7
holelength = 17
holeslantbtm = 7
holeslantheight = 17
#side profile
p1 = V3(0, 0, 0) #origin
p2 = V3(0, 0, height)
p3 = V3(0, -topoffset, height)
p4 = V3(0, -width, 0)
side = Part.makePolygon([p1, p2, p3, p4, p1])
block = Part.Face(side).extrude(V3(length/2, 0 ,0))
#Part.show(block)
#side rectangles
s1 = V3(length/2, 0, 0)
s2 = V3(length/2, 0, side_height)
s3 = V3(length/2, -width, side_height)
s4 = V3(length/2, -width, 0)
side1 = Part.makePolygon([s1, s2, s3, s4, s1])
side1block = Part.Face(side1).extrude(V3(-side_length, 0, 0))
#Part.show(side1block)
n1 = V3(length/2, 0, height)
n2 = n1 - V3(notchlength, 0, 0)
n3 = n2 - V3(0, 0, notchdepth)
n4 = n1 - V3(0, 0, notchdepth)
side2 = Part.makePolygon([n1, n2, n3, n4, n1])
side2block = Part.Face(side2).extrude(V3(0, -width, 0))
#Part.show(side2block)
slantdir = (p3 - p4).normalize()
h1 = p4 + holeslantbtm * slantdir
h2 = h1 + holeslantheight * slantdir
h3 = h2 - V3(0, h2.y, 0)
h4 = h1 - V3(0, h1.y, 0)
side3 = Part.makePolygon([h1, h2, h3, h4, h1])
side3block = Part.Face(side3).extrude(V3(holelength/2, 0, 0))
#Part.show(side3block)
halffinal = (block.fuse(side1block)).cut(side2block.fuse(side3block)) #combine pieces
reflx = App.Matrix()
reflx.scale(-1, 1, 1) #reflection in YZ plane
reflected =halffinal.transformGeometry(reflx)
final = halffinal.fuse(reflected)
Part.show(final,"PDTutorial")
Code: Select all
import Part, FreeCAD, FreeCADGui
from FreeCAD import Vector as V3
from FreeCAD import Units
import pivy
from pivy import coin
class PDTutorial:
def __init__(self, obj):
self.Type = 'PDTutorialObject'
obj.addProperty("App::PropertyLength","Length","PDTutorial","Length of the object").Length = 53
obj.addProperty("App::PropertyLength","Width","PDTutorial","Width of the object").Width = 26
obj.addProperty("App::PropertyLength","Height","PDTutorial","Height of the object").Height = 26
obj.addProperty("App::PropertyLength","TopWidth","PDTutorial","Width of the object top").TopWidth = 5
obj.addProperty("App::PropertyLength","NotchDepth","PDTutorial","Depth of top corner notch").NotchDepth = 5
obj.addProperty("App::PropertyLength","NotchLength","PDTutorial","Length of top corner notch").NotchLength = 11
obj.addProperty("App::PropertyLength","SideHeight","PDTutorial","Height of side block").SideHeight = 16.7
obj.addProperty("App::PropertyLength","SideLength","PDTutorial","Length of side block").SideLength = 7
obj.addProperty("App::PropertyLength","HoleLength","PDTutorial","Length of central hole").HoleLength = 17
obj.addProperty("App::PropertyLength","HoleSlantBottom","PDTutorial","Central hole from bottom edge").HoleSlantBottom = 7
obj.addProperty("App::PropertyLength","HoleSlantHeight","PDTutorial","Slant height of central hole").HoleSlantHeight = 17
obj.Proxy = self
def execute(self, fp):
#doc = App.ActiveDocument
length = fp.Length
width = fp.Width
height = fp.Height
topoffset = fp.TopWidth
notchdepth = fp.NotchDepth
notchlength = fp.NotchLength
side_height = fp.SideHeight
side_length = fp.SideLength
holelength = fp.HoleLength
holeslantbtm = fp.HoleSlantBottom
holeslantheight = fp.HoleSlantHeight
#side profile
p1 = V3(0, 0, 0) #origin
p2 = V3(0, 0, height)
p3 = V3(0, -topoffset, height)
p4 = V3(0, -width, 0)
side = Part.makePolygon([p1, p2, p3, p4, p1])
block = Part.Face(side).extrude(V3(length/2, 0 ,0))
#Part.show(block)
#side rectangles
s1 = V3(length/2, 0, 0)
s2 = V3(length/2, 0, side_height)
s3 = V3(length/2, -width, side_height)
s4 = V3(length/2, -width, 0)
side1 = Part.makePolygon([s1, s2, s3, s4, s1])
side1block = Part.Face(side1).extrude(V3(-side_length, 0, 0))
#Part.show(side1block)
n1 = V3(length/2, 0, height)
n2 = n1 - V3(notchlength, 0, 0)
n3 = n2 - V3(0, 0, notchdepth)
n4 = n1 - V3(0, 0, notchdepth)
side2 = Part.makePolygon([n1, n2, n3, n4, n1])
side2block = Part.Face(side2).extrude(V3(0, -width, 0))
#Part.show(side2block)
slantdir = (p3 - p4).normalize()
h1 = p4 + holeslantbtm.Value * slantdir
h2 = h1 + holeslantheight.Value * slantdir
h3 = h2 - V3(0, h2.y, 0)
h4 = h1 - V3(0, h1.y, 0)
side3 = Part.makePolygon([h1, h2, h3, h4, h1])
side3block = Part.Face(side3).extrude(V3(holelength/2, 0, 0))
#Part.show(side3block)
halffinal = (block.fuse(side1block)).cut(side2block.fuse(side3block)) #combine pieces
reflx = App.Matrix()
reflx.scale(-1, 1, 1) #reflection in YZ plane
reflected =halffinal.transformGeometry(reflx)
final = halffinal.fuse(reflected)
#Part.show(final,"PDTutorial")
fp.Shape = final
doc = FreeCAD.ActiveDocument
a=doc.addObject("Part::FeaturePython","PDTutorial")
PDTutorial(a)
a.ViewObject.Proxy = 0
doc.recompute()