Re: [Maya-Python] scriptJob for change in optionVar values

2019-10-30 Thread Justin Israel
On Thu, Oct 31, 2019, 7:27 AM kiteh  wrote:

> Hi Tim,
>
> Thanks for the info, nonetheless! Glad to know that the scriptJob command
> gets updated with new args in Maya 2019.
>
> I have this tool written in PyQt Gui (accessed by clicking on the shelf
> button icon), in which it has a checkbox within that allows/ tells user
> whether the "Auto" mode is enabled or not.
> Checked means enabled, unchecked means disabled.
>
> Because this checkbox can only be navigate only when the UI is open (it
> uses an optionVar, eg. `myToolMode`), and so I thought it may be easier if
> I either:
>
>- Create a right click menu where the sub-menu (aka menuItem) will
>have a checkbox functionality so that it associates with the state of the
>optionVar.
>- Or, change the shelf icon image, eg. bg color of the icon will be
>colored red to signify that the mode is enabled.
>
> As mentioned, the shelf + its icons are generated by mel code, initially I
> tried the first approach (menuItem with checkbox), unfortunately it fails,
> as it does not works in the manner I had wanted to.
> And so, I tried out the second method, changing of the shelf icon where
> part of the mel code goes as:
> global proc myToolButton(string $parent)
> {
> string  $parentLayout = `setParent -q`,
> $shelfButtons[] = `layout -q -childArray $parentLayout`,
> $autoMode = $shelfButtons[`size $shelfButtons` - 1];
>
> // Script Job creation
> scriptJob -parent $autoMode -event "RecentCommandChanged"
> ("myToolIconChange(\"" + $autoMode + "\")");
> }
>
>
> global proc myToolIconChange(string $shelfButton)
> {
> string  $image = "myToolIconDisabled.png",
> $autoMode = `optionVar -q "myToolMode"`;
> int $myMode = 0;
>
>
> if ($autoMode == 1){
> $image = ("myToolIconEnabled.png"); // this will have a red bg
> color
> $myMode = 1;
>
> }else{
> $image = ("myToolIconDisabled.png");
> $myMode = 0;
> }
> if(`shelfButton -q -exists $shelfButton`)
> // Update the button with the image we chose.
> catchQuiet(`shelfButton -edit -image $image $shelfButton`);
> }
>
>
> By default, the optionVar/ the tool mode is in disabled state in first
> maya session. Currently the issue I had is:
>
>- I enabled the mode via the popup menu (shelf icon with red bg color)
>- Launch the tool (the pyqt checkbox is checked, which is correct)
>- Disabled the mode within the pyqt tool but the shelf icon did not
>gets updated
>- Shelf icon only gets updated (to non-red bg) unless I perform other
>actions within Maya context itself eg. creating a new locator
>
> Could you just set a callback for your shelf buttons
popupMenu postMenuCommand to update the check state from the optionVar?
Then it would be accurate every time you show the menu.


> Apologize for the long list of details.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/d9d515e0-2c0e-479f-917f-ecb6cc67ff19%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0jVmam8SV_6wYOSfsNFMRoSFwrkqEHid-1soVA_MrMPA%40mail.gmail.com.


Re: [Maya-Python] scriptJob for change in optionVar values

2019-10-30 Thread kiteh
Hi Tim, 

Thanks for the info, nonetheless! Glad to know that the scriptJob command 
gets updated with new args in Maya 2019.

I have this tool written in PyQt Gui (accessed by clicking on the shelf 
button icon), in which it has a checkbox within that allows/ tells user 
whether the "Auto" mode is enabled or not.
Checked means enabled, unchecked means disabled.

Because this checkbox can only be navigate only when the UI is open (it 
uses an optionVar, eg. `myToolMode`), and so I thought it may be easier if 
I either:

   - Create a right click menu where the sub-menu (aka menuItem) will have 
   a checkbox functionality so that it associates with the state of the 
   optionVar.
   - Or, change the shelf icon image, eg. bg color of the icon will be 
   colored red to signify that the mode is enabled.

