average pivot script

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
  12 December 2007
average pivot script

I wrote this code in order to average the pivot between components.
That way, I can use an averaged pivot when modelling with MEL.
The problem is that the script keeps telling me that $components
is not initialized. Can anyone help?

 global float[] proc centerComponentPivot() 
{

// Lists the selection.

$components = `ls -sl -fl`;

float $averageXYZ[] = {0, 0, 0};



// Itterates through the selection.

for($i = 0; $i < size($components); $i ++)

{

// Finds the position of a component, and assigns it to a float array.

float $XYZ[] = `pointPosition $components[$i]`;

print("Position " + $XYZ[0] + " " + $XYZ[1] + " " + $XYZ[2] + "\n");



// Adds the axis' positions together. For example, averageXYZ[0] 

// would be the total X-axis positions of the components.

$averageXYZ[0] = $averageXYZ[0] + $XYZ[0];

$averageXYZ[1] = $averageXYZ[1] + $XYZ[1];

$averageXYZ[2] = $averageXYZ[2] + $XYZ[2];

}



// Divides each axis' position by the number of components. This is the 

// equation for finding an average. By finding the average of each axi,

// I can now position the selected components' pivot.

$averageXYZ[0] = $averageXYZ[0] / size($components);

$averageXYZ[1] = $averageXYZ[1] / size($components);

$averageXYZ[2] = $averageXYZ[2] / size($components);

print $averageXYZ;

}
 
  12 December 2007
well what should i say... hmmm...
maya's right $components isn't initialized!


$components = `ls -sl -fl`;


this is your first use of $components so you need to initialize it. the ls command will return an array and you're using it later on in the script as an array so the line should look like this:


string $components[] = `ls -sl -fl`;


i'm not sure if there are some more mistakes but this is surely what maya meant.
please try the script with those changes and ask if it still isn't working.
 
  12 December 2007
Nope, tried it and the error is still the same.

Error Report:
// Error: global float[] proc centerComponentPivot()
//
// Error: Syntax error //
// Warning: float $averageXYZ[] = {0, 0, 0};
//
// Warning: Global variable is already initialized; this occurrence is ignored. //
// Error: for($i = 0; $i < size($components); $i ++)
//
// Error: "$components" is an undeclared variable. //
// Error: float $XYZ[] = `pointPosition $components[$i]`;
//
// Error: "$components" is an undeclared variable. //
// Error: $averageXYZ[0] = $averageXYZ[0] / size($components);
//
// Error: "$components" is an undeclared variable. //
// Error: $averageXYZ[1] = $averageXYZ[1] / size($components);
//
// Error: "$components" is an undeclared variable. //
// Error: $averageXYZ[2] = $averageXYZ[2] / size($components);
//
// Error: "$components" is an undeclared variable. //
// Error: }; //
// Error: Syntax error //
 
  12 December 2007

global float[] proc centerComponentPivot()

wrong way. do it like this:

 global proc float[] centerComponentPivot()
 


you do not return a value or better your float array. under "print $averageXYZ;" at the very bottom of your scirpt add the following:

return $averageXYZ;


this should really do the trick
 
  12 December 2007
I can't believe I missed that. I feel like a dunce.


Thanks a lot, it works now.
 
  12 December 2007
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 07:51 AM.


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