Gravity in Python???HELP PLEASE

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 04 April 2013   #1
Gravity in Python???HELP PLEASE

Okay, so I have scripted a code which the user selects an object then the script duplicates that object around a path. I now want to add a Gravity field to my entire scene. I've hit a brick wall, I can't figure out how to add this Dynamic to my script?

If you need anymore information please just ask... Any help is greatly appreciated
 
Old 04 April 2013   #2
import maya.cmds as mc
mc.gravity()

http://download.autodesk.com/global...on/gravity.html
 
Old 04 April 2013   #3
hmm that didn't seem to work the way I wanted it :/..

An example of my desired result exactly...

Open Maya > create poly sphere > select pShere1 > in 'Dynamics' menu, go Fields - Gravity

^^^^^^^^^^^^^^^^
If you skip through a few frames you'll see the sphere start to fall bellow the grid... basically all I want to do is have a code which uses all currently selected objects, to have the same effect as I've just given in the example. (the gravity field applied and start to react to this over the next frames.)

I'm really in a pickle on how to do this, any help/advice would be great ... And thanks for your response by the way!
 
Old 04 April 2013   #4
This should do it
import maya.cmds as mc
#List of objects
objList = ['pSphere1', 'pSphere2']
#Clear selection, or it will create new gravity for each object
mc.select(cl=1)
#Create gravity
grav = mc.gravity()
#Connect gravity to list of objects
mc.connectDynamic(objList, fields=grav[0])
 
Old 04 April 2013   #5
Works like a beaut!! Thanks for this and for the quick responses. I haven't used this forum much, but I will now.

Thanks again!!
 
Old 04 April 2013   #6
Hmm, I've just found I slight issue though.

I created 3 objects, selected them all then used the code, and it only seems to want to effect the one? Any idea why?

it only seems to want to apply the gravity field to one object only? :S

EDIT: Actually, it seems to make me specify which object I want to apply the gravity field to, rather than apply it to ALL selected objects.


import maya.cmds as mc
#List of objects
objList = ['!!HERE!!']
#Clear selection, or it will create new gravity for each object
mc.select(cl=1)
#Create gravity
grav = mc.gravity()
#Connect gravity to list of objects
mc.connectDynamic(objList, fields=grav[0])


Where I have writen "!HERE!", I have to write the name of my object then run the script and it works,

But

I would rather have it so it applies the gravity effect to ALL objects currently selected? Not sure if i'd have to save the selection in a list or not? :S

Last edited by b037973a : 04 April 2013 at 04:31 AM.
 
Old 04 April 2013   #7
If you study the code you'll notice that your selected objects have nothing to do with it, and in fact this line...
mc.select(cl=1)
...clears your selection.

You could try
objList = mc.ls(sl=True)

David
__________________
http://www.djx.com.au
 
Old 04 April 2013   #8
Great!! That worked perfect. Thanks
Now all of my objects fall freely
 
Old 04 April 2013   #9
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 04:47 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.