Home Technical Talk

[MAXScript] Collapse To

interpolator
Offline / Send Message
Revel interpolator
Hello people!
Quick question, why won't the bellow "Collapse To" script works on a selection of objects?
fn collapseTo =
(
    for obj in selection do
    (
        for i in obj.modifiers.count to 1 by -1 where
            obj.modifiers[i] == modPanel.getCurrentObject() do
            (
                maxops.CollapseNodeTo obj i off
                exit
            )
    )
)
collapseTo()
.. from what I understand, maxscript didn't really exposed to the "collapse to" function so I hack in a way to make it work but currently only works for a single object. Does anyone can point out the mistake on my code that make it's not working as expected on multiple selection of objects?

Replies

  • StereoVinny
    Options
    Offline / Send Message
    StereoVinny polycounter lvl 9
    'Collapse To' works on a specific modifier, by nature it can't really work on multiple objects.

    If you're trying to collapse multiple objects to a specific class of modifier you will have to change your logic as modPanel.getCurrentObject() returns a specific modifier, thus it cannot also exist on another object. Instead you would have to loop through the objects' modifiers looking for a specific class of modifier, collect its index in the stack and collapse the object's stack to this specific index if it was found.

    cheers
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    Hmm..but when I put "for obj in selection" loop, shouldn't it loop through each object 1 by 1?
  • monster
    Options
    Offline / Send Message
    monster polycounter
    modpanel.getCurrentObject() depends on what is displayed in the modifier panel. If you select multiple objects modpanel.getCurrentObject() will return undefined. If your modifier is instanced to all the objects selected, then modpanel.getCurrentObject() will return a modifier on the first loop iteration and then subsequent iterations will return undefined since the modifier is no longer instanced throughout the selection.

    StereoVinny's solution is what I would do. But if you know you're always going to deal with an instanced modifier you can make a simple change.
    fn collapseTo =
    (
    	--GET THE INSTANCED MODIFIER
    	iMod = modPanel.getCurrentObject()
    	
        for obj in selection do
        (
            for i in obj.modifiers.count to 1 by -1 where
                obj.modifiers[i] == iMod do
                (
                    maxops.CollapseNodeTo obj i off
                    exit
                )
        )
    )
    collapseTo()
    
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    Ha! make sense, thanks monster! :)
    And yea, I get what you mean now StereoVinny! even though that wasn't my original intention, but it sure does come in handy when I need it in the future! Also WELCOME TO POLYCOUNT! :)
  • S-S
    Options
    Offline / Send Message
    S-S polycounter lvl 18
    Just out of curiosity;

    Why use maxops commands in general? I usually rely on Node commands:

    ConvertTo and it's shortcuts like convertToPoly, convertToMesh and so on.

    You can find all of them in maxscript manual under "Node" chapter or using apropos "convertTo" on maxscript command line.
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    Hi S-S, what I wanted to achieve was not really a convert to poly/ mesh/ etc, but a collapse to a certain modifier on stack, similar to the right click > collapse to function, since it's not available by default to assign to a shortcut key (but collapse all function available by default on the shortcut key list), I have to hack it in.

    In fact, I do have a convert to function as well on my shortcut key list :)
Sign In or Register to comment.