Code: Select all
def fixVisibility():
for root_object in FreeCAD.ActiveDocument.RootObjects:
root_object.ViewObject.Visibility=True
for obj in root_object.OutListRecursive:
obj.ViewObject.Visibility=False
Code: Select all
def fixVisibility():
for root_object in FreeCAD.ActiveDocument.RootObjects:
root_object.ViewObject.Visibility=True
for obj in root_object.OutListRecursive:
obj.ViewObject.Visibility=False
By original fixVisibility I assume you meanchennes wrote: ↑Tue Jan 11, 2022 4:42 am I can fix the visibility issue with the stairs by re-writing the fixVisibility() function, but I'm not sure if this has negative consequences outside of this case, since I don't really understand the heuristics that were being used in the old one. @keithsloan52, can you have a look at this and make sure it's doing what you intended that function to do? The new version is quite a lot simpler because it relies on FreeCAD's internal "rootObject" notion, and the idea that coming out of the OpenSCAD converter, anything under a root object should be hidden. Obviously a real solution will have to cope with objects that weren't imported from OpenSCAD, but this is the core idea of the fix:
Code: Select all
def fixVisibility(): for root_object in FreeCAD.ActiveDocument.RootObjects: root_object.ViewObject.Visibility=True for obj in root_object.OutListRecursive: obj.ViewObject.Visibility=False
Code: Select all
def fixVisibility():
for obj in FreeCAD.ActiveDocument.Objects:
if(( obj.TypeId=="Part::Fuse" or obj.TypeId=="Part::MultiFuse") and shallHide(obj)):
if "Group" in obj.FullName:
alreadyhidden.append(obj)
obj.ViewObject.Visibility=False
for currentObject in obj.OutList:
if(currentObject not in alreadyhidden):
currentObject.ViewObject.Visibility=True
Thanks for checking, I didn't bother with a git blame, but it doesn't really matter, I'm pretty confident this is what the old function was trying to do. It's only called once, inside an if_gui clause, so we could define the function only in an if_gui as well, but Python being Python, it doesn't actually matter much. I don't know why it's at the top of the file... I usually bury these "cheater" functions at the bottom!keithsloan52 wrote: ↑Tue Jan 11, 2022 8:33 am I also note that the original code is followed by if gui: surely the whole thing should be subject to an if gui:
Code: Select all
$fn=64;
linear_extrude(2)
offset(r = 2)
difference(){
square([20, 20],center=true);
translate([10,10])
circle(d = 10);
}
Code: Select all
File "/Applications/FreeCAD.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 432, in p_offset_action
if subobj[0].Shape.Volume == 0 :
<class 'RuntimeError'>: shape is invalid
Adding to the code
Code: Select all
print(f'p6 : {p[6]}')
print(dir(p[6]))
Code: Select all
09:45:46 ImportCSG Version 0.6a
09:45:46 Start Lex
09:45:46 End Lex
09:45:46 Load Parser
09:45:46 Parser Loaded
09:45:46 Start Parser
09:45:46 ('height', '2')
09:45:46 ('center', 'false')
09:45:46 ('convexity', '1')
09:45:46 2d Point
09:45:46 ('scale', [1.0, 1.0])
09:45:46 ('$fn', '64')
09:45:46 ('$fa', '12')
09:45:46 ('$fs', '2')
09:45:46 ('r', '2')
09:45:46 ('$fn', '64')
09:45:46 ('$fa', '12')
09:45:46 ('$fs', '2')
09:45:46 2d Point
09:45:46 ('size', [20.0, 20.0])
09:45:46 ('center', 'true')
09:45:46 Square
09:45:46 Vector
09:45:46 Vector
09:45:46 Vector
09:45:46 Vector
09:45:46 Matrix
09:45:46 ('$fn', '64')
09:45:46 ('$fa', '12')
09:45:46 ('$fs', '2')
09:45:46 ('r', '5')
09:45:46 Circle : {'$fn': '64', '$fa': '12', '$fs': '2', 'r': '5'}
09:45:46 Circle Shape : True
09:45:46 Push Circle
09:45:46 MultMatrix
09:45:46 Multmatrix
09:45:46 [['1', '0', '0', '10'], ['0', '1', '0', '10'], ['0', '0', '1', '0'], ['0', '0', '0', '1']]
09:45:46 Matrix ((1,0,0,10),(0,1,0,10),(0,0,1,0),(0,0,0,1))
09:45:46 Apply Multmatrix
09:45:46 special orthogonal
09:45:46 rotation rounded
09:45:46 [<Part::Part2DObject>]
09:45:46 difference
09:45:46 2
09:45:46 [<Part::PartFeature>, <Part::Part2DObject>]
09:45:46 Push Resulting Cut
09:45:46 End Cut
09:45:46 p6 : [<Part::PartFeature>]
09:45:46 ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
09:45:46 Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/OpenSCAD_Alt_Import/freecad/OpenSCAD_Alt_Import/importCSG.py", line 96, in open
processcsg(tmpfile)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/OpenSCAD_Alt_Import/freecad/OpenSCAD_Alt_Import/importCSG.py", line 157, in processcsg
result = parser.parse(f.read())
File "/Applications/FreeCAD_19.2.app/Contents/Resources/lib/python3.8/site-packages/ply/yacc.py", line 333, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/Applications/FreeCAD_19.2.app/Contents/Resources/lib/python3.8/site-packages/ply/yacc.py", line 1120, in parseopt_notrack
p.callable(pslice)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/OpenSCAD_Alt_Import/freecad/OpenSCAD_Alt_Import/importCSG.py", line 411, in p_offset_action
if subobj[0].Shape.Volume == 0 :
<class 'RuntimeError'>: shape is invalid
Code: Select all
10:04:26 difference
10:04:26 2
10:04:26 [<Part::PartFeature>, <Part::Part2DObject>]
10:04:26 Push Resulting Cut
10:04:26 ['Base', 'Content', 'Document', 'ExpressionEngine', 'FullName', 'History', 'ID', 'InList', 'InListRecursive', 'Label', 'Label2', 'MemSize', 'Module', 'MustExecute', 'Name', 'NoTouch', 'OldLabel', 'OutList', 'OutListRecursive', 'Parents', 'Placement', 'PropertiesList', 'Refine', 'Removing', 'Shape', 'State', 'Tool', 'TypeId', 'ViewObject', 'Visibility', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'addExtension', 'addProperty', 'adjustRelativeLinks', 'dumpContent', 'dumpPropertyContent', 'enforceRecompute', 'evalExpression', 'getAllDerivedFrom', 'getDocumentationOfProperty', 'getEditorMode', 'getEnumerationsOfProperty', 'getGlobalPlacement', 'getGroupOfProperty', 'getLinkedObject', 'getParentGeoFeatureGroup', 'getParentGroup', 'getPaths', 'getPathsByOutList', 'getPropertyByName', 'getPropertyNameOfGeometry', 'getPropertyOfGeometry', 'getPropertyStatus', 'getPropertyTouchList', 'getStatusString', 'getSubObject', 'getSubObjectList', 'getSubObjects', 'getTypeIdOfProperty', 'getTypeOfProperty', 'hasChildElement', 'hasExtension', 'isDerivedFrom', 'isElementVisible', 'isValid', 'purgeTouched', 'recompute', 'removeProperty', 'resolve', 'resolveSubElement', 'restoreContent', 'restorePropertyContent', 'setEditorMode', 'setElementVisible', 'setExpression', 'setPropertyStatus', 'supportedProperties', 'touch']
10:04:26 End Cut
10:04:26 p6 : [<Part::PartFeature>]
Code: Select all
File "/Applications/FreeCAD.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 432, in p_offset_action
if subobj[0].Shape.Volume == 0 :
<class 'RuntimeError'>: shape is invalid
Code: Select all
mycircle = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython",'circle')
Draft._Circle(mycircle)
mycircle.Radius = r
mycircle.MakeFace = True
#mycircle = Draft.makeCircle(r,face=True) # would call doc.recompute
#mycircle = doc.addObject('Part::Circle',p[1]) #would not create a face
#mycircle.Radius = r
print('Circle Shape : ' +str(mycircle.Shape.isNull()))