How to assign Material in FreeCAD python script ?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
student007007
Posts: 10
Joined: Wed Oct 12, 2022 8:43 pm

How to assign Material in FreeCAD python script ?

Post by student007007 »

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: 53926
Joined: Tue Mar 17, 2015 9:14 am

Re: Material

Post by chrisb »

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.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
student007007
Posts: 10
Joined: Wed Oct 12, 2022 8:43 pm

Re: Material

Post by student007007 »

I will do it next time.

But do you know the answer to the problem?
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Material

Post by Kunda1 »

We should definately have a section in Material to answer this question
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Material

Post by Roy_043 »

Code: Select all

obj.ViewObject.ShapeMaterial.set("Bronze")
BTW: This and the Material page are unrelated.
Post Reply