Depending on the parameters I use, the code sometimes produces the correct model, other times the BRep screws
up. I can't find a pattern to the failure, so I wrote a test program that loops over the parameters. It produces a random
pattern of failure such that I suspect a serious bug (or bugs) in the system. I'm using 0.19.
Are there any workarounds for now?
The code, and one part of the table of success/failures, follows:-
Code: Select all
import Part
from FreeCAD import Base
from FreeCAD import Vector
Delta = 1.0
def CentredBox ( Length, Width, Height, Offset=Vector(0,0,0) ) :
Box = Part.makeBox ( Length, Width, Height, Vector ( -Length/2, -Width/2, -Height/2 ) + Offset )
return Box
def CentredCylinder ( Radius, Height, Offset=Vector(0,0,0) ) :
return Part.makeCylinder ( Radius, Height, Vector ( 0, 0, -Height/2 ) + Offset )
def CreateMold ( StraightLength, StraightRadius, SideLength, SideRadius, FilletRadius ) :
TubeLength = SideLength - StraightRadius
MainLength = max ( StraightLength, FilletRadius*2 + SideRadius*2 )
Width = StraightRadius*2 + FilletRadius*4 + TubeLength*2 + Delta
Depth = max ( StraightRadius, SideRadius ) * 2 + FilletRadius*4 + Delta
Height = MainLength + FilletRadius*2 + Delta
Block = CentredBox ( Width, Depth, Height )
Hole = CentredCylinder ( StraightRadius, Height )
Block = Block.cut ( Hole )
Side = CentredCylinder ( SideRadius, Width, Vector(0,0,Width/2) )
Side.rotate ( Vector(0,0,0), Vector(0,1,0), 90 )
Block = Block.cut ( Side )
Block = Block.makeFillet ( FilletRadius, Block.Edges )
return Block
def CreateShoulderedTeePiece ( StraightLength, StraightRadius, SideLength, SideRadius, FilletRadius ) :
Mold = CreateMold ( StraightLength, StraightRadius, SideLength, SideRadius, FilletRadius )
Radius = max ( StraightRadius, SideRadius )
Block = CentredBox ( SideLength*2, Radius*2+Delta, StraightLength )
return Block.cut ( Mold )
def Test ( ) :
StraightLength = 100
SideLength = 50
for FilletRadius in range (1,20) :
print ( "FilletRadius = ", FilletRadius )
for StraightRadius in range (5,20) :
Line = " "
for SideRadius in range(5,20) :
if SideRadius <= StraightRadius :
try :
Body = CreateMold ( StraightLength, StraightRadius, SideLength, SideRadius, FilletRadius )
Line += " __ "
except :
Body = CentredBox ( 10, 10, 10 )
Line += " Er "
else :
Line += " "
print ( Line )
return Body
if __name__ == "__main__" :
# Test() # Shows the problems, but takes a LONG time to run
import ImportGui
doc = FreeCAD.newDocument()
Body = CreateShoulderedTeePiece ( 100, 20, 50, 18, 20 )
Part.show ( Body )
Gui.activeDocument().activeView().viewIsometric()
Gui.activeDocument().activeView().setCameraType("Perspective")
doc.recompute()
Gui.SendMsgToActiveView("ViewFit")
Code: Select all
21:59:27 FilletRadius = 19
21:59:27 Er
21:59:27 Er Er
21:59:27 Er __ Er
21:59:27 Er __ __ Er
21:59:27 Er __ __ __ Er
21:59:27 __ Er __ __ __ Er
21:59:27 __ __ __ __ __ __ Er
21:59:27 Er __ Er __ __ __ __ Er
21:59:27 __ __ __ Er Er __ __ __ Er
21:59:27 __ __ __ __ __ __ __ __ __ Er
21:59:27 __ Er __ __ __ __ __ Er Er __ Er
21:59:27 __ __ __ __ __ __ __ Er Er __ __ Er
21:59:27 __ __ Er __ __ __ __ Er Er Er __ __ Er
21:59:27 __ __ Er __ __ __ __ Er Er Er __ __ __ Er
21:59:27 __ __ __ __ __ __ __ Er Er Er Er __ __ __ Er