proc string getValueFromComponent ( string $component ) { /* This procedure should take a component selection ( such as Sphere.u[1] ) and strip out everything but the number value in brackets, which should be returned back to the parent script. */ string $xfer = `match "\\..*" $component`; // strip out everything before the . // (in case there are numbers in the name) string $command = "match \"[0-9]+\"" + $xfer; // now return only numbers $value = `eval ( $command )`; return $value; } proc ajhNAD ( string $sel1, string $sel2 ) { /* This procedure should take two string inputs - either 2 NURBS surfaces or 2 NURBS isoparm selections. The procedure should attempt to attach the surfaces together using a .5 blend option. Then, it will rebuild the resulting surface to go from 0 to the number of spans. After that, it will detach the surface at the Span# matching the number of spans of the original 1st surface, which (should) detach the surfaces at the same isoparm where they were attached at. Then both surfaces should be rebuilt to be Uniform and from 0 to 1. After that, there is a good chance that one or both surfaces had a U or V direction changed on them, so the script will try to predict which directions were switched and switch them back. */ $surf1 = $sel1; // we need to so some stuff to the $sel variables, $surf2 = $sel2; // but we need them later so we'll duplicate them here $iso1u = `eval ("gmatch " + $sel1 + " \"*.u*\"")`; // is a u iso selected? $iso1v = `eval ("gmatch " + $sel1 + " \"*.v*\"")`; // is a v iso selected? $iso2u = `eval ("gmatch " + $sel2 + " \"*.u*\"")`; // is a u iso selected? $iso2v = `eval ("gmatch " + $sel2 + " \"*.v*\"")`; // is a v iso selected? string $surf1value; string $surf2value; if ( $iso1u || $iso1v ) { $surf1value = `getValueFromComponent( $sel1 )`; // grab the U or V value from the 1st object } if ( $iso2u || $iso2v ) { $surf2value = `getValueFromComponent( $sel2 )`; // grab the U or V value from the 2nd object } /* print "\n"; print " iso1U "; print $iso1u; print " iso1V "; print $iso1v; print " surf1value "; print $surf1value; // debugging spew print "\n"; // debugging spew print " iso2U "; print $iso2u; // debugging spew print " iso2V "; print $iso2v; print " surf2value "; print $surf2value; print "\n"; */ if ( $iso1u || $iso1v ) { // if it's an isoparm selection $surf1 = `eval ( "match \"^[^\.]*\" " + $sel1 )`; // grab the surface name } if ( $iso2u || $iso2v ) { // if it's an isoparm selection $surf2 = `eval ( "match \"^[^\.]*\" " + $sel2 )`; // grab the surface name } $surf1spansU = `getAttr ( $surf1 + ".spansU" )`; // get the number of spans $surf1spansV = `getAttr ( $surf1 + ".spansV" )`; // in both directions $surf2spansU = `getAttr ( $surf2 + ".spansU" )`; // get the number of spans $surf2spansV = `getAttr ( $surf2 + ".spansV" )`; // in both directions // attach the two surfaces (or isoparms) $newSurfaceList = `attachSurface -ch 1 -rpo 1 -kmk 1 -m 1 -bb 0.5 -bki 0 -p 0.1 $sel1 $sel2`; // remember the new surface and attachNode $newSurface = $newSurfaceList[0]; $attacheNode = $newSurfaceList[2]; // is the surface attached in the U Direction? $isU = `getAttr ( $attacheNode + ".directionU" )`; refresh; // gotta refresh or something screws up here // delete the old surface 2 delete $surf2; // rebuild the new surface as Uniform and 0 to numspans $newSurfaceList = `rebuildSurface -ch 1 -rpo 1 -rt 0 -end 1 -kr 2 -kcp 1 -kc 1 -su 4 -du 3 -sv 4 -dv 3 -tol 0.01 -dir 2 $newSurface`; // store the new surface $newSurface = $newSurfaceList[0]; string $newDetached[]; //detach the new surface at the point where the 2 original surfaces were attached //based on whether is was atached in U or V if ( $isU ) $newDetached = `detachSurface -ch 1 -rpo 1 ( $newSurface + ".u[" + $surf1spansU + "]" )`; else $newDetached = `detachSurface -ch 1 -rpo 1 ( $newSurface + ".v[" + $surf1spansV + "]" )`; rename $newDetached[0] $surf2; // rename the new surfaces to the old names rename $newDetached[1] $surf1; // rename the new surfaces to the old names //rebuild both new surfaces to be Uniform and 0 - 1 rebuildSurface -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 1 -kc 1 -su 4 -du 3 -sv 4 -dv 3 -tol 0.01 -dir 2 $surf2; rebuildSurface -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 1 -kc 1 -su 4 -du 3 -sv 4 -dv 3 -tol 0.01 -dir 2 $surf1; /* This next section attempts to return the surface to the orientation it was in before we started attaching anddetaching. This is good so that if a bunch of selection pairs were made it has less of a chance of screwing up and exploding the model. It doesn't work in all instances yet though... */ if ( $iso1u && $iso2v ) { if ( ( $surf1value == 0 ) && ( $surf2value == 1 ) ) { reverseSurface -d 0 -ch 1 -rpo 1 $surf1; // U reverseSurface -d 3 -ch 1 -rpo 1 $surf2; // SWAP reverseSurface -d 2 -ch 1 -rpo 1 $surf2; // BOTH } if ( ( $surf1value == 1 ) && ( $surf2value == 0 ) ) { reverseSurface -d 3 -ch 1 -rpo 1 $surf2; // SWAP reverseSurface -d 0 -ch 1 -rpo 1 $surf2; // U } if ( ( $surf1value == 0 ) && ( $surf2value == 0 ) ) { reverseSurface -d 0 -ch 1 -rpo 1 $surf1; // U reverseSurface -d 3 -ch 1 -rpo 1 $surf2; // SWAP reverseSurface -d 0 -ch 1 -rpo 1 $surf2; // V } if ( ( $surf1value == 1 ) && ( $surf2value == 1 ) ) { reverseSurface -d 2 -ch 1 -rpo 1 $surf2; // BOTH reverseSurface -d 3 -ch 1 -rpo 1 $surf2; // SWAP } } if ( $iso1v && $iso2u ) { if ( ($surf1value == 1 ) && ( $surf2value == 0 ) ) { reverseSurface -d 3 -ch 1 -rpo 1 $surf2; // SWAP reverseSurface -d 1 -ch 1 -rpo 1 $surf2; // V } if ( ($surf1value == 0 ) && ( $surf2value == 0 ) ) { reverseSurface -d 1 -ch 1 -rpo 1 $surf1; // V reverseSurface -d 3 -ch 1 -rpo 1 $surf2; // SWAP //reverseSurface -d 1 -ch 1 -rpo 1 $surf2; // V } if ( ($surf1value == 0 ) && ( $surf2value == 1 ) ) { reverseSurface -d 1 -ch 1 -rpo 1 $surf1; // V reverseSurface -d 3 -ch 1 -rpo 1 $surf2; // SWAP reverseSurface -d 0 -ch 1 -rpo 1 $surf2; // V reverseSurface -d 1 -ch 1 -rpo 1 $surf2; // V } if ( ($surf1value == 1 ) && ( $surf2value == 1 ) ) { reverseSurface -d 3 -ch 1 -rpo 1 $surf2; // SWAP reverseSurface -d 2 -ch 1 -rpo 1 $surf2; // BOTH } } if ( $iso1v && $iso2v ) { if ( ($surf1value == 0 ) && ( $surf2value == 1 ) ) { reverseSurface -d 1 -ch 1 -rpo 1 $surf1; // V reverseSurface -d 1 -ch 1 -rpo 1 $surf2; // V } if ( ($surf1value == 1 ) && ( $surf2value == 1 ) ) { reverseSurface -d 1 -ch 1 -rpo 1 $surf2; // V } if ( ($surf1value == 1 ) && ( $surf2value == 0 ) ) { reverseSurface -d 0 -ch 1 -rpo 1 $surf2; // U } if ( ($surf1value == 0 ) && ( $surf2value == 0 ) ) { reverseSurface -d 1 -ch 1 -rpo 1 $surf1; // V reverseSurface -d 0 -ch 1 -rpo 1 $surf2; // U } } if ( $iso1u && $iso2u ) { if ( ($surf1value == 0 ) && ( $surf2value == 1 ) ) { reverseSurface -d 0 -ch 1 -rpo 1 $surf1; // U reverseSurface -d 0 -ch 1 -rpo 1 $surf2; // U // reverseSurface -d 1 -ch 1 -rpo 1 $surf2; // V } if ( ($surf1value == 1 ) && ( $surf2value == 1 ) ) { reverseSurface -d 2 -ch 1 -rpo 1 $surf2; // BOTH } if ( ($surf1value == 1 ) && ( $surf2value == 0 ) ) { reverseSurface -d 1 -ch 1 -rpo 1 $surf2; // U } if ( ($surf1value == 0 ) && ( $surf2value == 0 ) ) { reverseSurface -d 0 -ch 1 -rpo 1 $surf1; // U } } } global proc ajhGONAD() { /* This procedure should grab the current selection and then run the ajhNAd procedure on each set of two objects selected. Later on thist procedure should filter out the non-NURBS objects, and check to make sure there is an even number of objects selected. */ $selectionList = `ls -sl`; $selSize = size($selectionList); //grab the selection select -cl; //clear the selection for ($i = 0; $i < $selSize; $i = $i + 2) { ajhNAD ( $selectionList[$i], $selectionList[$i + 1] ); //run ajhNAD on every selected pair } select -r $selectionList; //reselect the original selection }