I got a problem with a modifier I'm trying to make in maxscript. The idea is to have an array as modifier on a object, so you can quickly and dynamically change properties on the clones. It works okay at first, but my problem is that the modifier doesn't know/remember its parent.
If you add the modifier on a box, you get a bunch of boxes, then add the modifier on a sphere and you get a bunch of sphere, but as soon as you do updates, it uses the wrong parent.
Anyone know how I can get around this?
You can get the script
here. Just unpack it into Max's Scripts/Startup and there should be a Array Object modifier.
Replies
I gave a look at your code, haven't fixed it but I think I found the source of the issue. You declared a lot of global variables (usually a bad coding practice). Those variables are shared by every Array Object Modifier in the scene. If you create a Sphere, add your modifier and update the scene then in the listener type "Parent_Obj_Name" you'll get "Sphere01", then if you create a Box and do the same, you'll get "Box01" and whenever you modify parameters in an Array Object Modifier on Spheres or Boxes, it will access the value stored in the global variable "Parent_Obj_Name" which is now "Box01".
You should put modifier related data into modifier scope. I guess you can add them to the parameter block, or make them local to the modifier rollout, I'm not sure on this, you should run some tests.
As a side note, whenever you need variables in global scope, it is much better to define a structure holding them all, then create an instance declared as global with a quite unique name to avoid collision with other possible variables in the global scope by other scripts or plug-ins.
So using the example you have there, all the values stays within the single modifier and not the scene?
the sample I wrote about structures is very generic and shows a better coding practice when you need to declare many variables at global scope. If you define a structure containing all the variables you need, then instance the structure at global scope, you are exposing to the global scope a single "name", which is much better then declaring all your variables "names" in such scope.
This procedure will not solve your issue anyway, because all modifiers would access the same variables in the same single global structure.
I'm not a Plugin expert, but I guess you should add those variables to the parameter block. And I think you don't need to duplicate them all in the rollout, as you can access them directly. Look at: "Scripted Plug-in Clauses" in MaxScript Reference, section "Parameters".