[Closed] get list of all modifiers
Hello,
Is there a way I can get a list of all the modifier names as an array? I’m not talking about the list of modifers applied to an object but the complete list we see in the modifier list drop down.
Cheers,
Vikram.
From the maxscript help:
showClass "*:mod*" -- all the modifier classes
If you dump that to a stream and filter by “:” you should be able to get the creation names.
-Eric
EDIT: This should build an array of the creation names:
ss = stringstream ""
showClass "*:mod*" to:ss
seek ss 0
modArr = #()
while not (eof ss) do (
modNm = (readdelimitedstring ss " :")
append modArr modNm
skipToNextLine ss
)
EDIT 2: This will build 2 arrays, one for the creation name “modArr” and one for the default name of the applied modifier “modNmArr”. NOTE: You will need to handle the catch for non-creatable modifiers on however you want to handle it.
ss = stringstream ""
showClass "*:mod*" to:ss
seek ss 0
modArr = #() -- these are the creation names, ie execute (modArr[1]+"()") will create an instance of the modifier
modNmArr = #() -- these are the names as they appear on a newly created modifier in the modifier stack
while not (eof ss) do (
modNm = (readdelimitedstring ss " :")
append modArr modNm
try (append modNmArr (execute (modNm+"()")).name) catch (append modNmArr "") -- modifiy the catch to handle non-creatable modifiers, right now it is an empty string
skipToNextLine ss
)
When I run the last piece of code I get
StringStream:””
OK
OK
#()
#()
OK
That doesn’t seem right as this
showClass "*:mod*"
does give me the results I expect
Print the modArr and/or modNmArr arrays as the code is dumping the results to those arrays. Better to use the modified code, as it is cleaner and should get what you want.
-Eric
:shrug: Why does this only give you a limited array and end in ,… when there are obviously more modifiers
#("Affect_Region", "Bend", "Bevel", "Bevel_Profile", "CamPerspCorrect", "CameraMap", "Cap_Holes", "Civil_View_Divide_Spline", "Civil_View_Guard_Rail", "Civil_View_Road_Marking", "Civil_View_Spline_to_Mesh", "Cloth", "CrossSection", "DeleteMesh", "DeletePatch", "DeleteSplineModifier", "Disp_Approx", "Displace", "DynBuilding", "Edit_Mesh", ...)
Oh sure come in here being all efficient and tidy with your code.
-Eric
Although I dont think my version will give you names exactly as they appear in the list like yours does
i can’t check it now but i remember that any class has a property localizedname. what does it show?
That is just as easy though, just loop through your array and collect as I outlined before. Again it needs to be a try/catch as some of the classes aren’t creatable through maxscript and will throw an error:
modNmArr = for nm in modArr collect (try ((execute (nm+"()")).name) catch (""))
-Eric
because i don’t have max open to double-check the code please excuse me if it not works:
-- version #1
for c in modifier.classes collect c.localizedname
-- version #2
for c in modifier.classes where c.creatable collect (c()).name
both work… version 2 seems to give better names (“PhysX Rigid Body” rather than “PhysXModRB”)
i remember that was a reason for me to use them both. i don’t like the second method because it creates max nodes to get the names. #1 doesn’t return right names. probably it should be #3
how about version 1.5:
for c in modifier.classes collect if c.creatable then (c()).name else c.localizedname
I remember poking at this years ago to try and get the names in a more efficient way and I couldn’t find one. I was either parsing strings or doing as you did Denis and make an instance of each to get the information. In the end it really didn’t mater as it only needed to run once to get all the data when the tool launched.