this post was submitted on 25 Feb 2024
14 points (100.0% liked)

FreeCAD

858 readers
44 users here now

Your own 3D parametric modeler.

www.freecadweb.org

FreeCAD is an open-source parametric 3D modeler made primarily to design real-life objects of any size. Parametric modeling allows you to easily modify your design by going back into your model history and changing its parameters.

founded 2 years ago
MODERATORS
14
submitted 8 months ago* (last edited 8 months ago) by [email protected] to c/[email protected]
 

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
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 8 months ago (1 children)

Not done freecad scripting so disclaimer that this isn't tested and the like, I do some python for work though. So, looking at the api docs for make_facebinder it looks like it can accept a second, optional parameter that will name the resulting object. I'd say start there.

[–] [email protected] 1 points 8 months ago (1 children)

Sorry, didn't update

I made it work with the help of the FreeCAD Forum!

I'd post the correct script up there but since i changed GPUs today and Mesa drivers apparently bugged out FreeCAD i can't even start the program right now :D

[–] [email protected] 2 points 8 months ago

Glad you got it working!