How to make this macro reusable?
Hello,
so i just started to do some macro writing and had to get some help by ChatGPT because i am no programmer. But i made something useful for me.
<span style="color:#323232;">import FreeCAD
</span><span style="color:#323232;">import PartDesignGui
</span><span style="color:#323232;">import Draft
</span><span style="color:#323232;">import Part
</span><span style="color:#323232;">import PartDesign
</span><span style="color:#323232;">from FreeCAD import Base
</span><span style="color:#323232;">
</span><span style="color:#323232;">doc_name = App.activeDocument().Label
</span><span style="color:#323232;">
</span><span style="color:#323232;">sels = FreeCADGui.Selection.getSelectionEx('', 0)
</span><span style="color:#323232;">facebinder1 = Draft.make_facebinder(sels[0])
</span><span style="color:#323232;">facebinder2 = Draft.make_facebinder(sels[1])
</span><span style="color:#323232;">Draft.autogroup(facebinder1)
</span><span style="color:#323232;">Draft.autogroup(facebinder2)
</span><span style="color:#323232;">FreeCAD.ActiveDocument.recompute()
</span><span style="color:#323232;">App.getDocument(doc_name).addObject('Part::Loft','Loft')
</span><span style="color:#323232;">App.getDocument(doc_name).ActiveObject.Sections=[App.getDocument(doc_name).Facebinder, App.getDocument(doc_name).Facebinder001, ]
</span><span style="color:#323232;">App.getDocument(doc_name).ActiveObject.Solid=True
</span><span style="color:#323232;">App.getDocument(doc_name).ActiveObject.Ruled=False
</span><span style="color:#323232;">App.getDocument(doc_name).ActiveObject.Closed=False
</span>
I select two faces from two bodies and it will create two seperate facebinders and performs a loft with those two.
This allows me to make a loft in one fell swoop. However the facebinders created by the
Draft.make_facebinder(sels[X])
will always come out as Facerbinder and Facebinder001 and counting upwards. I don’t see any way to change those names. Yes, i can do something with labels, but the following part of
App.getDocument(doc_name).ActiveObject.Sections=[App.getDocument(doc_name).Facebinder, App.getDocument(doc_name).Facebinder001, ]
doesn’t seem to work with labels… As you can see Facebinder and Facebinder001 are hardcoded in there. Is there any way to either fully rename items so i could go for facebinder_temp1 and _temp2 and then rename them afterwards to make room for another _temp1 and _temp2 again or if i can somehow let the Loft function know what Facebinders were created prior?
Sorry if this is a little bit unstructured i am bashing my head right now… maybe you can help me out here.
Thanks!
EDIT:
Solution was:
<span style="color:#323232;"># -*- coding: utf-8 -*-
</span><span style="color:#323232;">
</span><span style="color:#323232;"># Macro Begin: /home/frank-garuda/.local/share/Ondsel/Macro/asfasdf.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
</span><span style="color:#323232;">import FreeCAD
</span><span style="color:#323232;">import PartDesignGui
</span><span style="color:#323232;">import Draft
</span><span style="color:#323232;">import Part
</span><span style="color:#323232;">import PartDesign
</span><span style="color:#323232;">
</span><span style="color:#323232;"># Gui.runCommand('Std_DlgMacroRecord',0)
</span><span style="color:#323232;">### Begin command Part_Loft
</span><span style="color:#323232;">from FreeCAD import Base
</span><span style="color:#323232;">
</span><span style="color:#323232;"># Get document name
</span><span style="color:#323232;">doc_name = App.activeDocument().Label
</span><span style="color:#323232;">
</span><span style="color:#323232;"># Gui.runCommand('Std_DlgMacroRecord',0)
</span><span style="color:#323232;">### Begin command Std_Workbench
</span><span style="color:#323232;"># Gui.activateWorkbench("DraftWorkbench")
</span><span style="color:#323232;">### End command Std_Workbench
</span><span style="color:#323232;">### Begin command Draft_Facebinder
</span><span style="color:#323232;">sels = FreeCADGui.Selection.getSelectionEx('', 0)
</span><span style="color:#323232;">facebinder1 = Draft.make_facebinder(sels[0])
</span><span style="color:#323232;">facebinder1.Label = "Facebinder_Loft_1"
</span><span style="color:#323232;">facebinder2 = Draft.make_facebinder(sels[1])
</span><span style="color:#323232;">facebinder2.Label = "Facebinder_Loft_2"
</span><span style="color:#323232;">Draft.autogroup(facebinder1)
</span><span style="color:#323232;">Draft.autogroup(facebinder2)
</span><span style="color:#323232;">FreeCAD.ActiveDocument.recompute()
</span><span style="color:#323232;">App.getDocument(doc_name).addObject('Part::Loft','Loft')
</span><span style="color:#323232;">App.getDocument(doc_name).ActiveObject.Sections=[facebinder1, facebinder2, ]
</span><span style="color:#323232;">App.getDocument(doc_name).ActiveObject.Solid=True
</span><span style="color:#323232;">App.getDocument(doc_name).ActiveObject.Ruled=False
</span><span style="color:#323232;">App.getDocument(doc_name).ActiveObject.Closed=False
</span>
Add comment