'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…
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…