Introduction to Maya - Modeling Fundamentals Vol 1
This course will look at the fundamentals of modeling in Maya with an emphasis on creating good topology. We'll look at what makes a good model in Maya and why objects are modeled in the way they are.
# 1 17-07-2013 , 11:07 PM
Registered User
Join Date: Jul 2013
Posts: 3

Textfield Access help.

Hey Guys,

Complete nub coder trying to streamline rigging process here.

Having an issue with textfield queries within a window, as a start just want to be able to determine the start and end points of this nSpine rig just in Y Xform value.

All I want to do is to be able to call back textfield values from a window into the proc that creates the rig, determining the start and end Y Values of the first curve. Very simple i'm sure, but just pulling my hair out. Can't seem to find the correct way to declare the variables, globally or not to make them accessible within the actual proc.

The attached script is the latest non-functional iteration. The problem seems to be in the variable declaration within the window code and query proc?

Thanks for the help and sorry for the lack of comments/understandable code.


// Creates Bound Joint Chain within nSpineCreator
proc vrtJnt(){
string $selVerts[] = `ls -sl -fl`;
for ($vrts in $selVerts){
select $vrts;
string $cl[] = `newCluster " -relative -envelope 1"`;
select -cl;
string $jnt = `joint -n bn_nSpine01 -rad 0.1`;
string $ptCnJnt[] = `pointConstraint -offset 0 0 0 -weight 1 $cl $jnt`;
string $findPtCn[] = `listRelatives -typ pointConstraint $jnt`;
select $findPtCn[0]; doDelete;
select -replace $cl; doDelete;
}
}

// Creates Joint Driver Chain within nSpineCreator
proc vrtJnt02(){
string $selVerts[] = `ls -sl -fl`;
for ($vrts in $selVerts){
select $vrts;
string $cl[] = `newCluster " -relative -envelope 1"`;
select -cl;
string $jnt = `joint -n jDrv_nSpine01 -rad 0.15`;
string $ptCnJnt[] = `pointConstraint -offset 0 0 0 -weight 1 $cl $jnt`;
string $findPtCn[] = `listRelatives -typ pointConstraint $jnt`;
select $findPtCn[0]; doDelete;
select -replace $cl; doDelete;
}
for ($jn=1; $jn<6; ++$jn ){
parent ("jDrv_nSpine0" + ($jn+1))("jDrv_nSpine0" + $jn);
}
}

// Creates nSpine
proc nSpineCreator()
{
string $spIK_crv = "spIK_nSpine01";

// PROBLEM LINE BELOW With variable definitions?
curve -d 1 -p 0 $startValue 0 -p 0 $endValue 0 -k 0 -k 1 -n spIK_nSpine01;

rebuildCurve -ch 1 -rpo 1 -rt 0 -end 0 -kr 0 -kcp 0 -kep 1 -kt 0 -s 1 -d 5 -tol 0.01 "spIK_nSpine01";
select ($spIK_crv + ".cv[*]" );
vrtJnt;
select ($spIK_crv + ".cv[*]" );
vrtJnt02;
select -r jDrv_nSpine01 ;
select -add jDrv_nSpine05 ;
select -add spIK_nSpine01 ;
ikHandle -sol ikSplineSolver -ccv false -pcv false;
for ($jn=1; $jn<7; ++$jn ){
select -r ("jDrv_nSpine0" + $jn);
select -add ("bn_nSpine0" + $jn);
pointConstraint -offset 0 0 0 -weight 1;
select -cl;
}
joint -n jCtrl_chest01 -rad 0.3;
select -cl;
joint -n jCtrl_hip01 -rad 0.3;
select -r jDrv_nSpine05;
select -add jCtrl_chest01;
pointConstraint -offset 0 0 0 -weight 1 -n pc_chestCtrl;
select -cl;
select pc_chestCtrl;
doDelete;
select jCtrl_chest01;
select -cl;
select -r jDrv_nSpine01;
select -add jCtrl_hip01;
pointConstraint -offset 0 0 0 -weight 1 -n pc_hipCtrl;
select -cl;
select pc_hipCtrl;
doDelete;
select -add jCtrl_hip01;
select -cl;
select -r jCtrl_chest01;
select -add jCtrl_hip01;
select -add spIK_nSpine01;
SmoothBindSkin;
}

// Text Field Query
// BIG PROBLEM PROC?
proc query()
{
$startValue =`floatField -query -value $floatStartName`;
$endValue =`floatField -query -value $floatEndName`;
nSpineCreator();
select -cl;
}

