PDA

View Full Version : Help with UV-manipulation


DeadlyNightshade
08-07-2012, 09:11 PM
Hi
I'm working on the textureWindowCreateToolbar.mel to create additional shortcut buttons in the standard UV texture editor. So far things have gone a lot better then expected, but now I've bumped into problems and need help.

What I wanna change compared to the default code is to remove one of the input fields (one is enough for me) and to add a lot of extra buttons. Now that part seems settled (I think) - although I'm unsure that the buttons are "hooked" to the input field correctly. Either way: the procedures I use to manipulate the UV's are based on the nudgeIt -MEL script. So I've basicly taken that way of writing and applying it on my own stuff. So far the code looks like this:

/////////////////////////////
// Functions and variables //
/////////////////////////////

global float $manipAmt;
$manipAmt=0.1;

global proc UVmanip(float $manipAmt)
{
print ("Manipulation value set to: "+$manipAmt+" UV units.");
}

global proc UVmanipulation(float $manipType, float $manipAmt)
{
switch ($manipType){
case "1":
polyEditUV -u 0 -v $manipAmt; // Up
break;

case "2":
polyEditUV -u ($manipAmt * -1) -v 0; // Left
break;

case "3":
polyEditUV -u $manipAmt -v 0; // Right
break;

case "4":
polyEditUV -u 0 -v ($manipAmt * -1); // Down
break;

case "5":
polyEditUV -a ($manipAmt * -1); // CW Rotation
break;

case "6":
polyEditUV -a $manipAmt; // CCW Rotation
break;

case "7":
polyEditUV -s ($manipAmt); // Scale up
break;

case "8":
polyEditUV -s ($manipAmt * -1); // Scale down
break;

case "9":
polyEditUV -su ($manipAmt * 1); // Scale U up
break;

case "10":
polyEditUV -su ($manipAmt * -1); // Scale U down
break;

case "11":
polyEditUV -sv ($manipAmt * 1); // Scale V up
break;

case "12":
polyEditUV -sv ($manipAmt * -1); // Scale V down
break;
}
}

/////////////////////
// UV Manip layout //
/////////////////////
setParent ..;

//
// Init hidden/shown option var
//
if (!`optionVar -exists "showStatusCopyPaste"`) {
optionVar -intValue "showStatusCopyPaste" 1;
}

string $toggleCopyPasteCmd = "\"copyPasteLayout\", " +
"\"copyPasteCollapse\", " +
"\"\", " +
"\"showStatusCopyPaste\")";

//
// Set up open/close bar
//
setUITemplate -pushTemplate TexWinBarTemplate;

iconTextButton -vis true
-parent $gUVTexEditToolBar
-annotation (uiRes("m_textureWindowCreateToolBar.kShowHideCopyPasteIconsAnnot"))
-i1 textureEditorOpenBar.png
-c ("textureWindowCreateToolBar_toggleIcons(-1," + $toggleCopyPasteCmd)
copyPasteCollapse;

setUITemplate -popTemplate;

//
// Set up icons
//
// copy/paste controls
formLayout manipLayout;

global string $uvEntryField;

setUITemplate -pushTemplate TexWinFloatFieldTemplate;

int $floatFieldWidth = $iconSize * 2 + $horizGap;
floatField
-precision 3
-ed true
-width $floatFieldWidth
-annotation (uiRes("m_textureWindowCreateToolBar.kEnterValueTotransformInUAnnot"))
$uvEntryField;

setUITemplate -popTemplate;

