diff --git a/lattice2AttachablePlacement.py b/lattice2AttachablePlacement.py index eca48fe..a4e4f28 100644 --- a/lattice2AttachablePlacement.py +++ b/lattice2AttachablePlacement.py @@ -36,16 +36,22 @@ import lattice2Subsequencer as Subsequencer def makeAttachablePlacement(name): '''makeAttachablePlacement(name): makes an attachable Placement object.''' - rev_number = int(App.Version()[2].split(" ")[0]) + + try: + rev_number = int(App.Version()[2].split(" ")[0]) + except Exception as err: + rev_number = 10000000 + if rev_number < 9177: #obsolete! obj = FreeCAD.ActiveDocument.addObject("Part::AttachableObjectPython",name) + AttachablePlacement(obj) + if FreeCAD.GuiUp: + ViewProviderAttachablePlacement(obj.ViewObject) else: - obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) + obj = lattice2BaseFeature.makeLatticeFeature(name, AttachablePlacement, ViewProviderAttachablePlacement, no_disable_attacher= True) obj.addExtension("Part::AttachExtensionPython", None) - AttachablePlacement(obj) - if FreeCAD.GuiUp: - ViewProviderAttachablePlacement(obj.ViewObject) + return obj class AttachablePlacement(lattice2BaseFeature.LatticeFeature): diff --git a/lattice2BaseFeature.py b/lattice2BaseFeature.py index f190630..04d7ce8 100644 --- a/lattice2BaseFeature.py +++ b/lattice2BaseFeature.py @@ -49,16 +49,34 @@ def getDefShapeColor(): return (r/255.0, g/255.0, b/255.0, (255-o)/255.0) -def makeLatticeFeature(name, AppClass, ViewClass): - '''makeLatticeFeature(name, AppClass, ViewClass = None): makes a document object for a LatticeFeature-derived object.''' - obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) +def makeLatticeFeature(name, AppClass, ViewClass, no_body = False, no_disable_attacher = False): + '''makeLatticeFeature(name, AppClass, ViewClass, no_body = False): makes a document object for a LatticeFeature-derived object. + + no_body: if False, the Lattice object will end up in an active body, and Part2DObject will be used. + no_disable_attacher: if True, attachment properties of Part2DObject won't be hidden''' + + body = activeBody() + if body and not no_body: + obj = body.newObject("Part::Part2DObjectPython",name) + obj.AttacherType = 'Attacher::AttachEngine3D' + if not no_disable_attacher: + attachprops = [ + 'Support', + 'MapMode', + 'MapReversed', + 'MapPathParameter', + 'AttachmentOffset', + ] + for prop in attachprops: + obj.setEditorMode(prop, 2) #hidden + else: + obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) AppClass(obj) if FreeCAD.GuiUp: if ViewClass: vp = ViewClass(obj.ViewObject) else: vp = ViewProviderLatticeFeature(obj.ViewObject) - return obj diff --git a/lattice2Common.py b/lattice2Common.py index a21989b..40c9246 100644 --- a/lattice2Common.py +++ b/lattice2Common.py @@ -90,3 +90,6 @@ def screen(feature): return feature feature = getattr(feature.Document, feature.Name) return feature + +def activeBody(): + return FreeCADGui.ActiveDocument.ActiveView.getActiveObject("pdbody")