I have problem with this method. I am trying to rename materials assigned to layers to use layer’s name.
In case the layer does not have material (-1), it assigns a new one with correct name (no problem here). However, if layer already has material, it renames it (new name visible in the Layer palette) but in Material Editor the material name stays the same, and upon saving/closing/re-opening the file, the new names are gone.
Am I missing something or this is a bug?
Code below:
Call Main()
Sub Main()
Dim arrLayers
Dim i, intMI
arrLayers = Rhino.GetLayers(, False)
If isnull(arrLayers) Then Exit Sub
For i=0 To Ubound(arrLayers)
intMI = Rhino.LayerMaterialIndex(arrLayers(i))
If intMI = -1 Then intMI = Rhino.AddMaterialToLayer(arrLayers(i))
Call Rhino.MaterialName(intMI, Rhino.LayerName(arrLayers(i), False))
Next
End Sub
After saving the file, all the new material names are gone.
Any ideas where the problem can be with what I am trying to do?
This is just a simple example - I am doing an overhaul of the whole material libraries we use and this issue is holding it back for now. Thanks for looking into it.
Also - I tried using this command:
_RenderRenameMaterial
it asks for ID or Instance name… whether I feed it with the material name, or material ID (retrieved by Rhino.MaterialID method) I always get: “Invalid Instance” result.
Ultimately I’d like to use this:
Rendersavematerialtofile to save the materials into files, but this does not work either (same problem)
Ha, I can’t point it out since on your end all works OK as expected! : /
I will try few more things… in the meantime, are you able to get the same results with RenderRenameMaterial ?
What do I use as the ID / Instance name ?
Well, it doesn’t accept what Rhino.MaterialId returns. I suspect this is because the method returns an “ON” material id, not an “RDK” material id. But the command also does (seem to) accept a material name. Perhaps @andy can enlighten us on how this works, being that there isn’t any documentation.
Hmmm… It sometimes works, sometimes does not. Can’t pinpoint the condition when. For example, in this file, it does not. Could you check this one on your end? Is it possible that V4 materials are messing something up?
Why when I purge this file it says Purged 5 V4 materials and 5 V5 materials? Maybe in my templates something carried over from V4 and now affects V5? I’m still lost! All layers and their materials in this file were created from scratch in latest V5 SR11 RC
Yes, I’m afraid this confusion is because there are essentially two material systems in Rhino. There is another system built on top of the the original one (the RDK).
If you look at the plug-in UUID of a “low-level” material, it will either be NULL, or it will be non-null. NULL uuids mean that the low level controls work (they are “in charge”). This happens with materials from from older versions of Rhino.
If the plug-in UUID is non null, then the material is controlled by “something else”. That might be a plug-in like Flamingo. Or it might be the RDK. If it’s {99999999-9999-9999-9999-999999999999}, then the RDK is in charge and you should use the RDK scripting methods to change values on materials.
Ok, now it is making sense-- I am able to detect if the material is RDK or original, and either use regular methods or RDK methods to do what I need. Thanks Andy!