HA !
* * *
1) the $counter wasn't defined before the while loop thus it was zero and didn't create the lines.
2) Joss gave me an idea. i always only created the first plane and copied it (i'm a lazy bastard). this never worked. solution: just create two planes completely newly.
thanks until now... i work on now...
* * *
deadalvs
* * *
script:
if (`window -exists "TrussWindow"` == 1){deleteUI "TrussWindow";}
window -title "TrussCreateWindow" -mnb 0 -mxb 0 TrussWindow;
columnLayout -adjustableColumn 1;
setParent ..;
setParent ..;
frameLayout -label "Create Trusses" -cll true;
columnLayout;
button -label "Get two selected Nurbs" -command "getNurbs();";
separator -w 300;
text -l "Number of randomized sticks";
intField stickCount;
button -label "Simple randomized Truss" -command "randTruss `intField -q -v stickCount`";
separator -w 300;
showWindow TrussWindow;
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
global proc getNurbs()
//gets the names of the 2 nurbs surfaces, and adds these names to 2 global variables. repeat for the shape nodes.
{
//first define the 4 global variables needed. global variables can be used to transfer data between procs.
//in order to avoid the "must be given a constant value" error, you first create the variable, and then give it a value.
global string $nurbsTrans1;
global string $nurbsTrans2;
global string $nurbsShape1;
global string $nurbsShape2;
//find the 2 selected nurbs surfaces
string $sel[] = `ls -sl`;
//add those two nurbs surfaces to the global variables we have already created.
$nurbsTrans1 = $sel[0];
$nurbsTrans2 = $sel[1];
//now repeat the process for the shape nodes
pickWalk -d down;
string $selShape[] = `ls -sl`;
$nurbsShape1 = $selShape[0];
$nurbsShape2 = $selShape[1];
print $sel;
}
/*************************************************************************/
global proc randTruss(int $stickCount)
{
//as you have already done for the $stickCount variable, you need to reassign the global variables in this proc.
//in the rest of the code, I have replaced instances of '$selShape' with the global variables created above.
//$sel[0] becomes $nurbsTrans1
//$sel[1] becomes $nurbsTrans2
//$selShape[0] becomes $nurbsShape1
//$selShape[1] becomes $nurbsShape2
global int $stickCount;
global string $nurbsTrans1;
global string $nurbsTrans2;
global string $nurbsShape1;
global string $nurbsShape2;
//select "STAB*";
//delete;
vector $vectorP1;
vector $vectorP2;
int $U1 = `nurbsPlane -q -patchesU $nurbsShape1`;
int $V1 = `nurbsPlane -q -patchesV $nurbsShape1`;
int $U2 = `nurbsPlane -q -patchesU $nurbsShape2`;
int $V2 = `nurbsPlane -q -patchesV $nurbsShape2`;
int $counter = $stickCount;
//sticks are created until the stickCount is reached. they only get created if the randomized points of the two surfaces are less than
//2.5 units away from each other.
while ($counter < $stickCount)
{
global int $stickCount;
string $sel[];
vector $vectorP1;
vector $vectorP2;
int $ZufallU1 = `floor (rand (0, ($U1 + 3)))`;
int $ZufallV1 = `floor (rand (0, ($V1 + 3)))`;
int $ZufallU2 = `floor (rand (0, ($U2 + 3)))`;
int $ZufallV2 = `floor (rand (0, ($V2 + 3)))`;
$vectorP1 = `pointPosition ($nurbsTrans1 + ".cv" + "[" + $ZufallU1 + "][" + $ZufallV1 + "]")`;
$vectorP2 = `pointPosition ($nurbsTrans2 + ".cv" + "[" + $ZufallU2 + "][" + $ZufallV2 + "]")`;
print $vectorP1;
print $vectorP1;
$squaredDist =`pow ($vectorP2.x - $vectorP1.x) 2` + `pow ($vectorP2.y - $vectorP1.y) 2` + `pow ($vectorP2.z - $vectorP1.z) 2` ;
$dist = `sqrt $squaredDist`;
if ($dist <= 2.5)
{
curve -d 1 -p ($vectorP1.x) ($vectorP1.y) ($vectorP1.z) -p ($vectorP2.x) ($vectorP2.y) ($vectorP2.z) -k 0 -k 1 ;
rename "STAB_";
$counter ++;
}
}
print "\nEnd of Proc";
}