PDA

View Full Version : problem with for loop and lattices


j00ey
07-26-2007, 11:32 AM
I've written a pair of scripts [which are probably a bit clumsy as I'm no expert] and am trying to get rid of one error...

the first script imports 29 tubes into another scene and attaches them to motion paths with flow path objects [lattices]. It also renames the lattices, lattice bases and ffd nodes to avoid naming problems further down the line... [it does other stuff too but that all seems to work]

the second one deletes some connections made by the first then deletes the lattices and tubes etc...

I can run the import and the delete then the import again fine UNLESS i have another [30th] lattice in the scene. I've tried renaming the extra lattice / base & ffd but the import script falls over as the first newly created lattice gets the suffix 31 whilstand then tries to access #1...

if I delete the other lattice then run the import script it's fine. It's as if Maya is storing 'number of lattices created so far' and insisting on starting from that number +1. How can I reset it to 0? Or is there another way around this problem? Partitions?

Any help greatly appreciated
Many thanks in advance

ps here are the relevant chunks :

IMPORT:

for ($i = 1; $i<30; $i++)
{
select -r ("tubeGrp" + $i) ("tubePath" + $i);
pathAnimation -fractionMode true -follow true -followAxis z -upAxis y -worldUpType "vector" -worldUpVector 0 1 0 -inverseUp false -inverseFront false -bank false -startTimeU `playbackOptions -query -minTime` -endTimeU `playbackOptions -query -maxTime`;
flow -divisions 2 2 400 -objectCentered 0 -localCompute 1 -localDivisions 2 2 30 ("tubeGrp" + $i) ;
delete ("motionPath" + $i + "_uValue");
setAttr ("ffd" + $i + ".outsideLattice") 1;
rename ("ffd" + $i) ("tubeFfd" + $i);
}

//group Paths and Lattices

select -cl;
for ($i = 1; $i<30; $i++)
{
select -add ("tubePath" + $i);
}
group -name tubePathsGrp;

select -cl;
for ($i = 1; $i<30; $i++)
{
rename ("ffd" + $i + "Lattice") ("tube" + $i + "Lattice");
rename ("ffd" + $i + "Base") ("tube" + $i + "Base");
select -add ("tube" + $i + "Lattice");
select -add ("tube" + $i + "Base");
}
group -name tubeLatticesGrp;



DELETE :

string $tubeSetup[] = {"glassTubesLyr" , "trimCtrl" , "Tubes" , "tubePathsGrp" , "tubeLatticesGrp"};
int $size = `size $tubeSetup`;

for ($i = 0; $i < $size; $i++)
{
if (`objExists $tubeSetup[$i]`)
{
delete $tubeSetup[$i];
}
}

BoostAbuse
07-27-2007, 04:38 PM
Why not write yourself a simple debug statement? List the lattices inside of the scene and store them in an array, if the size of the array is greater than the number of lattices you wish, then you can pass in a new argument to say 'start at this number' or if nothing is detected, 'start at 1'.

If lattices exist, tokenize them down to the numerical index and then store that value to say if the size of the lattices is greater than 0, find the last known lattice number in the scene and re-run the script appending +1 with each creation.

Hope that helps a bit.

-s

j00ey
07-27-2007, 04:50 PM
Thanks for the tips - I'll look into those methods. I got round the problem in the end by putting this inside the loop that generates the lattices :

string $latticeNames[] = `flow -divisions 2 2 400 -objectCentered 0 -localCompute 1 -localDivisions 2 2 30 ("tubeGrp" + $i)` ;
rename $latticeNames[1] ("tubeFfd" + $i);
rename $latticeNames[2] ("tube" + $i + "Lattice");
rename $latticeNames[3] ("tube" + $i + "Base");

seems to work for now but I'll have a look into your suggestions for future reference
Thanks again

CGTalk Moderation
07-27-2007, 04:50 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.