Need help, or want to share a macro? Post here!
student007007
Posts: 10 Joined: Wed Oct 12, 2022 8:43 pm
Post
by student007007 » Thu Dec 01, 2022 2:07 am
Hello,
How can I assign a material to the code? For example Concrete.
Code:
Code: Select all
import FreeCADGui as Gui
import FreeCAD as App
document_name = "bla bla"
file_name = "PATH/{}.FCStd".format(document_name)
Gui.showMainWindow()
doc = App.newDocument(document_name)
App.setActiveDocument(document_name)
doc = App.ActiveDocument
doc.addObject("Part::Cylinder","myCylinder")
doc.myCylinder.Radius = 12
doc.myCylinder.Height = 5
doc.myCylinder.ViewObject.Visibility = True
doc.recompute()
Gui.exec_loop()
Thanks
Last edited by
Kunda1 on Thu Dec 01, 2022 4:21 pm, edited 2 times in total.
Reason: Updated thread title to be less generic
chrisb
Veteran
Posts: 54213 Joined: Tue Mar 17, 2015 9:14 am
Post
by chrisb » Thu Dec 01, 2022 6:25 am
Please edit your post and put the code in code tags using the button </>. That makes the post easier to read. It is not so important here, but in other cases it shows immediately if there are indentations or not.
student007007
Posts: 10 Joined: Wed Oct 12, 2022 8:43 pm
Post
by student007007 » Thu Dec 01, 2022 12:40 pm
I will do it next time.
But do you know the answer to the problem?
Kunda1
Veteran
Posts: 13434 Joined: Thu Jan 05, 2017 9:03 pm
Post
by Kunda1 » Thu Dec 01, 2022 1:40 pm
We should definately have a section in
Material to answer this question
Roy_043
Veteran
Posts: 8552 Joined: Thu Dec 27, 2018 12:28 pm
Post
by Roy_043 » Thu Dec 01, 2022 4:12 pm
Code: Select all
obj.ViewObject.ShapeMaterial.set("Bronze")
BTW: This and the
Material page are unrelated.