Edit materials from code
-
Access the material object, via the Materials collection.
Then change it's properties. (See the API dictionary for examples, on both.)
-
I just tried changing the display name for a new file, opened with the Susan component.
Her trousers have material 'jean blue'
At the console:
mats = Sketchup.active_model.materials #>> #<Sketchup;;Materials;0x656d2f8> m = mats['jean blue'] #>> #<Sketchup;;Material;0x6525214> m.name.inspect #>> "jean blue" m.display_name.inspect #>> "jean blue" m.name="bluejeans" #>> "bluejeans" m.display_name.inspect #>> "bluejeans"And I visually see in the Materials Inspector that the display_name has indeed changed.
-
thank you very much, functioned to change the display name

I looked at the API dictionary do not understand,
could you give me an example?
such as changing the color of the material 'blue jean' to red -
I have understood
mats = Sketchup.active_model.materials m = mats['jean blue'] m.color=[180, 0, 0]I am new to this,that good there are good people willing to help, thank you very much Dan
(I know very little English)
-
I have another related question,
if I have a cube, each side painted a different color and then create a group or component, how I can access the list of materials the component or group to modify these materials from the code?
Would greatly appreciate a simple example of this, I could not find him anywhere
-
Any group [or a component-instance] can themselves have a 'material' - e.g.
group.materialif it's 'nil' then it has no material, however if it has a material any faces within the group that 'have no material' will display with that group's material [although they still have 'nil' material individually, they will display with the group's material].
The faces [and edges for that matter] inside a group.entities can have materials [face.material] - or 'nil' if none.
Therefore, to find the materials used inside a group [or component definition found from its instance], make a collection of thegroup.entitiesfaces and then iterate through those faces and collect eachface.material, use.uniq!on that array, so you have only one of each; then iterate that array of materials and make a list of their 'names' etc etc...

-
Note:
Material.nameis the internal ID name - whileMaterial.diplay_nameis what SU display in the material browser (exposes to the UI).
For instance, you cannot useMaterial.display_nameas a key in theModel.materialscollection - it will fail in some circumstances (for instance when the name is wrapped in [])Read more: http://www.thomthom.net/thoughts/2012/03/the-secrets-of-sketchups-materials/
-
Diego... see: Ruby Newbie's Guide to Getting Started
-
wow, is more complicated than I expected, I doubt that achieves do with my current knowledge of the Ruby API, I guess I'll have to wait a while thank you very much Dan, Tig and Thomthom for guiding me

-
this is what I have achieved so far
entidad = %(#FF8000)[Sketchup]%(#0040BF)[.active_model.selection][0] curretmaterial = entidad%(#0040BF)[.material] nameM = curretmaterial%(#0040BF)[.name] curretmaterial%(#0040BF)[.color]=[102, 0, 51] curretmaterial%(#0040BF)[.name]=%(#BF8080)["nuevo tono"]I shall be able then apply the recommendations
(sorry for bad English)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better š
Register LoginAdvertisement