I'm relatively new to FreeCAD and this is my first post on the form. I'm looking to learn so let me know if I'm missing something.
I'm doing most of my work with python scripting and so far it's going great. However I'm having a very strange issue with part translation in one of my featurePython parts.
Here's the execute function from its class:
Code: Select all
def execute(self, obj):
dx = HEAD_DIA_8_32+3
dy = obj.MountHoleDistance.Value + CLR_DIA_8_32*2 + 2
dz = HEAD_DZ_8_32+3
part = Part.makeBox(dx, dy, dz)
part.translate(App.Vector(-dx/2, -dy/2, -dz))
for i in part.Edges:
if i.tangentAt(i.FirstParameter) == App.Vector(0, 0, 1):
part = part.makeFillet(4, [i])
temp = Part.makeCylinder(CLR_DIA_8_32/2, dz-HEAD_DZ_8_32, App.Vector(0, 0, 0), App.Vector(0, 0, -1))
temp = temp.fuse(Part.makeCylinder(HEAD_DIA_8_32/2, HEAD_DZ_8_32, App.Vector(0, 0, HEAD_DZ_8_32-dz), App.Vector(0, 0, -1)))
part = part.cut(temp)
temp.rotate(App.Vector(0, 0, -dz/2), App.Vector(0, 1, 0), 180)
temp.translate(App.Vector(0, -obj.MountHoleDistance.Value/2, 0))
part = part.cut(temp)
temp.translate(App.Vector(0, obj.MountHoleDistance.Value, 0))
part = part.cut(temp)
part.translate(App.Vector(5, 5, 5))
obj.Shape = part
I've done a fair bit of testing around to figure out exactly what works and what doesn't. If I put that command up one line above the cut command, or if I put something like the for loop under it it works.
If I simplify the script to just the makeBox and translate command it works, but if I add back and of the cut commands or the for loop it doesn't.
So this works as expected:
Code: Select all
def execute(self, obj):
dx = HEAD_DIA_8_32+3
dy = obj.MountHoleDistance.Value + CLR_DIA_8_32*2 + 2
dz = HEAD_DZ_8_32+3
part = Part.makeBox(dx, dy, dz)
part.translate(App.Vector(-dx/2, -dy/2, -dz))
part.translate(App.Vector(5, 5, 5))
obj.Shape = part
Code: Select all
def execute(self, obj):
dx = HEAD_DIA_8_32+3
dy = obj.MountHoleDistance.Value + CLR_DIA_8_32*2 + 2
dz = HEAD_DZ_8_32+3
part = Part.makeBox(dx, dy, dz)
part.translate(App.Vector(-dx/2, -dy/2, -dz))
temp = Part.makeCylinder(CLR_DIA_8_32/2, dz-HEAD_DZ_8_32, App.Vector(0, 0, 0), App.Vector(0, 0, -1))
temp = temp.fuse(Part.makeCylinder(HEAD_DIA_8_32/2, HEAD_DZ_8_32, App.Vector(0, 0, HEAD_DZ_8_32-dz), App.Vector(0, 0, -1)))
part = part.cut(temp)
part.translate(App.Vector(5, 5, 5))
obj.Shape = part