From 34dfac07016c9455065b4f874ef3bcd917e9f4a1 Mon Sep 17 00:00:00 2001 From: AccidentallyTheCable Date: Sun, 19 Mar 2023 23:39:58 -0700 Subject: [PATCH] Add try/catch around line/shape color property settings to prevent utter failures on import --- kicadStepUptools.py | 66 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/kicadStepUptools.py b/kicadStepUptools.py index 3b5f19d..7b7e625 100644 --- a/kicadStepUptools.py +++ b/kicadStepUptools.py @@ -3341,11 +3341,27 @@ def reset_prop_shapes(obj,doc,App,Gui,rmv=None): #Part.show(w1) #say(w) # - FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.getObject(obj.Name).ShapeColor - FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.getObject(obj.Name).LineColor - FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.getObject(obj.Name).PointColor - FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.getObject(obj.Name).DiffuseColor - FreeCADGui.ActiveDocument.ActiveObject.Transparency=FreeCADGui.ActiveDocument.getObject(obj.Name).Transparency + + try: + FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.getObject(obj.Name).ShapeColor + except BaseException as e: + sayerr(f"Failed to set Shape Color: {e}") + try: + FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.getObject(obj.Name).LineColor + except BaseException as e: + sayerr(f"Failed to set Line Color: {e}") + try: + FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.getObject(obj.Name).PointColor + except BaseException as e: + sayerr(f"Failed to set Point Color: {e}") + try: + FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.getObject(obj.Name).DiffuseColor + except BaseException as e: + sayerr(f"Failed to set Diffuse Color: {e}") + try: + FreeCADGui.ActiveDocument.ActiveObject.Transparency=FreeCADGui.ActiveDocument.getObject(obj.Name).Transparency + except BaseException as e: + sayerr(f"Failed to set Transparency: {e}") #FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.getObject(obj.Name).ShapeColor #FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.getObject(obj.Name).LineColor #FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.getObject(obj.Name).PointColor @@ -3392,10 +3408,22 @@ def reset_prop_shapes2(obj,doc,App,Gui): #FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.Part__Feature.LineColor #FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.Part__Feature.PointColor #FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.Part__Feature.DiffuseColor - FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.getObject(obj.Name).ShapeColor - FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.getObject(obj.Name).LineColor - FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.getObject(obj.Name).PointColor - FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.getObject(obj.Name).DiffuseColor + try: + FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.getObject(obj.Name).ShapeColor + except BaseException as e: + sayerr(f"Failed to set Shape Color: {e}") + try: + FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.getObject(obj.Name).LineColor + except BaseException as e: + sayerr(f"Failed to set Line Color: {e}") + try: + FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.getObject(obj.Name).PointColor + except BaseException as e: + sayerr(f"Failed to set Point Color: {e}") + try: + FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.getObject(obj.Name).DiffuseColor + except BaseException as e: + sayerr(f"Failed to set Diffuse Color: {e}") #FreeCADGui.ActiveDocument.ActiveObject.Transparency=FreeCADGui.ActiveDocument.getObject(obj.Name).Transparency new_label=obj.Label FreeCAD.ActiveDocument.removeObject(obj.Name) @@ -3412,10 +3440,22 @@ def copy_objs(obj,doc): FreeCAD.ActiveDocument.addObject('Part::Feature',obj.Label).Shape=obj.Shape #App.ActiveDocument.ActiveObject.Label=obj.Label - FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.getObject(obj.Name).ShapeColor - FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.getObject(obj.Name).LineColor - FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.getObject(obj.Name).PointColor - FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.getObject(obj.Name).DiffuseColor + try: + FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.getObject(obj.Name).ShapeColor + except BaseException as e: + sayerr(f"Failed to set Shape Color: {e}") + try: + FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.getObject(obj.Name).LineColor + except BaseException as e: + sayerr(f"Failed to set Line Color: {e}") + try: + FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.getObject(obj.Name).PointColor + except BaseException as e: + sayerr(f"Failed to set Point Color: {e}") + try: + FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.getObject(obj.Name).DiffuseColor + except BaseException as e: + sayerr(f"Failed to set Diffuse Color: {e}") #FreeCADGui.ActiveDocument.ActiveObject.Transparency=FreeCADGui.ActiveDocument.getObject(obj.Name).Transparency FreeCAD.ActiveDocument.recompute() #App.ActiveDocument.ActiveObject.ViewObject.Visibility = False