Dup. and Match Transforms

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
  09 September 2012
Dup. and Match Transforms

I'm open to suggestions for something tighter and efficient.


/*
Duplicate and Match Transforms
version 0.2
October 29, 2012
Author: Matthew L. Stoehr
Source: formandspace.com

Objective:
Duplicate and match object transformations of all selected objects.
Preserves inputs for duplicate objects.

How to use:
1. Select all objects to match.
2. Select object to duplicate last. (Last object selected is duplicated).
3. Run script.
*/

dupAndTransform();

proc dupAndTransform()
{
	string $c[] = `ls -sl`;	int $s = size($c);
	int $i;
	string $oldObj = $c[$s-1];
	string $newObj = ($c[$s-1] + "_copy_");
	
	for ($i = 0; $i < $s-1; $i++)
	{
			
		 float $m[] = `xform -q -ws -m $c[$i]`;

		 string $duplicatedObject[] = `duplicate -n $newObj -un $oldObj`;
			
		 xform -ws -m ($m[0]) ($m[1]) ($m[2]) ($m[3])
					  ($m[4]) ($m[5]) ($m[6]) ($m[7])
					  ($m[8]) ($m[9]) ($m[10]) ($m[11])
					  ($m[12]) ($m[13]) ($m[14]) ($m[15]) $duplicatedObject;
		
	}
}




 /*
 Duplicate and Match Transforms
 version .01
 Sept. 7, 2012
 Author: Matthew L. Stoehr
 Source: formandspace.com
 
 Objective:
 Duplicate and match object transformations of all selected objects.
 Preserves inputs for duplicate objects.
 
 How to use:
 Select all objects to match first, select object to duplicate last.
 Last object selected is duplicated.
 Run script.
 */
 
 string $c[] = `ls -sl`;
 int $s = size($c);
 int $i = 0;
 
 for ($node in $c){
  
 	if($i<$s-1){
 		select -r $c[$i];
 		vector $vt = `xform -q -ws -t`;
 		vector $vr = `xform -q -ws -ro`;
 		vector $vs = `xform -q -s`;
 		   
 		select -r $c[$s-1];
 		duplicate -un;
 		xform -ws -t ($vt.x) ($vt.y) ($vt.z);
 		xform -ws -ro ($vr.x) ($vr.y) ($vr.z);
 		xform -s ($vs.x) ($vs.y) ($vs.z);
 	}
 	
 	$i++;
 }
 
 select -r $c;
 
__________________
maya and zbrush training
creating CG3D since 2001

3D Models
@ Turbosquid

my Scripts

Last edited by Stoehr : 10 October 2012 at 07:59 AM.
 
  09 September 2012
Your problem is naive, and your algorithm has a linear complexity. So what exactly are you looking for?
 
  09 September 2012
Merely suggestions on other approaches to the same problem.
__________________
maya and zbrush training
creating CG3D since 2001

3D Models
@ Turbosquid

my Scripts
 
  09 September 2012
Sorry, I still don't understand the motivation. But if all you want is just another approach, then you can use for example particle instantiation - one source object with different transforms.
 
  09 September 2012
Sounds good. Do you think the -matrix would be more efficient in the xform, rather than using the -t, -ro, and -s separately?
__________________
maya and zbrush training
creating CG3D since 2001

3D Models
@ Turbosquid

my Scripts
 
  09 September 2012
Dunno, but if you need performance you should use C++, or at least python with OpenMaya.
 
  10 October 2012
On the subject of xform, object matching, and matrix... I've modified this little script following NaughtyNathans multiple suggestions not to refer to "select" in code (as it's sloppy), and it is now using the matrix to find and set for the duplicates. and is encapsulated in a procedure. I'm familiar with python, and I understand from multiple sources that using python or pymel is the way to go in maya, but I do enjoy learning the original MEL, as it has helped me to understand old scripts and the new python language. The updated code is above.
__________________
maya and zbrush training
creating CG3D since 2001

3D Models
@ Turbosquid

my Scripts
 
  10 October 2012
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 05:37 PM.


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