How to make this macro reusable?
How to make this macro reusable?
How to make this macro reusable? - FreeCAD Forum
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.
import FreeCAD import PartDesignGui import Draft import Part import PartDesign from FreeCAD import Base doc_name = App.activeDocument().Label sels = FreeCADGui.Selection.getSelectionEx('', 0) facebinder1 = Draft.make_facebinder(sels[0]) facebinder2 = Draft.make_facebinder(sels[1]) Draft.autogroup(facebinder1) Draft.autogroup(facebinder2) FreeCAD.ActiveDocument.recompute() App.getDocument(doc_name).addObject('Part::Loft','Loft') App.getDocument(doc_name).ActiveObject.Sections=[App.getDocument(doc_name).Facebinder, App.getDocument(doc_name).Facebinder001, ] App.getDocument(doc_name).ActiveObject.Solid=True App.getDocument(doc_name).ActiveObject.Ruled=False App.getDocument(doc_name).ActiveObject.Closed=False
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:
# -*- coding: utf-8 -*- # Macro Begin: /home/frank-garuda/.local/share/Ondsel/Macro/asfasdf.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++ import FreeCAD import PartDesignGui import Draft import Part import PartDesign # Gui.runCommand('Std_DlgMacroRecord',0) ### Begin command Part_Loft from FreeCAD import Base # Get document name doc_name = App.activeDocument().Label # Gui.runCommand('Std_DlgMacroRecord',0) ### Begin command Std_Workbench # Gui.activateWorkbench("DraftWorkbench") ### End command Std_Workbench ### Begin command Draft_Facebinder sels = FreeCADGui.Selection.getSelectionEx('', 0) facebinder1 = Draft.make_facebinder(sels[0]) facebinder1.Label = "Facebinder_Loft_1" facebinder2 = Draft.make_facebinder(sels[1]) facebinder2.Label = "Facebinder_Loft_2" Draft.autogroup(facebinder1) Draft.autogroup(facebinder2) FreeCAD.ActiveDocument.recompute() App.getDocument(doc_name).addObject('Part::Loft','Loft') App.getDocument(doc_name).ActiveObject.Sections=[facebinder1, facebinder2, ] App.getDocument(doc_name).ActiveObject.Solid=True App.getDocument(doc_name).ActiveObject.Ruled=False App.getDocument(doc_name).ActiveObject.Closed=False