DualOpAmp
12-28-2007, 04:37 PM
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;
}
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;
}