As mentioned, the shelf + its icons are generated by mel code, initially I 
tried the first approach (menuItem with checkbox), unfortunately it fails, 
as it does not works in the manner I had wanted to.
And so, I tried out the second method, changing of the shelf icon where 
part of the mel code goes as:
global proc myToolButton(string $parent)
{
string  $parentLayout = `setParent -q`,
$shelfButtons[] = `layout -q -childArray $parentLayout`,
$autoMode = $shelfButtons[`size $shelfButtons` - 1];

// Script Job creation
scriptJob -parent $autoMode -event "RecentCommandChanged" 
("myToolIconChange(\"" + $autoMode + "\")");
}


global proc myToolIconChange(string $shelfButton)
{
string  $image = "myToolIconDisabled.png",
$autoMode = `optionVar -q "myToolMode"`;
int $myMode = 0;


if ($autoMode == 1){
$image = ("myToolIconEnabled.png"); // this will have a red bg color
$myMode = 1;

}else{
$image = ("myToolIconDisabled.png");
$myMode = 0;
}
if(`shelfButton -q -exists $shelfButton`)
// Update the button with the image we chose.
catchQuiet(`shelfButton -edit -image $image $shelfButton`);
}


By default, the optionVar/ the tool mode is in disabled state in first maya 
session. Currently the issue I had is:

   - I enabled the mode via the popup menu (shelf icon with red bg color)
   - Launch the tool (the pyqt checkbox is checked, which is correct)
   - Disabled the mode within the pyqt tool but the shelf icon did not gets 
   updated
   - Shelf icon only gets updated (to non-red bg) unless I perform other 
   actions within Maya context itself eg. creating a new locator 


Apologize for the long list of details.

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/d9d515e0-2c0e-479f-917f-ecb6cc67ff19%40googlegroups.com.


Re: [Maya-Python] scriptJob for change in optionVar values

2019-10-29 Thread Tim Fowler
Ah, well that's unfortunate.  I'm not aware of another way off the top of
my head.  Is there something specific you're trying to do that you can
share?  Maybe there's an alternative approach...

-Tim

On Tue, Oct 29, 2019 at 3:41 PM kiteh  wrote:

> Okay, my bad, it seems that this command is only available in Maya 2019.
> Unfortunately I am using an earlier version, Maya 2018 though.
> any other alternatives?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/5f51cc9b-7847-4c8c-9e4a-3fedbf491ec8%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CALKD2WpaJu%3D2gGb%2B3e3uFSMpWrv_ijweW5W6vHq3nxDn-NJSNA%40mail.gmail.com.


Re: [Maya-Python] scriptJob for change in optionVar values

2019-10-29 Thread kiteh
Okay, my bad, it seems that this command is only available in Maya 2019. 
Unfortunately I am using an earlier version, Maya 2018 though.
any other alternatives?

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/5f51cc9b-7847-4c8c-9e4a-3fedbf491ec8%40googlegroups.com.


Re: [Maya-Python] scriptJob for change in optionVar values

2019-10-29 Thread kiteh
Hey Tim, thanks for getting back.

I am not seeing -optionVarChange within the docs of `scriptJob` command 
though (I'm looking at the 2018 documentation). 

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/a8d8e95d-e46e-4cd8-85f0-6f954fff1da2%40googlegroups.com.


Re: [Maya-Python] scriptJob for change in optionVar values

2019-10-29 Thread Tim Fowler
global proc MyOptionVarCallback()
{
int $val = `optionVar -q createPolyPrimitiveAsTool`;
print ("Create polys with tool: " + $val + "\n");
}

scriptJob -optionVarChange "createPolyPrimitiveAsTool"
"MyOptionVarCallback";


I think there's a flag for that, although the doc's might have it spelled
incorrectly for some reason.  This code will run whenever you change the
"Interactive Creation" option.

-Tim

On Tue, Oct 29, 2019 at 12:20 PM kiteh  wrote:

> Hi all, I am trying to write a custom scriptJob that will activates when
> it detects a change in an `optionVar` value.
>
> Initially, I was using `RecentCommandChanged` as the event name, which
> seemingly have work, but however, it calls everything I navigate to another
> (new) tool command.
> Is there a better event name/ create a personal event that I can adopt?
>
> P.S: The current code I am working on uses MEL and hence unable to use the
> ones within OpenMaya.
>
> Appreciate in advance for any replies.
>
> Cheers.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/3618aa5f-00d7-44c4-813d-62d49c9e29e7%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CALKD2WpRjEVPHmNeD9btt6P3mXKy_BKG975TOnqABg9D_0Fuog%40mail.gmail.com.