[Closed] Select object by modifier and do something in that modifiers sub level?
I’m trying to write a script, but I cant seem to get this part to work. I want the script to select how ever many objects not hidden in the scene that have a custom named modifier, which was originally an “Edit_Poly” modifier, but renamed to “A-New Name Here “. Then go into that modifier in each object, and create a copy of an existing object in the scene named “attachmetomod” and attatch the copy, leaving the original for the next object with the “A-New Name Here ” modifier to create another copy and attatch, looping this until all objects with the modifier “A-New Name Here ” have the object named “attachmetomod” attatched to it, then delete the original “attachmetomod” object.
Script Use to Create the Custom Modifier:
newmod = Edit_Poly()
newmod.name = "A-New Name Here"
if $ != undefined then
(
addModifier $ (newmod) before:1
)
else
(
messageBox "Select Something!"
)
Alright! so you need every object in the scene that contains the renamed “Edit Poly” modifier to have a copy of the “attachmetomod” object? and then delete the original “attachmetomod”? ok
(
theObj = $attachmetomod -- assigns the obj to a variable
copyObj = undefined -- creates an empty variable
disablesceneredraw() -- disables viewport redraw for speed purposes
undo "Undo Attach Nodes" on -- lets create an Undo so you can undo for what ever reason
(
for obj in objects do -- lets go through all the objs in the scene
(
for x = 1 to obj.modifiers.count do -- lets go through all the modifiers on the obj
(
if (classof obj.modifiers[x]) == Edit_Poly do -- checks if any of the modifiers are edit polys (this is not needed but i like to do it)
(
if obj.modifiers[x].name == "A-New Name Here" do -- checks to see if the modifiers has the proper given name
(
copyObj = copy theObj -- lets make a copy of the obj to attach
max modify mode
select obj -- pretty much whenever you want to do operations on a modifier through script you need to select the object that you are dealing with
obj.modifiers[x].SetOperation #Attach -- sets the attach operation for the edit_poly modifiers ( polyop methods will not work because its a modifier )
obj.modifiers[x].attach copyObj editPolyNode:obj -- attaches the obj
) -- end name check
)-- end modifiers check
) -- ends modifiers list loop
) -- ends scene objects loop
)-- ends undo
enablesceneredraw() -- enables viewport redraw
delete theObj -- Deletes the original obj to attach
)
Hope this helps !
Thanks! that works perfect! I will be updating my old maxscript to reflect what I’ve learned.
BTW I have another post which will include the updated script here http://forums.cgsociety.org/showthread.php?f=98&t=1044336
I am almost done with scripting this little plugin which will be used by very many 3ds max users that create content for a specific game, but I’m stuck at one very crucial, very difficult step involving rigging (attachmetomod) evenly to unrigged bones with maxscript.
See currently they are forced to open the exported .dae file and search for a specific line and add correct bone count and missing bones names for every single rigged object.
I will certainly take a look at it im off to bed ATM but I will look at it tomorrow!
Ok it seems to not work if any of the objects in the scene have a modifier on them.
I’ve tried everything i could think of but no matter what if any of the scenes objects have a modifier other than the custom one or edit poly modifier, the script returns loop errors.
I just tried it here and it works i had a bunch of objects some with 3 or more modifiers some with just one and only 3 of the objects actually had the renamed edit poly and it all worked.
Ok I found out why you was able to get it to work because your renamed edit poly modifier must of been at the top of the stack, my renamed edit poly modifiers are not at the top of the stack and can not be which is why its not working for me.
But when I put them at the top it worked, so I’m still unsure how to get this to work if the modifier is not at the top of the stack.
Thanks for the help, please if u can get it to work reguardless of the renamed modifiers position in the stack let me know how.
EDIT :
Ok, I found out how to get it to work, just needed to add
modPanel.setCurrentObject obj.modifiers[#A-New Name Here]
just after
select obj
Thanks Again!! Guess I just needed to tell the script to select that modifier first.
Also I Updated my old script in the Rigging Thread I made http://forums.cgsociety.org/showthread.php?f=98&t=1044336
Which I still need help with :banghead: