PDA

View Full Version : MEL array weirdness


doppelganger
07-28-2003, 02:20 AM
One more question everyone
When I try and capture the names of each object I create with this command
string $pikes[] = `polyCone -r 1 -h 2 -sx 3 -sy 1 -sz 0 -ax 0 1 0 -tx 1 -ch 1`;
which is in a do/while loop
when the loop terminates and I print the contents of the string I get the following list
print $pikes;
time1
renderPartition
renderGlobalsList1
defaultLightList1
defaultShaderList1
postProcessList1
defaultRenderUtilityList1
lightList1
defaultTextureList1
lambert1
particleCloud1
initialShadingGroup
initialParticleSE
initialMaterialInfo
shaderGlow1
dof1
defaultRenderGlobals
defaultRenderQuality
defaultResolution
defaultLightSet
defaultObjectSet
characterPartition
defaultHardwareRenderGlobals
hyperGraphInfo
hyperGraphLayout
globalCacheControl
ikSystem
dynController1
strokeGlobals
persp
perspShape
top
topShape
front
frontShape
side
sideShape
lightLinker1
layersFilter
objectTypeFilter50
renderLayersFilter
objectTypeFilter51
renderingSetsFilter
objectTypeFilter52
relationshipPanel1LeftAttrFilter
relationshipPanel1RightAttrFilter
layerManager
defaultLayer
renderLayerManager
defaultRenderLayer
globalRender
pCone1
pConeShape1
polyCone1
pCone2
...

why does it add all these other items and not just the poly cones I created?

Thanks

Scott

bigfatMELon
07-28-2003, 04:16 AM
Can you post your entire Do/While loop? There isn't enough info here to figure out how you are getting that result.

-jl

doppelganger
07-29-2003, 12:21 AM
Sure, here is the source

//declare variables for the rotate x and y values

float $initalx = 0;
int $pike_count = 0;

seed (1);


do {

float $rotx = `rand 0 78`;
float $roty = `rand -30 30`;
float $trans = `rand .5`;


//create cone
string $pikes[] = `polyCone -r 1 -h 2 -sx 3 -sy 1 -sz 0 -ax 0 1 0 -tx 1 -ch 1`;

//scale into shape of pike
scale -r .088 10.001 .076;

//move pivot to base of pike
xform -ws -piv 0 -10 0;

//move pike to groundplane
move -rpr -y 0;

//duplicate with random xy transform
//duplicate -rr; move -r 1;

//rotate in the x and y axes to tilt forward and to side
rotate -ws $rotx $roty 0;

//add one to $pike_count
$pike_count ++;


print $pike_count;
}
while ($pike_count < 10);

GDC
07-29-2003, 12:51 AM
umm... I don't see any place where you are gathing up $pikes to print it. The way you have it now everytime your do while loop runs it resets $pikes with the new results from polyCone.

If you wan to keep an array with all of the names of the objects you create in your loop, I'd do it like this:

string $allNames[];
int $pike_count = 0;

do{
//create cone
string $pikes[] = `polyCone -r 1 -h 2 -sx 3 -sy 1 -sz 0 -ax 0 1 0 -tx 1 -ch 1`;

// add this name to the array
$allNames[size($allNames)]=$pikes[0];

//add one to $pike_count
$pike_count ++;

}
while ($pike_count < 10);

print $allNames;



--g

doppelganger
07-29-2003, 05:45 AM
Thanks for the reply it is exaxtly what I needed. Could I trouble you to tell me what exactly the following line does?

// add this name to the array
$allNames[size($allNames)]=$pikes[0];

I am familiar with using size () and I see that it does the job I need it to do but how is it going about doin it? I would look it up in the docs but the syntax is such I am not sure what to look up : )

Thanks again for your help!

Scott

bigfatMELon
07-29-2003, 05:01 PM
the result ead like this:

Put the first item of $pikes into $allNames at the index position that is one larger than the last one in that array. Array indexes start at zero, so the following works:

$pikes[0] = "this is the first position";
$pikes[1] = "this is the second position";
$pikes[2] = "this is the third position";

Now, if you don't know what the next available position is, like when you are adding things to an array within a loop, you need a while to assign data to the next available spot in the array. Conveniently, the size of the array will always point to the next available index because indexes are zero inclusive. Using the array we created above:

size($pikes);
//3

There are three items in the array and the last item is index #2, so that brings us to:

$allNames[size($allNames)]=$pikes[0]

-jl

doppelganger
07-29-2003, 05:59 PM
Thanks for the details! I get it now :)

Cheers!

Scott

anopheles
09-10-2005, 01:44 PM
I just started a search and was directly linked with this thread!
I was searching for
relationshipPanel1RightAttrFilter

this nodes get created when I execute my UI Script!

This is what creates a panel:

string $camera = `columnLayout -adjustableColumn true`;
string $subTestcam = `frameLayout -w 600 -h 600 -mw 0 -lv false -bv true -bs "etchedOut"`;
string $testcam = `modelPanel -l "Facial Controlls" -cam "front1"`;
modelEditor -e -grid 0 $testcam;
setParent $camera;

weird!

CGTalk Moderation
09-10-2005, 01:44 PM
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.