PDA

View Full Version : Move Modifiers SubObject (Slice Plane)


Nupsi
01-08-2011, 09:19 AM
Hi there,

First of all: I know almost nothing about maxscript and the script below is almost completely taken from the macro recorder.

Problem:
I need to add a slice modifier to hundreds and hundreds of unique objects (no instances!) and animate the slice plane within the modifier. The adding works just fine, but I canīt find a way to move the sub object (slice plane) of any modifier via maxscript. Copy and paste donīt work, because all objects are on a different height and this offsets the slice plane, even if I set the pivot point to zero.

So this is what I need in detail:
- add slice modifier
- animate on
- select sub object slice plane
- move slice plane from position 300cm above ground on Frame0 to 0cm above ground on Frame100
- animate off
- deselect sub object slice plane

And this is what I have so far:
units.DisplayType = #metric
units.SystemType = #centimeters
modPanel.addModToSelection (SliceModifier ()) ui:on
set animate on
subobjectLevel = 1
modPanel.setCurrentObject $.modifiers[#Slice]
$.position = [0,0,300]
sliderTime = 100f
$.move = [0,0,-300]
subobjectLevel = 0
modPanel.setCurrentObject $.modifiers[#Slice]
set animate off

Everything works fine except the moving of the sub object. Right now the whole object gets moved instead of the slice plane inside the modifier?!?

Thanks a lot in advance!
Nupsi

JHN
01-08-2011, 02:23 PM
No behind max right now, but the listener output doesn't always produce the best results, try this:


for o in selection do
(
local sliceMod = sliceModifier Slice_Type:2
addModifier o sliceMod

with animate on
(
at time 0 sliceMod.Slice_Plane.pos = [0,0,300]
at time 100 sliceMod.Slice_Plane.pos = [0,0,-300]
)
)


Hope it works!
-Johan

Nupsi
01-08-2011, 03:17 PM
Hi Johan and thanks a lot for your help!!!
The sript works so far like a charm, except that the position of the slice plane now is relative to the position of the object. Which means, if the object is at pos z50 than the slice plane is created at z350 at frame 0 and at -250 at Frame 100. But I need the slice plane to be every time at Frame 0 at z300 and at Frame 100 at z0, no matter where the object is placed in space :(

EDIT:
I created a new local called ObjPos and substract this value from the SlicePlane-Position. For sure this is the worst thing ever written in maxscript, but somehow it works :)

So here is the working script for anyone else who might need this some day

Thanks again for your help, Johan! I really appreciate it!

Nupsi
01-08-2011, 04:59 PM
To avoid any problems for all of you I had to delete the script because I found out that it scales up all mrproxys in a scene. Iīve no idea what causes this, but probably itīs the units-routine at the beginning of the script.

So the problem is still active and any help would be nice! Thanks!

SnipeyX
01-08-2011, 05:21 PM
Did you try just getting rid of the units stuff? I didn't see your second script before you took it down, I would put it back up so others can help you troubleshoot what's going on. Just add a disclaimer in there.

Judging from your first code piece, my guess would be maybe your scene's units are something different, and then when you are changing it in the code that is causing objects to scale. I don't see any reason why you need to assign units for what you are doing.

Are you trying to slice mrProxys too?

JHN
01-08-2011, 06:09 PM
EDIT:
I created a new local called ObjPos and substract this value from the SlicePlane-Position. For sure this is the worst thing ever written in maxscript, but somehow it works :)

So here is the working script for anyone else who might need this some day

Thanks again for your help, Johan! I really appreciate it!

This is because the subObject position rotation etc, lives in object space and not worldspace. So the pivot of the object is always the startpoint for a subObject gizmo. So what you did makes total sense.

-Johan

Nupsi
01-09-2011, 07:39 AM
Did you try just getting rid of the units stuff? I didn't see your second script before you took it down, I would put it back up so others can help you troubleshoot what's going on. Just add a disclaimer in there.

Judging from your first code piece, my guess would be maybe your scene's units are something different, and then when you are changing it in the code that is causing objects to scale. I don't see any reason why you need to assign units for what you are doing.

Are you trying to slice mrProxys too?
Hi and thanks for your answer!
Sorry for taking down the script completly. Of course you need it to help *duh*! Iīll attach it again to the end of this post.

The scene units in my working scene are set to metric/centimeters too, just like in the script. And if I delete the units-code from the script, the slice plane uses max-units and I have no idea how to convert from max units to metric units inside maxscript?!

And no, I donīt try to slice mrProxys ;) For them I cached the slice-animation directly into the mib-file.

Hereīs the script, again:
WARNING! DO NOT USE THIS SCRIPT IN YOUR WORKING SCENES!
(
units.DisplayType = #metric
units.SystemType = #centimeters
for o in selection do
(
local sliceMod = sliceModifier Slice_Type:2
addModifier o sliceMod
local ObjPos = o.center

with animate on
(
at time 0 sliceMod.Slice_Plane.pos = [0,0,300]-ObjPos
at time 100 sliceMod.Slice_Plane.pos = [0,0,-50]-ObjPos
)
)
)


Thanks!

SnipeyX
01-09-2011, 03:34 PM
Ah okay, yeah i didn't know if you were doing something different with units other than what was posted the first time. I would double check what your file's units are. If it was set to centimeters, then your script wouldn't be changing anything, and that code would not be needed.

Just type units.systemtype in the listener and see what it returns. (Of course, if you do this after you run your script, we know what it'll return, so do it on your source file.) Of course, the menu correlation to that code is going to Customize > Unit Setup > System unit Setup, so you could do that as well.

My guess is you are getting display units and system units confused. You probably have centimeters as display but something else as system. That would be the reason it is using a different unit value prior to your code, because it will use you system unit, which must be something different than centimeters.

If things in your scene are at the correct scale, then what you should do is create a new blank file, change the system settings for that file to centimeters, then merge in everything from your other scene. That should preserve the correct scale, and then you can run your code without issue.

denisT
01-09-2011, 05:38 PM
the current system units are not an issue in this case. you should look at Modifier Sub-Object Transform Properties in mxs help. to get right slice plane position in word space coordinate system you have to transform it:

(
n = box pos:[10,20,30]
m = sliceModifier Slice_Type:2
addModifier n m
objTM = n.objectTransform
modTM = getModContextTM n m
-- set slice plane position at world coordinates [0,0,300]
m.Slice_Plane.pos = [0,0,300] * modTM * (inverse objTM)
)


the same way you have to transform the plane's rotation if the current node has additional object rotation offset.

ps. i don't have MAX right now to double-check the code but i hope that i haven't missed anything.

CGTalk Moderation
01-09-2011, 05:38 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.