I am reverse engineering an existing script to learn. Can anyone tell me what the second line below the variable in line one does?
1 RBmod = (MassFX_RBody ())
addmodifier $ RBmod
Thanks!
Solved! Go to Solution.
Solved by blakestone. Go to Solution.
Never use $ in a script. This is not a good solution. Always use selection instead.
$ can return one of two things, either a node or an array of nodes. This can cause bugs in your code if you are testing with multiple objects selected you will have properties like .count for an array but when only one object is selected and it doesn't represent an array there is no .count property.
Selection will always return an array and will keep your code clean.
Paul,
Thanks for the advice. Would this be the proper syntax?
RBmod = (MassFX_RBody ())
addmodifier selection RBmod
Yes, it is a mapped function to it will apply the modifier to all the objects selected.
The script you have provided will add the "MassFX" modifier to all selected objects as an "Instance", meaning if you adjust the values of one of these modifiers it will adjust all Instances of this with the same values, something you may/may-not want?
Here is another example how this can be achieved without being Instanced.
-- Applies MassFX_RBody Modifier to ONLY Geometry Objects in selection AND only -- if they don't already have the MassFX_RBody Modifier already applied. -- Script inside UNDO function so users may perform an UNDO if script has been run accidentally. ( with undo on ( for o in selection where superClassOf o == GeometryClass and o.modifiers[#MassFX_RBody] == undefined do addModifier o (MassFX_RBody()) ) )