//
// Klart för test och felsök
//
setUITemplate -pushTemplate TexWinButtonTemplate;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(1,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipMoveUp;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(4,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipMoveDown;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(2,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipMoveLeft;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(3,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipMoveRight;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(5,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipRotCW;

setUITemplate -popTemplate;


setUITemplate -pushTemplate TexWinButtonTemplate;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(6,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipRotCCW;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(7,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipScaleUp;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(8,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipScaleDown;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(9,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipScaleUpU;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(10,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipScaleDownU;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(11,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipScaleUpV;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(12,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipScaleDownV;

setUITemplate -popTemplate;


formLayout -edit

-attachForm uvEntryField "top" $edgeMargins
-attachForm uvEntryField "left" 0

-attachControl manipRotCCW "top" $edgeMargins
-attachControl manipRotCCW "left" uvEntryField
-attachControl manipRotCW "top" $edgeMargins
-attachControl manipRotCW "left" manipRotCCW

-attachControl manipScaleUp "top" $edgeMargins
-attachControl manipScaleUp "left" manipRotCW
-attachControl manipScaleUpU "top" $edgeMargins
-attachControl manipScaleUpU "left" manipScaleUp
-attachControl manipScaleUpV "top" $edgeMargins
-attachControl manipScaleUpV "left" manipScaleUpU

-attachForm manipMoveLeft "left" 0
-attachControl manipMoveLeft "top" uvEntryField
-attachControl manipMoveRight "left" manipMoveLeft
-attachControl manipMoveRight "top" uvEntryField
-attachControl manipMoveUp "left" manipMoveRight
-attachControl manipMoveUp "top" manipRotCCW
-attachControl manipMoveBottom "left" manipMoveUp
-attachControl manipMoveBottom "top" manipRotCW

-attachControl manipScaleDown "left" manipMoveDown
-attachControl manipScaleDown "top" manipScaleUp
-attachControl manipScaleDownU "left" manipScaleDown
-attachControl manipScaleDownU "top" manipScaleUpU
-attachControl manipScaleDownV "left" manipScaleDownU
-attachControl manipScaleDownV "top" manipScaleUpV

manipLayout;
Maya whines a lot about the UVmanipulation -procedure, saying it has bad nesting and that it has too many parameters of $manipAmt. I'm a MEL noob so I really don't see where the problem is here or why it is happening: and the script editor is bad at explaining

(Some of the annotations are empty but DW about that - i'll fix that later)

NaughtyNathan
08-07-2012, 10:22 PM
try removing all those if...else commands and replace the whole kit and caboodle with switch..case instead:

http://download.autodesk.com/global/docs/maya2012/en_us/files/Controlling_the_flow_of_a_script_switch...case.htm

DeadlyNightshade
08-07-2012, 10:57 PM
Thanks. That's a better way of writing it.
Now, the errors.

My global procedure declarations give me the following errors:

"Procedures cannot be nested within each other."
"Procedure has multiple parameters named "$manipAmt"

I don't understand why it's whining. I don't see any nested procedures. All I see is variables inside these procedures.

NaughtyNathan
08-08-2012, 10:47 AM
where exactly are you placing all this code? there doesn't appear to be a problem with what you've posted so I'm guessing you're pasting this inside an existing Maya MEL script, and maybe inside an existing proc definition..?
I'm not sure what else to suggest because as it stands it's fine... (at least it doesn't exhibit the errors you're seeing when I run it)

DeadlyNightshade
08-08-2012, 11:39 AM
I see.
Well I'm currently at work so I can't upload/check my script file either. But I'll upload it and post a download link here once I get home.

Thanks for your help.

DeadlyNightshade
08-08-2012, 07:52 PM
Well it seems like it's nested after all. My code is located in the global procedure that creates the actual UV toolbar:

global proc textureWindowCreateToolBar(string $toolBar,
string $editor,
string $editorCmd)
// Description: Add the texture window toolbar
{
...so things should be cool if I just move these procedures outside so they are not nested correct?

Either way, here is my script:

Download:
http://www.speedyshare.com/sBWzC/scripts.zip
textureWindowCreateToolbar.mel
textureWindowCreateToolbar.res.mel

Files goes to:
c:\Users\ your user \Documents\maya\ maya version \scripts
(warning - these files replace the default Autodesk scripts. Do a backup before you copy)

DeadlyNightshade
08-08-2012, 08:34 PM
/////////////////////
// UV Manip layout //
/////////////////////
setParent ..;

//
// Init hidden/shown option var
//
if (!`optionVar -exists "showStatusCopyPaste"`) {
optionVar -intValue "showStatusCopyPaste" 1;
}

string $toggleCopyPasteCmd = "\"copyPasteLayout\", " +
"\"copyPasteCollapse\", " +
"\"\", " +
"\"showStatusCopyPaste\")";

//
// Set up open/close bar
//
setUITemplate -pushTemplate TexWinBarTemplate;

iconTextButton -vis true
-parent $gUVTexEditToolBar
-annotation (uiRes("m_textureWindowCreateToolBar.kShowHideCopyPasteIconsAnnot"))
-i1 textureEditorOpenBar.png
-c ("textureWindowCreateToolBar_toggleIcons(-1," + $toggleCopyPasteCmd)
copyPasteCollapse;

setUITemplate -popTemplate;

//
// Set up icons
//
// copy/paste controls
formLayout UVmanipLayout;

setUITemplate -pushTemplate TexWinFloatFieldTemplate;

global string $uvEntryField;


int $floatFieldWidth = $iconSize * 2 + $horizGap;
floatField
-precision 3
-ed true
-width $floatFieldWidth
-annotation (uiRes("m_textureWindowCreateToolBar.kEnterValueTotransformInUAnnot"))
$uvEntryField;

setUITemplate -popTemplate;

//
// Note to self: Layout still needs testing
//
setUITemplate -pushTemplate TexWinButtonTemplate;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(6,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipRotCCW;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(5,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipRotCW;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(7,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipScaleUp;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(9,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipScaleUpU;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(11,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipScaleUpV;

setUITemplate -popTemplate;

setUITemplate -pushTemplate TexWinButtonTemplate;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(2,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipMoveLeft;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(3,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipMoveRight;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(1,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipMoveUp;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(4,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipMoveDown;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(8,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipScaleDown;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(10,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipScaleDownU;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-width $iconSize -height $iconSize
-command "UVmanipulation(12,$manipAmt)"
-annotation (getRunTimeCommandAnnotation (" "))
manipScaleDownV;

setUITemplate -popTemplate;


formLayout -edit

-attachForm uvEntryField "top" $edgeMargins
-attachForm uvEntryField "left" 0

-attachControl manipRotCCW "top" $edgeMargins
-attachControl manipRotCCW "left" $margin uvEntryField
-attachControl manipRotCW "top" $edgeMargins
-attachControl manipRotCW "left" $margin manipRotCCW

-attachControl manipScaleUp "top" $edgeMargins
-attachControl manipScaleUp "left" $margin manipRotCW
-attachControl manipScaleUpU "top" $edgeMargins
-attachControl manipScaleUpU "left" $margin manipScaleUp
-attachControl manipScaleUpV "top" $edgeMargins
-attachControl manipScaleUpV "left" $margin manipScaleUpU

-attachForm manipMoveLeft "left" 0
-attachControl manipMoveLeft "top" $margin uvEntryField
-attachControl manipMoveRight "left" $margin manipMoveLeft
-attachControl manipMoveRight "top" $margin uvEntryField
-attachControl manipMoveUp "left" $margin manipMoveRight
-attachControl manipMoveUp "top" $margin manipRotCCW
-attachControl manipMoveBottom "left" $margin manipMoveUp
-attachControl manipMoveBottom "top" $margin manipRotCW

-attachControl manipScaleDown "left" $margin manipMoveDown
-attachControl manipScaleDown "top" $margin manipScaleUp
-attachControl manipScaleDownU "left" $margin manipScaleDown
-attachControl manipScaleDownU "top" $margin manipScaleUpU
-attachControl manipScaleDownV "left" $margin manipScaleDownU
-attachControl manipScaleDownV "top" $margin manipScaleUpV

UVmanipLayout;

Error: line 2084: Too many arguments. Expected 1, found 2.
Line 2084 is the last one in the above code: UVmanipLayout

NaughtyNathan
08-08-2012, 09:45 PM
the -attachControl flags should have string string INT string parameters...

DeadlyNightshade
08-08-2012, 10:43 PM
Thanks - I've fixed that now. I had forgotten to add the $margin variable on the controllers.
I still get the same kind of error though: Too many arguments.

(the last string of the -attachControl flag isn't necessary btw - it even looks like that in the default code, many controllers end with just $edgeMargins)

EDIT: I don't get it and I'm starting to get angry. I can't see any syntax errors - and I even compared it to the default code (compared in notepad++ side by side - the code is found below) and it has the same structure:

// DEFAULT MOVE and COPY LAYOUT GROUP

////////////////
// Copy/Paste //
////////////////
setParent ..;

//
// Init hidden/shown option var
//
if (!`optionVar -exists "showStatusCopyPaste"`) {
optionVar -intValue "showStatusCopyPaste" 1;
}

string $toggleCopyPasteCmd = "\"copyPasteLayout\", " +
"\"copyPasteCollapse\", " +
"\"\", " +
"\"showStatusCopyPaste\")";

//
// Set up open/close bar
//
setUITemplate -pushTemplate TexWinBarTemplate;

iconTextButton -vis true
-parent $gUVTexEditToolBar
-annotation (uiRes("m_textureWindowCreateToolBar.kShowHideCopyPasteIconsAnnot"))
-i1 textureEditorOpenBar.png
-c ("textureWindowCreateToolBar_toggleIcons(-1," + $toggleCopyPasteCmd)
copyPasteCollapse;

setUITemplate -popTemplate;

//
// Set up icons
//
// copy/paste controls
formLayout copyPasteLayout;

// UV Entry field. Will allow user to set current uv value
// of uv in selection list. Will update when selection list
// changes.
//
// Ideally the fields should update as the selected UV(s)
// is/are transformed but there is not a good way to do
// this. Should be an event that exists for scriptJob.

global string $uvEntryFieldU;
global string $uvEntryFieldV;

setUITemplate -pushTemplate TexWinFloatFieldTemplate;

int $floatFieldWidth = $iconSize * 2 + $horizGap;
floatField
-precision 3
-ed true
-cc "textureWindowUVEntryCommand(1)"
-width $floatFieldWidth
-annotation (uiRes("m_textureWindowCreateToolBar.kEnterValueTotransformInUAnnot"))
$uvEntryFieldU;

floatField
-precision 3
-ed true
-cc "textureWindowUVEntryCommand(0)"
-width $floatFieldWidth
-annotation (uiRes("m_textureWindowCreateToolBar.kEnterValueTotransformInVAnnot"))
$uvEntryFieldV;

setUITemplate -popTemplate;

setUITemplate -pushTemplate TexWinButtonTemplate;

// originally planned to lock current UV values but it's
// more important to have an update button for the selected
// UV's coordinates
iconTextButton
-image1 "uvUpdate.png"
-annotation (uiRes("m_textureWindowCreateToolBar.kRefreshUVValuesAnnot"))
-command "undoInfo -swf false; textureWindowCreateToolBar_isUVTransformed; undoInfo -swf true;"
-commandRepeatable true -label (uiRes("m_textureWindowCreateToolBar.kRefreshUVValuesLbl"))
updateValueButton;

setUITemplate -popTemplate;

setUITemplate -pushTemplate TexWinCheckBoxTemplate;

iconTextCheckBox
-image1 "uvEntryToggle.png"
-onCommand "uvEntryTransformModeCommand"
-offCommand "uvEntryTransformModeCommand"
-value $gUVEntryTransformMode
-annotation (uiRes("m_textureWindowCreateToolBar.kUVTransformationEntryAnnot"))
uvEntryTransformModeButton;

setUITemplate -popTemplate;

setUITemplate -pushTemplate TexWinButtonTemplate;

iconTextButton
-image1 "copyUV.png"
-command "PolygonCopy"
-annotation (getRunTimeCommandAnnotation ("PolygonCopy"))
copyUVButton;

popupMenu -button 3
-parent copyUVButton
-postMenuCommand "PolygonCopyOptions"
copyUVButtonPopup;

iconTextButton
-image1 "pasteUV.png"
-command "PolygonPaste"
-annotation (getRunTimeCommandAnnotation ("PolygonPaste"))
pasteUVButton;

popupMenu -button 3
-parent pasteUVButton
-postMenuCommand "PolygonPasteOptions"
pasteUVButtonPopup;

setUITemplate -popTemplate;

setUITemplate -pushTemplate TexWinCheckBoxTemplate;

iconTextCheckBox
-image1 "copyUVMode.png"
-onCommand "textureWindowCreateToolBar_copyPasteMode 1"
-offCommand "textureWindowCreateToolBar_copyPasteMode 0"
-annotation (uiRes("m_textureWindowCreateToolBar.kToggleCopyPasteAnnot"))
copyModeButton;

setUITemplate -popTemplate;

setUITemplate -pushTemplate TexWinButtonTemplate;

iconTextButton
-enable false
-image1 "pasteUDisabled.png"
-command "textureWindowCreateToolBar_uvPaste 1 0"
-annotation (uiRes("m_textureWindowCreateToolBar.kPasteUValueAnnot"))
pasteUButton;

iconTextButton
-enable false
-image1 "pasteVDisabled.png"
-width $iconSize -height $iconSize
-command "textureWindowCreateToolBar_uvPaste 0 1"
-annotation (uiRes("m_textureWindowCreateToolBar.kPasteVValueAnnot"))
pasteVButton;

iconTextButton
-image1 "cycleUVs.png"
-command "polyRotateUVsByVertex"
-commandRepeatable true -label (uiRes("m_textureWindowCreateToolBar.kCycleUVsCounterClockwiseLbl"))
-annotation (uiRes("m_textureWindowCreateToolBar.kCycleUVsCounterClockwiseAnnot"))
cycleUVsButton;

setUITemplate -popTemplate;

formLayout -edit

-attachForm uvEntryFieldU "top" $vertGap
-attachForm uvEntryFieldU "left" 0
-attachForm uvEntryFieldV "top" $vertGap
-attachControl uvEntryFieldV "left" $horizGap uvEntryFieldU
-attachForm updateValueButton "top" 0
-attachControl updateValueButton "left" $horizGap uvEntryFieldV
-attachForm uvEntryTransformModeButton "top" 0
-attachControl uvEntryTransformModeButton "left" $horizGap updateValueButton

-attachControl copyUVButton "top" $vertGap uvEntryFieldU
-attachForm copyUVButton "left" 0
-attachControl pasteUVButton "top" $vertGap uvEntryFieldU
-attachControl pasteUVButton "left" $horizGap copyUVButton
-attachControl pasteUButton "top" $vertGap uvEntryFieldU
-attachControl pasteUButton "left" $horizGap pasteUVButton
-attachControl pasteVButton "top" $vertGap uvEntryFieldU
-attachControl pasteVButton "left" $horizGap pasteUButton
-attachControl copyModeButton "top" $vertGap uvEntryFieldU
-attachControl copyModeButton "left" $horizGap pasteVButton
-attachControl cycleUVsButton "top" $vertGap uvEntryFieldU
-attachControl cycleUVsButton "left" $horizGap copyModeButton
copyPasteLayout;
*/
// DEFAULT MOVE and COPY LAYOUT GROUP END
//
It's commented out because I'm saving the original code in my script file. Either way, the only differences really are variable names, and that the default code has two fields and some other button types and that's it.

DeadlyNightshade
08-09-2012, 09:23 PM
Current code:
/////////////////////
// UV Manip layout //
/////////////////////

setParent ..;

//
// Init hidden/shown option var
//
if (!`optionVar -exists "showStatusCopyPaste"`) {
optionVar -intValue "showStatusCopyPaste" 1;
}

string $toggleCopyPasteCmd = "\"copyPasteLayout\", " +
"\"copyPasteCollapse\", " +
"\"\", " +
"\"showStatusCopyPaste\")";

//
// Set up open/close bar
//

setUITemplate -pushTemplate TexWinBarTemplate;

iconTextButton -vis true
-parent $gUVTexEditToolBar
-annotation (uiRes("m_textureWindowCreateToolBar.kShowHideCopyPasteIconsAnnot"))
-i1 textureEditorOpenBar.png
-c ("textureWindowCreateToolBar_toggleIcons(-1," + $toggleCopyPasteCmd)
copyPasteCollapse;

setUITemplate -popTemplate;

//
// Set up icons
//

formLayout uvManipLayout;

global string $uvEntryField;
global float $manipAmt;
$manipAmt=1.0;

setUITemplate -pushTemplate TexWinFloatFieldTemplate;

floatField
-precision 3
-ed true
-width 48
-annotation (uiRes("m_textureWindowCreateToolBar.kEnterValueToManipUVAnnot"))
$uvEntryField;

setUITemplate -popTemplate;

setUITemplate -pushTemplate TexWinButtonTemplate;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -a $manipAmt"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipRotCCWAnnot"))
manipRotCCW;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -a ($manipAmt * -1)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipRotCWAnnot"))
manipRotCW;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -s ($manipAmt)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipScaleUpAnnot"))
manipScaleUp;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -su ($manipAmt * 1)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipScaleUpUAnnot"))
manipScaleUpU;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -sv ($manipAmt * 1)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipScaleUpVAnnot"))
manipScaleUpV;

setUITemplate -popTemplate;

setUITemplate -pushTemplate TexWinButtonTemplate;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -u ($manipAmt * -1) -v 0"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipMoveLeftAnnot"))
manipMoveLeft;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -u $manipAmt -v 0"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipMoveRightAnnot"))
manipMoveRight;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -u 0 -v $manipAmt"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipMoveUpAnnot"))
manipMoveUp;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -u 0 -v ($manipAmt * -1)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipMoveDownAnnot"))
manipMoveDown;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -s ($manipAmt * -1)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipScaleDownAnnot"))
manipScaleDown;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "UVmanipulation(10,$manipAmt)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipScaleDownUAnnot"))
manipScaleDownU;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -sv ($manipAmt * -1)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipScaleDownVAnnot"))
manipScaleDownV;

setUITemplate -popTemplate;

formLayout -edit

-attachForm uvEntryField "top" $vertGap
-attachForm uvEntryField "left" 0

-attachControl anipRotCCW "top" $vertGap
-attachControl anipRotCCW "left" $horizGap
-attachControl manipRotCW "top" $vertGap
-attachControl manipRotCW "left" $horizGap

-attachControl manipScaleUp "top" $vertGap
-attachControl manipScaleUp "left" $horizGap
-attachControl manipScaleUpU "top" $vertGap
-attachControl manipScaleUpU "left" $horizGap
-attachControl manipScaleUpV "top" $vertGap
-attachControl manipScaleUpV "left" $horizGap

-attachForm manipMoveLeft "top" $vertGap uvEntryField
-attachControl manipMoveLeft "left" 0
-attachControl manipMoveRight "top" $vertGap uvEntryField
-attachControl manipMoveRight "left" $horizGap manipMoveLeft
-attachControl manipMoveUp "top" $vertGap manipRotCCW
-attachControl manipMoveUp "left" $horizGap manipMoveRight
-attachControl manipMoveBottom "top" $vertGap manipScaleUp
-attachControl manipMoveBottom "left" $horizGap manipMoveUp

-attachControl manipScaleDown "left" $horizGap manipMoveBottom
-attachControl manipScaleDown "top" $vertGap manipScaleUp
-attachControl manipScaleDownU "left" $horizGap manipScaleDown
-attachControl manipScaleDownU "top" $vertGap manipScaleUpU
-attachControl manipScaleDownV "left" $horizGap manipScaleDownU
-attachControl manipScaleDownV "top" $vertGap manipScaleUpV
uvManipLayout;
Removed the switch (wasnt needed) and cleaned up the layout. But I STILL get the same error: TOO MANY ARGUMENTS!! :(

NaughtyNathan
08-09-2012, 09:42 PM
check your formLayout flags!!! the -attachForm flag should have THREE params, and -attachControl should have FOUR. you have at least one -attachForm with 4 params...

If you can't debug where the error lies, simply REMOVE ALL the offending code and put it back line by line... you don't need any of those formLayout edits to actually run the code successfully, only to make it look right. Take them all out and add then back one by one.

DeadlyNightshade
08-09-2012, 11:28 PM
Great! Thanks.
The editor now starts up and I have the buttons. Some of the commands will have to be tweaked but that's another issue.
The high priority issue now is fixing the floatField. As of now, entering a new value into it does not update the variable $manipAmt; - why?

//
// Set up icons
//

formLayout uvManipLayout;

global string $uvEntryField;
global float $manipAmt;
$manipAmt=1.0;

setUITemplate -pushTemplate TexWinFloatFieldTemplate;

floatField
-precision 3
-ed true
-width 48
-annotation (uiRes("m_textureWindowCreateToolBar.kEnterValueToManipUVAnnot"))
-value $manipAmt;
$uvEntryField;

setUITemplate -popTemplate;

setUITemplate -pushTemplate TexWinButtonTemplate;

I guess I need a -cc flag and a command that takes the value of the floatField (uvEntryField) and updates $manipAmt with it. But how do I get the value from a floatField?

EDIT: What would be the correct syntax on the changeCommand flag?
floatField
-precision 3
-ed true
-width 48
-changeCommand ('$manipAmt = "floatField -query -value $uvEntryField"')
-annotation (uiRes("m_textureWindowCreateToolBar.kEnterValueToManipUVAnnot"))
$uvEntryField;

NaughtyNathan
08-10-2012, 10:18 AM
MEL doesn't support ' quotes, only " (doubles) so:
-changeCommand "$manipAmt = `floatField -query -value $uvEntryField`"however, all code callbacks are executed in the global scope, so unless $uvEntryField is a global variable, this won't work. Doing any of this with global variables is not the best approach to be honest anyway. Fortunately, MEL UI controls have a trick whereby you can reference the control value directly by refering to it as #1:
-changeCommand "$manipAmt = #1"should work. if your control has more than one value, you can use #2, #3 and #4 to refer to it's other values.

DeadlyNightshade
08-10-2012, 10:34 PM
Thanks a lot Nathan, you've been very helpful. That #1 -thing really did the trick.

Now I just need to fix my commands. Code is below (I stripped away the -ac button stuff coz it's already working):
formLayout uvManipLayout;

global string $uvEntryField;
global float $manipAmt;
$manipAmt=1.0;


setUITemplate -pushTemplate TexWinFloatFieldTemplate;

floatField
-precision 3
-ed true
-width 48
-changeCommand "$manipAmt = #1" // reads new floatField input
-annotation (uiRes("m_textureWindowCreateToolBar.kEnterValueToManipUVAnnot"))
$uvEntryField;

setUITemplate -popTemplate;

setUITemplate -pushTemplate TexWinButtonTemplate;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -a $manipAmt"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipRotCCWAnnot"))
manipRotCCW;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -a ($manipAmt * -1)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipRotCWAnnot"))
manipRotCW;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -su ($manipAmt)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipScaleUAnnot"))
manipScaleU;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -su ($manipAmt) -sv ($manipAmt)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipScaleUVAnnot"))
manipScaleUV;

setUITemplate -popTemplate;

setUITemplate -pushTemplate TexWinButtonTemplate;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -u ($manipAmt * -1) -v 0"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipMoveLeftAnnot"))
manipMoveLeft;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -u $manipAmt -v 0"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipMoveRightAnnot"))
manipMoveRight;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -u 0 -v $manipAmt"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipMoveUpAnnot"))
manipMoveUp;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -u 0 -v ($manipAmt * -1)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipMoveDownAnnot"))
manipMoveDown;

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -sv ($manipAmt * 1)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipScaleVAnnot"))
manipScaleV;

setUITemplate -popTemplate;

formLayout -edit

// lots of -attachControls and -attachForms

uvManipLayout;
I've also rearranged the buttons somewhat, and removed 3 scale buttons (because you really don't need negative ones).

Now, the last(?) problem is the following:

The scale (manipScaleUV, manipScaleU, manipScaleV) and the rotate buttons (manipRotCW, manipRotCCW) work, but acts very weird. When the commands are run, Maya considers the pivot of my selected shell to be slightly outside the BOTTOM LEFT corner of my selection - so everything scales from/to or rotates around that area. It's like it doesn't "remember" that the pivot is actually in the center of the selection. This is a very annoying issue as it causes all my scale and rotate operations to skew/offset the shells.

I'm also going to add buttons to the left of the input field for quickly manipulating the value of the floatField. For example:
+/- 10.0, 1.0, 0.1, and 0.01. The idea here is to have positive increments on left click (normal command) and then use the popupMenu for negative increments (using the -postMenuCommand), and parent it to the positive button. This should - in theory at least - give me the ability to have two commands on one button, correct?

djx
08-11-2012, 10:17 AM
A quick look at polyEditUV in the manual will show you the pivotU and pivotV keywords. This could be a solution to your last(?) problem.

Rather than using the popup menu for your negative increments, I think I would have used ctrl-left click. Just a bit more user-friendly imo.

David

DeadlyNightshade
08-11-2012, 12:31 PM
Yea that is the correct flag to use.
However, I can't have it as a static value (0.5) but it has to be a variable. And that variable needs to have the same value as where the manipulator is. And when the manipulator is moved, that value has to update.

It seems like polyEditUV might not be the correct command here (seems too complex making it behave like the default UV scale/rotate floatField).

EDIT: If you take a look at your own textureWindowCreateToolBar.mel you will see that the default interface uses a 3-case switch with each of the following: moveSuperContext, RotateSuperContext and scaleSuperContext.

EDIT 2:
I found out how I can query the position:

texMoveContext -q -position texMoveContext
texRotateContext -q -position texRotateContext
texScaleContext -q -position texScaleContext

These commands returns two floats: for the U and V coords.
But how would I go on to insert these returned values into two different variables? ($manipUCoord and $manipVCoord). Would an array be a good idea here and if so, how do I insert two return values into it?

Also, this query needs to go into the button commands
iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "polyEditUV -pivotU (0.5) -pivotV (0.5) -a $manipAmt"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipRotCCWAnnot"))
manipRotCCW;

...and since there are now two commands needed (first the pivot coordinates query, then the actual manipulation execution (angle, scale, etc)) - would it be smarter to just make this into a global procedure or is it OK to place these on the same line?

Something like this I would imagine (PSUEDO CODE):
-command "Query manipulator, insert return values into two variables, then run polyEditUV -pivotU ($manipUCoord) -pivotV ($manipVCoord) -a $manipAmt"

djx
08-11-2012, 02:25 PM
You can build a button command that is several lines of mel. This can include if's and for's, but since you are writing it as a string (in quotes) you need to escape quotes withing the commands with \. Needless to say, this can get really messy, and hard to read, let alone debug. I think you would be better off writing a global proc as your button command.

Inside the button command proc you can use the getModifiers command (see manual) to check whether ctrl, shift or alt were pressed when the button was clicked.

David

DeadlyNightshade
08-11-2012, 02:58 PM
Alright thanks.
This is how it's setup right now.

I have the following global procedure:
global proc updateManipCoords()
{
string $cTool = "";
$cTool = currentCtx();
switch($cTool)
{
case "moveSuperContext":
$manipCoords = `texMoveContext -q -position texMoveContext`;
break;

case "RotateSuperContext":
$manipCoords = `texRotateContext -q -position texRotateContext`;
break;

case "scaleSuperContext":
$manipCoords = `texScaleContext -q -position texScaleContext`;
break;
}
}
...which grabs the coordinates of any manipulation tool: rotate, move, scale, and updates the array with them.
Then I just call on it on the button command:
iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "updateManipCoords(); polyEditUV -pivotU ($manipCoords[0]) -pivotV ($manipCoords[1]) -a ($manipAmt * -1)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipRotCCWAnnot"))
manipRotCCW;
EDIT:
Problem: The function call works, and so does the variables. I added some lines with "print" to my updateManipCoords() just to see that the procedure is activated when I click the buttons.
HOWEVER - for some reason the pivotU and pivotV flags is not set to the values $manipCoords[0] and $manipCoords[1] - which results in skewing/offsetting of the UV shells when clicking these buttons. It seems to be a syntax error since I got things working just 10 minutes ago.

EDIT2:
And on the side I'm working on buttons to modify the floatField value by a set increment. I'm having problems overwriting the old value of the floatField though:
global string $uvEntryField = "uvEntryField";

...lots of code

floatField
-precision 3
-ed true
-value $manipAmt
-width 48
-changeCommand "$manipAmt = #1" // reads new floatField input
-annotation (uiRes("m_textureWindowCreateToolBar.kEnterValueToManipUVAnnot"))
$uvEntryField;

...lots of code

iconTextButton
-image1 "manipScaleV.bmp"
-command "$manipAmt += 0.1; floatField -v $manipAmt $uvEntryField"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.testButtonAnnot"))
testButton;
First part works. Every time I click the button the $manipAmt is changed (and properly executed by other functions too). But the last part gives me the error: Object's name 'uvEntryField' is not unique. Why? $uvEntryField is the name of the floatField to be modified and $manipAmt is the new value.

NaughtyNathan
08-11-2012, 10:22 PM
always remember to use the -edit (-e) flag when editing an existing control, otherwise how does Maya know you're not trying simply to create a new control...?

DeadlyNightshade
08-11-2012, 10:28 PM
Oh I see.
Yea that makes sense. I wasn't even aware of such a flag though - it's not listed in the manual http://download.autodesk.com/global/docs/maya2012/en_us/Commands/floatField.html
...but I guess it's a global flag or something.

Thanks again Nathan.

EDIT: Any thoughts on why I can't set the pivot to my variables in the polyEditUV command?

DeadlyNightshade
08-12-2012, 11:43 PM
Okay so this is a long post! I've split it up into "problem 1" and "problem 2" to make it more readable.

Problem 1:
polyEditUV pivot -flags not using my variable.
This procedure gets the manipulation tool coordinates from the scale, move or rotate tool and stores them in an array:

global proc updateManipCoords()
{
string $cTool = "";
$cTool = currentCtx();
switch($cTool)
{
case "moveSuperContext":
$manipCoords = `texMoveContext -q -position texMoveContext`;
break;

case "RotateSuperContext":
$manipCoords = `texRotateContext -q -position texRotateContext`;
break;

case "scaleSuperContext":
$manipCoords = `texScaleContext -q -position texScaleContext`;
break;
}
}

That function is called on by my polyEditUV -buttons, like this:

iconTextButton
-image1 "updatePsdTextureEditor.png"
-command "updateManipCoords(); polyEditUV -pivotU ($manipCoords[0]) -pivotV ($manipCoords[1]) -a ($manipAmt * -1)"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipRotCCWAnnot"))
manipRotCCW;

Problem is though that the polyEditUV pivot flags does not seem to "read" the coords from the array - AT ALL. The pivot remains at origin (0.0) for
unknown reasons.

Problem 2:
This procedure calculates the distance between two UVs (this one along U):

global proc calcUdist()
{
global string $uvEntryField = "uvEntryField";
float $uvbox[] = `polyEvaluate -bc2`;
float $uDiff = `abs($uvbox[1] - $uvbox[0])`;
float $manipAmt = $uDiff;

floatField -e -v $manipAmt $uvEntryField;
}

It's called upon by this button:
iconTextButton
-image1 "manipCalcUDist.bmp"
-command "calcUdist();"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipUDistAnnot"))
manipUDist;
Problem is that even though the floatField appears to get the difference (of the UVs) as it's new value, I don't think that is the case.
Why? Because I have several other buttons for increasing the floatField value in steps of +10, +1, +0.1, etcetera - or to invert the value.
Example button:

iconTextButton
-image1 "manipVal10.bmp"
-command "$manipAmt += 10; floatField -e -v $manipAmt $uvEntryField;"
-annotation (getRunTimeCommandAnnotation ("m_textureWindowCreateToolBar.kmanipVal10Annot"))
manipVal10;

But when executing the above command, it does the math on the value that was there BEFORE calcUdist() made changes to the floatField.
I know this for sure because I have 6 different math buttons (inversion, reset, +10, +1, +0.1 and +0.01) and they all work just fine together.
But the calcUdist()? Nope!!! It does not.

So... I thought that ok, maybe it's coz it's not a global. So I set "global" in front of the $manipAmt float but get this error:
Initialization of global variable "$manipAmt" requires a constant value.
...even though I already defined $manipAmt as a global and assigned it the value 1.0 at the start of the script.

DeadlyNightshade
08-13-2012, 10:20 PM
Problem 2 solved.
It was due to a stupid problem (didnt declare the variable properly).
Problem 1 remains though and I got no clue how to fix it.

rgkovach123
08-14-2012, 03:14 PM
updateManipCoords needs to return the pivot so polyEditUV can use the values.

From your example $manipCoords doesn't ever make it out of your procedure.

DeadlyNightshade
08-14-2012, 06:53 PM
Ok that makes sense.
I wasn't familiar with what "return" is used for - I thought that as long as I redefine/rewrite this global variable, things will be fine.
Which is rather odd actually because I have another function for calculating the space between two UV coords. That procedure seems able to overwrite one variable.

Anyway, I changed the updateManipCoords() procedure
global proc float[] updateManipCoords()
{
string $cTool = "";
$cTool = currentCtx();
switch($cTool)
{
case "moveSuperContext":
$manipCoords = `texMoveContext -q -position texMoveContext`;
break;

case "RotateSuperContext":
$manipCoords = `texRotateContext -q -position texRotateContext`;
break;

case "scaleSuperContext":
$manipCoords = `texScaleContext -q -position texScaleContext`;
break;
}
return $manipCoords;
print "U is: ";
print $manipCoords[0];
print " - ";
print "V is: ";
print $manipCoords[1];
}
...but that doesn't seem to return the $manipCoords array properly.
I've tried writing it differently but I always get the errors "Procedure is missing a return statement" or "Procedure is missing a return value" and similiar...

EDIT: Just writing global proc float updateManipCoords() gave me an error saying that a float[] type was returned when a float (non-array) was expected

rgkovach123
08-14-2012, 09:19 PM
you should declare your return variable first outside the scope of the switch statement as an empty array.

Also, print statements after a return statement won't print, because the proc stops. you need to put the print statements before the return statement.

DeadlyNightshade
08-14-2012, 10:27 PM
Thanks Robert that really did the trick.
Now my script works exactly as I want and the coords are returned properly.

CGTalk Moderation
08-14-2012, 10:27 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.