I’m tying to write a little spript that adds a material modifier to all selected objects and sets its ID.
After stealing ideas from Lele’s One liner thread, the macro recorder and a little bit chat gpt I got this:
Which works very good, if there is only one object selected. When I select multible objects i get:
Needless to say I dont really have a clue of what Im doing here.
I can’t be far off but im kinda stuck now and I need this to work, I have to set material id’s for >100k objects.
*for some reason the forum doesent like if i write code in here even in the [ Code ] tag. I allways get a 403 error… so I posted images. Sorry for that:roll_eyes:*
Instaced for the objects I selected is fine.
My Process would be: selecting a bunch of objects that I now need a certain mat ID - hit the button for that ID - Assign them to a hidden layer so they are gone and I can move on to the next bunch of objects.
A few days of that and I should be done.
(yes I’ll put macroscrpt buttons for like 20 ids in a toolbar, I know a script with a dialoge and proper UI would be waay cooler but would take me a few days to malke probably an I dont have those)
modPanel.addModToSelection (Materialmodifier())
for mod in selection[1].modifiers do (if (classOf mod EQUALEQUAL Materialmodifier) then (mod.materialID = 17))
IMPORTANT: You need to replace the EQUALEQUAL in the code to two equal signs. It’s the double equal sign that throws the 403 error.
The addModToSelection will add an instanced Material ID modifier to all of the objects but you only need to change the modifier on one of them (“selection[1]”) to the new value rather than cycling through all of them. Fast enough on a few items but if you had hundreds it might take a bit of time and isn’t necessary.
Here’s a quick version with a dialog box to set the Material ID. Same EQUALEQUAL change as before…
rollout matID "Set Material ID" width:160 height:96
(
spinner 'spn1' "New Material ID" pos:[12,14] width:68 height:16 range:[1,100,1] type:#integer scale:1 align:#left
button 'btn1' "Set Material ID" pos:[8,43] width:144 height:40 align:#left
on btn1 pressed do
(
if selection.count != 0 then
(
modPanel.addModToSelection (Materialmodifier())
for mod in selection[1].modifiers do (if (classOf mod EQUALEQUAL Materialmodifier) then (mod.materialID = spn1.value))
)
)
)
CreateDialog MatID()