CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 05-06-2013, 01:40 AM   #1
Rewi
New Member
portfolio
Nick Taylor
melbourne, AU
 
Join Date: Mar 2009
Posts: 15
make chain script

so i need to write a script which creates a window and makes a chain, but im having trouble getting my xform lines to work! i want it to move each chain the radius+girth of the link so it sits in the right place and rotate it 90degrees but im not having much luck. any help would be awesome thanks!

global proc cc(string $name, float $radius, float $chainGirth, int $chainLength)

{
string $chainLink[] = `polyTorus -r $radius -sr $chainGirth -tw 0 -sx 20 -sy 20 -ax 0 1 0 -cuv 1 -ch 1 -n $name`;

for ($i=0;$i<$chainLength;$i++)
{

float $distBetween = (($radius+$chainGirth)*($i - 1));
polyTorus -r $radius -sr $chainGirth -tw 0 -sx 20 -sy 20 -ax 0 1 0 -cuv 1 -ch 1 -n $name;
xform -ro 90 0 0 $name[0];
xform -t ($distBetween) 0 0 $name[0]; // changed that from -r
}

}
 
Old 05-06-2013, 09:23 AM   #2
depakeen
Veteran
portfolio
Jerome Pourcel
Paris, FR
 
Join Date: Sep 2011
Posts: 45
Hi,

Did you expect something like that?
Code:
global proc cc(string $name, float $radius, float $chainGirth, int $chainLength) { float $offset = 0;//this variable will keep each torus' offset and add it to the next one for ($i = 0 ; $i < $chainLength ; $i++) { $myTorus = ($name + $i);//changes the name polyTorus -r $radius -sr $chainGirth -tw 0 -sx 20 -sy 20 -ax 0 1 0 -cuv 1 -ch 1 -n $myTorus; if ($i)//we don't want to change anything on the first torus { xform -t (($radius*2) - ($chainGirth*2) + $offset) 0 0 $myTorus; $offset += (($radius*2) - ($chainGirth*2));//adds offset if ($i%2)//applies rotation if $i is odd xform -ro 90 0 0 $myTorus; } } }
 
Old 05-06-2013, 09:55 AM   #3
Borgfriend
Veteran
portfolio
Neal Bürger
Ludwigs Maximilians Universität
Munich, Germany
 
Join Date: Jul 2004
Posts: 51
Hope this simplifies it for you:

Code:
import pymel.core as pm def makeChain(name, radius, girth, lenght): for i in range(0,lenght): obj = pm.polyTorus(radius = radius, sr = girth, tw= 0, sx = 20, sy = 20, ax = (0,1,0), ch = 1, n = name) if i % 2 == 1: pm.rotate(0, 90, 0) distance = 2*(radius - girth)*i pm.move(distance,0,0) makeChain("test", 1, 0.1, 10)
__________________
www.nealbuerger.com
 
Old 05-06-2013, 04:18 PM   #4
depakeen
Veteran
portfolio
Jerome Pourcel
Paris, FR
 
Join Date: Sep 2011
Posts: 45
You're right, borgFriend, the way to calculate offset is much nicer like you did. Let's re-write it in MEL (I've added a random input, just in case...)
Code:
global proc cc(string $name, float $radius, float $chainGirth, int $chainLength, float $random) { for ($i = 0 ; $i < $chainLength ; $i++) { $myTorus = ($name + $i);//changes the name polyTorus -r $radius -sr $chainGirth -tw 0 -sx 20 -sy 20 -ax 0 1 0 -cuv 1 -ch 1 -n $myTorus; xform -t ((($radius - $chainGirth)*2) * $i) 0 0 $myTorus; if ($i%2)//applies rotation if $i is odd xform -ro 90 0 0 $myTorus; //adds a little bit of random... float $randomRot = `rand (-$random) $random`; xform -r -ro $randomRot 0 0 $myTorus; } } cc("test",10,2,8,20);
 
Old 05-06-2013, 09:43 PM   #5
Rewi
New Member
portfolio
Nick Taylor
melbourne, AU
 
Join Date: Mar 2009
Posts: 15
Thumbs up

thanks u guys!! works a treat! I've gotta rig it too so i'll have a go at that.. thanks for the help!
 
Old 05-07-2013, 11:06 AM   #6
Borgfriend
Veteran
portfolio
Neal Bürger
Ludwigs Maximilians Universität
Munich, Germany
 
Join Date: Jul 2004
Posts: 51
Well, I played around with it some more, and added rig support:
It takes a curve as input and creates a chain.

Full code around 150 lines:
http://nealbuerger.com/2013/05/auto...ks-along-curve/
__________________
www.nealbuerger.com

Last edited by Borgfriend : 05-07-2013 at 03:50 PM.
 
Old 05-07-2013, 11:06 AM   #7
CGTalk Moderation
Expert
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,478
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 07:38 PM.


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