PDA

View Full Version : A simple script problem


Opeth
08-29-2002, 12:43 PM
hi! this is my first post here :)
its about a little script i'm trying to write, which is supposed to be extremely simple, but having it be my first script, its proving otherwise...
the scripts perpus is this:
i want it to scatter a selected objects clones across a certain other object using attachment constraint. this way i might be able to make a nicely moving chain mail, or nits on a leather jacket etc.
so far this is what i have:
(i havnen't done the cloning part yet, nor the distribution of the objects on the diffrent faces of the node object, but thats for later)
for i in selection do
(
i.position.controller = attachment ()
i.position.controller.node = $plane01
addnewkey i.position.controller.keys 1
)

now, what i'm trying to do is get the GetKey thing to work, & i'm not being at all successfull with this attempt. can anyone please explain to me the syntex & the usage way of the GetKey command & the MAXAkey system? i tried the maxscript reference & it helped me only so much...

LFShade
08-29-2002, 03:03 PM
attachCtrl is an interface to the attachment constraint to get and set keys. you should use attachCtrl.addNewKey to set keys and attachCtrl.getKey to retrieve them properly as MAXAKey values. Using the standard getKey will only return a MAXKey value, which won't let you work with the properties specific to the attachment constraint. Therefore,

for i in selection do
(
local att = attach node:$plane01
i.position.controller = att
attachCtrl.addnewkey att 1
)

will add an attachment controller to each object, with $plane01 as the target object, and with a key set at frame 1. Then, assuming the selected object has an attachment constraint with keys set on it, you could get a handle to the first key like this:
foo = attachCtrl.getKey $.position.controller 1
You can see that attachCtrl.getKey takes an attachment controller and an integer number as its arguments. Keep in mind that the integer is a 1-based index of the controller's key array, not a frame number. Since this expression uses the attachCtrl interface, it returns a MAXAKey value to foo, and you can set and get its properties through simple dot notation.

foo.face = 20
foo.coord = [ 0, 0 ]
...

You can find all the properties available to you in the MAXScript docs under the "attachment controller keys" heading.

Good luck:thumbsup:

Opeth
08-29-2002, 03:43 PM
aahh i'll try that right away! thanks very much!!

btw.. just wondering... where from, what from or why does your signature say what it does? :)

LFShade
08-29-2002, 03:59 PM
I don't remember where I pulled that quote from in my sig. I'll likely change it soon, anyway:shrug:

I've noticed a strange behavior with the attachment controller and MAXScript, by the way. For some reason, changes to the keys done through MXS don't update properly in the viewports. According to the "Attachment - PositionController" section of the docs, the attachCtrl interface includes an update() function - but it doesn't work when I try it, and it is not listed in the "AttachCtrl const StructDef" section of the docs:surprised

I'm looking into this now...

Opeth
08-29-2002, 06:04 PM
hmm.. good luck with that :)
anyway, i tried using what u wrote me & my script works perfectly.. so far hehe :)
now i have these matters ahead of me (which i will try to figure alone cuz that way its more enjoyable):
1) having the user enter the multiplier that will decide on every #th face of the destribution object a clone of the scattered object will be placed.
2) finding out the number of faces the destribution object has.
3) cloning a the selected objects to scatter as many times as needed to fill all the face devided by the multiplier the user will enter in part 1 above.
4) this isn't gonna be anytime soon, but i'll try having the scattered objects scatter only across selected faces.. but right now, not only do i not know the syntax, but i don't even have an idea of how to do that... BUT I'LL FIGURE IT OUT! :)

thanx for your help again dude. & leave the personal signiture, its good!

CGTalk Moderation
01-13-2006, 03:00 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.