I have modified an example found online to add a new PBR material to the scene. If I run this script again, it creates a new material labled …(1), …(2), etc. How can I keep track of the current number lable added? Can I find and delete / use materials added with previous runs of the script?
Or you could use a naming convention for your material, say “Kral PBR” and each time before you create the material instead first look through the RenderMaterials table to see if already such a material exist. If it does only change the texture on that material instance.
Yes, as mentioned, your example is the core of the script and I don’t think I could write it alone. In actual fact I don’t know how to script as can be seen by my futile attempts to utilise this website MaterialTable.Find Method (String, Boolean) (rhino3d.com). From what I see the Find() accepts a string and a boolean but when I use “rd.Tables.MaterialTable.Find(“MyPBRTexture*”, True)” I get an error: “Message: Find() takes exactly 3 arguments (2 given)”. I guess anyone using it understands it all to well but moving from rhinoscript to rhinocommon I can’t properly understand what’s going on. Here Guides (rhino3d.com) I found a lot information but it’s like “Use the shovel to dig a hole”. What I need is a guide on how to use the showel before I can get to digging the hole.
My goal is to to make a script that Can be used multiple times applying materials on single/multiple objects (surfaces) while overwritting the material already applied to the object.
If the script could create the metalness mask itself based on the provided texture that would be a great enhancement. I’d like to conquer this part alone as part of my learning but I need to know if it can be done inside Rhino python script or if I need to make it a standalone program?
I’ve been gethering all kinds of guides and I’ll be grateful for links to more.
From what I found around the forums it seems I’m getting objects mixed up with guids or vice versa. Both with materials and objects I got the lists I wanted but wasn’t able to work with them in any way. Now I’m getting a " getset_descriptor is not callable" (I coudn’t find what that means).
Anyway I’ve added the testing textures which I realize I’ve left out. AssignPBR.py (2.6 KB)
obs = [sc.doc.Objects.FindId(obid) for obid in objs_to_texture] # get all the RhinoObjects from the GUIDs
for ob in obs:
ob.RenderMaterial = new_pbr
ob.CommitChanges()
(One of) The mistake(s) you made was using AddMaterialToObject as a property, but it is a method. Anyway, the above snipped will ensure objects get the RenderMaterial new_pbr assigned.
I would guess “(One of) The mistake(s)” I made was assuming that throwing random stuff into the script and checking on the variables comming out is a valid scripting process. But what do I know I’m a beginner. With this piece fallen in I’ve managet to make the script do what I need. Thank you a lot for all the hints. Have a nice day.