// Input Window
int $blankLine = 60;
string $blankLineStyle = "in";
int $buttonWidth = 100;
int $buttonHeight = 50;
string $title = "NSpine Creator";
string $nSpineWin = "nSpineCreator";
string $spineWin = $nSpineWin + "spineWin";
if (`window -exists $nSpineWin`)
deleteUI $nSpineWin;
if( `dockControl -exists $spineWin` )
deleteUI $spineWin;
window -width 700 -height 256 -sizeable true -title $title $nSpineWin;
string $form = `formLayout -parent $nSpineWin`;
columnLayout -adjustableColumn true;
separator -height $blankLine -style $blankLineStyle;
text -label $title -font "boldLabelFont" -align "center";
separator -height $blankLine -style $blankLineStyle;
rowLayout -numberOfColumns 4;
text -label "Y Start";

// PROBLEM LINE BELOW?
$floatStartName = `floatField`;

text -label "Y End";

// PROBLEM LINE BELOW?
$floatEndName = `floatField`;

setParent..;
rowLayout -numberOfColumns 2;
string $createButton = `button -label "Create!" -command "query();"`;
separator -height $blankLine -style $blankLineStyle;
setParent..;
button -label "Close" -width $buttonWidth -command "deleteUI -window nSpineCreator;";
showWindow $nSpineWin;

# 2 18-07-2013 , 02:30 AM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
There might be more issues(I'm glad you realized its messy lol) but so far the code in this procedure is trying to query undefined variables. Curly brackets{} limit the scope of variables defined inside them.

Code:
proc query()
{
$startValue =`floatField -query -value $floatStartName`;
$endValue =`floatField -query -value $floatEndName`;
nSpineCreator();
select -cl;
}


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
# 3 18-07-2013 , 11:16 PM
Registered User
Join Date: Jul 2013
Posts: 3
Thanks heaps for getting back to me.

Managed to solve it. Was to do with the declarations as you pointed out. I was throwing the incorrect arguments into the original proc and declaring the variables at the wrong time, which was causing all kinds of missing definitions and redeclarations, noob mistake from an animator whos knowledge of mel was connectAttr and select -hi and expressioned camera shakes until recently!

Now I just need to figure out how to clean up the code and get rid of all the redundancies I seem to be making. As a rule of thumb in your opinion is it good to encapsulate as many things as possible in procs for easy access and alteration later?

# 4 19-07-2013 , 02:51 AM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
Good that you got that straightened out. As for using procs, I would say yes, compartmentalize as much as you can, makes debugging and expanding so much easier. I look at my older code and shake my head as was repeating code in several areas that could have been streamlined if I had just one proc with a couple arguments and a conditional statement or two. An example I see in yours is:


vrtJnt() and vrtJnt02()

They seem very much alike with the exception of the value of the -rad flag:

Code:
string $jnt = `joint -n bn_nSpine01 -rad 0.1`;
It's possible to pass an argument(or arguments! just separate them with commas) to the proc by declaring the variable(s) within the parentheses, like:

Code:
proc vrtJnt(int $x){
	
	// Let's declare this radius variable out here so it won't be constrained to 
        // the following `if else` statement. 
	// The value of $radius will
	// depend on what the script finds when it tests the value of $x

	float $radius;
	
	if($x == 0){
		
		$radius = 0.1;
		
		print "I'm a fluffy puppy ^^/n";
		
	}else if($x == 1){
		
		$radius = .015;
		
	}//and on and on if need be or use a `case switch` if you're more comfortable with that
	
	//do some stuff that uses the variable $x like:
	string $jnt = `joint -n bn_nSpine01 -rad $radius`;
	
	//etc etc

}
Then when the proc is called, different numbers can make the script go into different modes depending on the conditional statement, in my case `0` sent it into print fluffy puppy mode! user added image

Code:
vrtJnt(0);


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
# 5 19-07-2013 , 06:09 AM
Registered User
Join Date: Jul 2013
Posts: 3
Wow, thanks for taking the time!

Have it working now querying locators for more refined positioning and number of spine joints within that length. Will save me so much time.

Ah sweet yeah, i'm screwing up like that throughout, i'll start doing that for the other parts. Also, COMMENTS AND INSETS haha! Then i'm going to port it into python. I have a mission ahead of me :p.

Laaast question, the end script will have all my rigging functionality piece by piece into it. So there are going to be I would say 15-20 individual pieces being made including basic skeleton setups and then driver setups for stretches etc etc etc. How big does a mel script have to be to warrant externally sourcing scripts and what kind of slow down would I be expecting if I started importing/including.

Thanks again guru, the fluffy puppies are in the mail as we speak.

# 6 19-07-2013 , 10:06 PM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
Oh flattery will get you everywhere but a guru I am not lol.

Interesting question about about sourcing. I don't know how much code would start slowing things down in that regard, I'm sure other factors like machine specs play their part, I know I haven't hit that ceiling yet. I think plugins would do that quicker. Maya is loaded in under 5 seconds on this machine(i7 3.4GHz + 16GB RAM) and I have quite a bit of source lines in my userSetup file. All my little "quality of life" procs I tossed into one file and it keeps getting expanded, most of the other files revolve around specific tools and those tend to be even larger. I'm getting the same start up time with default prefs.


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads