CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 04-07-2013, 12:56 AM   #1
b037973a
New Member
portfolio
United Kingdom
 
Join Date: Mar 2013
Posts: 10
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-07-2013, 02:51 AM   #2
LegoBlock
Veteran
portfolio
John
Freelance Rigger / Animator
Culver City, USA
 
Join Date: Aug 2011
Posts: 40
Code:
import maya.cmds as mc mc.gravity()

http://download.autodesk.com/global...on/gravity.html
 
Old 04-07-2013, 03:40 AM   #3
b037973a
New Member
portfolio
United Kingdom
 
Join Date: Mar 2013
Posts: 10
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-07-2013, 03:57 AM   #4
LegoBlock
Veteran
portfolio
John
Freelance Rigger / Animator
Culver City, USA
 
Join Date: Aug 2011
Posts: 40
This should do it
Code:
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-07-2013, 04:17 AM   #5
b037973a
New Member
portfolio
United Kingdom
 
Join Date: Mar 2013
Posts: 10
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-07-2013, 04:20 AM   #6
b037973a
New Member
portfolio
United Kingdom
 
Join Date: Mar 2013
Posts: 10
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-07-2013 at 04:31 AM.
 
Old 04-07-2013, 08:38 AM   #7
djx
Where's my pony?
 
djx's Avatar
David Johnson
vfx & creature td
Melbourne, Australia
 
Join Date: Jun 2003
Posts: 3,389
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-07-2013, 11:36 AM   #8
b037973a
New Member
portfolio
United Kingdom
 
Join Date: Mar 2013
Posts: 10
Great!! That worked perfect. Thanks
Now all of my objects fall freely
 
Old 04-07-2013, 11:36 AM   #9
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 02:58 AM.


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