diff --git a/src/Mod/BIM/bimcommands/BimLayers.py b/src/Mod/BIM/bimcommands/BimLayers.py index d69767ddeb..4ad159229b 100644 --- a/src/Mod/BIM/bimcommands/BimLayers.py +++ b/src/Mod/BIM/bimcommands/BimLayers.py @@ -137,18 +137,19 @@ class BIM_Layers: import Draft + doc = FreeCAD.ActiveDocument changed = False # delete layers for name in self.deleteList: if not changed: - FreeCAD.ActiveDocument.openTransaction("Layers change") + doc.openTransaction("Layers change") changed = True - FreeCAD.ActiveDocument.removeObject(name) + doc.removeObject(name) # assign for target, objs in self.assignList.items(): - target_obj = FreeCAD.ActiveDocument.getObject(target) + target_obj = doc.getObject(target) if target_obj: for obj in objs: target_obj.Proxy.addObject(target_obj, obj) @@ -159,10 +160,10 @@ class BIM_Layers: name = self.model.item(row, 1).toolTip() obj = None if name: - obj = FreeCAD.ActiveDocument.getObject(name) + obj = doc.getObject(name) if not obj: if not changed: - FreeCAD.ActiveDocument.openTransaction("Layers change") + doc.openTransaction("Layers change") changed = True if self.model.item(row, 1).icon().isNull(): obj = Draft.make_layer(self.model.item(row, 1).text()) @@ -183,7 +184,7 @@ class BIM_Layers: else: projects = [ o - for o in FreeCAD.ActiveDocument.Objects + for o in doc.Objects if hasattr(o, "Proxy") and hasattr(o.Proxy, "ifcfile") ] if projects: @@ -209,77 +210,78 @@ class BIM_Layers: obj = ifc_tools.create_layer( self.model.item(row, 1).text(), project ) + vobj = obj.ViewObject # visibility checked = self.model.item(row, 0).checkState() == QtCore.Qt.Checked - if checked != obj.ViewObject.Visibility: + if checked != vobj.Visibility: if not changed: - FreeCAD.ActiveDocument.openTransaction("Layers change") + doc.openTransaction("Layers change") changed = True - obj.ViewObject.Visibility = checked + vobj.Visibility = checked # label label = self.model.item(row, 1).text() # Setting Label="" is possible in the Property editor but we avoid it here: if label and obj.Label != label: if not changed: - FreeCAD.ActiveDocument.openTransaction("Layers change") + doc.openTransaction("Layers change") changed = True obj.Label = label # line width width = self.model.item(row, 2).data(QtCore.Qt.DisplayRole) # Setting LineWidth=0 is possible in the Property editor but we avoid it here: - if width and obj.ViewObject.LineWidth != width: + if width and vobj.LineWidth != width: if not changed: - FreeCAD.ActiveDocument.openTransaction("Layers change") + doc.openTransaction("Layers change") changed = True - obj.ViewObject.LineWidth = width + vobj.LineWidth = width # draw style style = self.model.item(row, 3).text() - if obj.ViewObject.DrawStyle != style: + if style is not None and vobj.DrawStyle != style: if not changed: - FreeCAD.ActiveDocument.openTransaction("Layers change") + doc.openTransaction("Layers change") changed = True - obj.ViewObject.DrawStyle = style + vobj.DrawStyle = style # line color color = self.model.item(row, 4).data(QtCore.Qt.UserRole) - if obj.ViewObject.LineColor[3:] != color: + if color is not None and vobj.LineColor[3:] != color: if not changed: - FreeCAD.ActiveDocument.openTransaction("Layers change") + doc.openTransaction("Layers change") changed = True - obj.ViewObject.LineColor = color + vobj.LineColor = color # shape color color = self.model.item(row, 5).data(QtCore.Qt.UserRole) - if obj.ViewObject.ShapeColor[3:] != color: + if color is not None and vobj.ShapeColor[3:] != color: if not changed: - FreeCAD.ActiveDocument.openTransaction("Layers change") + doc.openTransaction("Layers change") changed = True - obj.ViewObject.ShapeColor = color + vobj.ShapeColor = color # transparency transparency = self.model.item(row, 6).data(QtCore.Qt.DisplayRole) - if obj.ViewObject.Transparency != transparency: + if transparency is not None and vobj.Transparency != transparency: if not changed: - FreeCAD.ActiveDocument.openTransaction("Layers change") + doc.openTransaction("Layers change") changed = True - obj.ViewObject.Transparency = transparency + vobj.Transparency = transparency # line print color color = self.model.item(row, 7).data(QtCore.Qt.UserRole) - if obj.ViewObject.LinePrintColor[3:] != color: + if color is not None and vobj.LinePrintColor[3:] != color: if not changed: - FreeCAD.ActiveDocument.openTransaction("Layers change") + doc.openTransaction("Layers change") changed = True - obj.ViewObject.LinePrintColor = color + vobj.LinePrintColor = color # recompute if changed: - FreeCAD.ActiveDocument.commitTransaction() - FreeCAD.ActiveDocument.recompute() + doc.commitTransaction() + doc.recompute() # exit self.dialog.reject() diff --git a/src/Mod/Draft/draftguitools/gui_layers.py b/src/Mod/Draft/draftguitools/gui_layers.py index 6e47773156..1b8c4bc85c 100644 --- a/src/Mod/Draft/draftguitools/gui_layers.py +++ b/src/Mod/Draft/draftguitools/gui_layers.py @@ -208,7 +208,7 @@ class LayerManager: # draw style style = self.model.item(row, 3).text() - if vobj.DrawStyle != style: + if style is not None and vobj.DrawStyle != style: if not changed: doc.openTransaction("Layers change") changed = True @@ -216,7 +216,7 @@ class LayerManager: # line color color = self.model.item(row, 4).data(QtCore.Qt.UserRole) - if vobj.LineColor[:3] != color: + if color is not None and vobj.LineColor[:3] != color: if not changed: doc.openTransaction("Layers change") changed = True @@ -224,7 +224,7 @@ class LayerManager: # shape color color = self.model.item(row, 5).data(QtCore.Qt.UserRole) - if vobj.ShapeColor[:3] != color: + if color is not None and vobj.ShapeColor[:3] != color: if not changed: doc.openTransaction("Layers change") changed = True @@ -232,7 +232,7 @@ class LayerManager: # transparency transparency = self.model.item(row, 6).data(QtCore.Qt.DisplayRole) - if vobj.Transparency != transparency: + if transparency is not None and vobj.Transparency != transparency: if not changed: doc.openTransaction("Layers change") changed = True @@ -240,7 +240,7 @@ class LayerManager: # line print color color = self.model.item(row, 7).data(QtCore.Qt.UserRole) - if vobj.LinePrintColor[:3] != color: + if color is not None and vobj.LinePrintColor[:3] != color: if not changed: doc.openTransaction("Layers change") changed = True