PDA

View Full Version : Simple script acting odd !


PePeTD
07-13-2009, 12:32 AM
so i wrote the following script to go through the selected controllers of my character. Problem is for some reason max is not updating it self while the script is running. When i first run the script and press the Single button on the rollout it should add a edit_spline to my object and then collapse it down to the editable_Spline, but instead the first time you press the button it adds the edit_spline but doesn't collapse it if i then press the button again it will collapse the previous edit_poly and the next one.

I am confused .... why is this happening if max reads scripts line by line how come it is not doing what i want on the first time ?

rollout trydnt "Fix it"
(
local b = undefined
local p = undefined

button fixBtn "FIX Spline" width:140

on fixBtn pressed do
(
for i = 1 to selection.count do
(
p = Edit_Spline() --created the unique modifier
b = selection[i].modifiers.count --counts the number of modifiers
addmodifier selection[i] p before:b -- adds the eit poly under all the modifiers if there is any

-- following goes through the modifiers on the object and if any modifiers is a classof Edit_Spline then colapse it
for mi = 1 to selection[i].modifiers.count do
(
if (classof selection[i].modifiers[mi]) == Edit_Spline then
(
print b
maxOps.CollapseNodeTo selection[i] mi on
)
)
)
)
)
createdialog trydnt

PePeTD
07-13-2009, 12:54 AM
So the problem is even more confusing.

if you press the button once it adds the edit_poly if you press it again then it collapse the previous and the new one, then if you press it again it will add the edit_poly again and not collapse it so this script works every other button press only :P

Mathieson
07-13-2009, 01:07 AM
Hey Felipe,

I haven't been able to recreate the issue yet with the provided code. I have tested on a single spline with no modifiers, a selection of splines with no modifiers, and then a selection of splines with an emptyModifier on each. It has worked in each of these instances for me.

What kinds of modifiers do you have on the spline objects you are processing? I have had issues sometimes when trying to add a modifier, through script, below certain modifier types (skin comes to mind). Maybe there is some kind of conflict here that is preventing it from collapsing on the first go through. Have you tried deleting all modifiers and running it on just the bare objects?

When you run the code and the stack doesn't collapse, does the print statement inside the if statement still output all the values for you?

Mathieson
07-13-2009, 01:19 AM
Another thought. What happens if you manually add an edit_spline and then run the script? Does it still fail on the first time?

PePeTD
07-13-2009, 01:29 PM
Hey Felipe,

I haven't been able to recreate the issue yet with the provided code. I have tested on a single spline with no modifiers, a selection of splines with no modifiers, and then a selection of splines with an emptyModifier on each. It has worked in each of these instances for me.

What kinds of modifiers do you have on the spline objects you are processing? I have had issues sometimes when trying to add a modifier, through script, below certain modifier types (skin comes to mind). Maybe there is some kind of conflict here that is preventing it from collapsing on the first go through. Have you tried deleting all modifiers and running it on just the bare objects?

When you run the code and the stack doesn't collapse, does the print statement inside the if statement still output all the values for you?

Hey Mat !

The only modifier that the splines could have is an Attribute holder that is why i made sure to add the edit spline under everything just in case. It could be a max 8 bug ? and yes it still prints the statement inside the if statement.



Another thought. What happens if you manually add an edit_spline and then run the script? Does it still fail on the first time?

if I add the Edit_spline by hand and run the script it does not fail.

thx for the help ! :P

PePeTD
07-13-2009, 01:49 PM
... Tried it on Max 2010 and it worked... brilliant.. now i know its max 8.

PEN
07-13-2009, 02:29 PM
Have you tried using convertToSplineShape instead?

PePeTD
07-13-2009, 03:41 PM
I will give it a try , but i think that will collapse everything even my attribute holder in some objects.

Mathieson
07-13-2009, 05:04 PM
I will give it a try , but i think that will collapse everything even my attribute holder in some objects.

You could collect the modifiers from each object before collapsing it and then add them again afterwards. I've had to do this before to get around something and it did the trick, just takes a bit of extra time.

CGTalk Moderation
07-13-2009, 05:04 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.