CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 04-25-2013, 04:09 PM   #1
manuaarts
New Member
Allasia Emmanuel
3d-matchmovers
Marseille, France
 
Join Date: Nov 2005
Posts: 11
Maya : Unable to Activate Viewport 2.0 by script.

Hi everybody

I'm trying to activate Viewport 2.0 by script.
( I'm using Maya 2013 x64 on Windows )

I tryed this command :
Code:
ActivateViewport20;


Nothing happens. No error, but no Viewport 2.0 !
Of course,when i'm using the mouse : no problem.

Hope someone can help me
 
Old 04-25-2013, 06:14 PM   #2
Keilun
Expert
Keilun
Canada
 
Join Date: Aug 2005
Posts: 729
ActivateViewport20 is reliant on a modelPanel having focus. If you do this through the UI with Echo All Commands, you get the following output (formatted horribly):

Code:
ActivateViewport20; { string $currentPanel = `getPanel -withFocus`; string $panelType = `getPanel -to $currentPanel`; if ($panelType == "modelPanel") { setRendererInModelPanel "ogsRenderer" $currentPanel; } else if ($panelType == "scriptedPanel") { string $cmd = "setRendererInModelPanel \"ogsRenderer\" "; scriptedPanelRunTimeCmd( $cmd, $currentPanel ); }}; updateModelPanelBar MayaWindow|formLayout1|viewPanes|modelPanel4|model Panel4|modelPanel4;


If you read that code, you'll see that it uses getPanel -withFocus to determine the active viewport panel. Obviously if you're clicking on the UI, you're guaranteed to have the correct panel with focus. If you run it through a script however you are not.

As such, what you need to do by script is decompose that code so that it runs using a given modelPanel and you will need to come up with a way to determine the panel you want to modify, whether that is passed in from another script or hardcoded by name, or you set all modelPanels to VP2.0.

By default, there are 4 model panels for each of the 4 views (front, side, top, persp). I don't recall how they correspond to the particular modelPanel numbers, but you are guaranteed on startup to have 4 modelPanels named:

modelPanel1
modelPanel2
modelPanel3
modelPanel4

When you startup with just a single perspective view, that's usually modelPanel4 unless the user has configured things differently in the scene, etc.

Once you know what modelPanel you're looking for just run the subset of the above code:

Code:
global proc myEnableVP20( string $currentPanel ) { if ($panelType == "modelPanel") { setRendererInModelPanel "ogsRenderer" $currentPanel; } else if ($panelType == "scriptedPanel") { string $cmd = "setRendererInModelPanel \"ogsRenderer\" "; scriptedPanelRunTimeCmd( $cmd, $currentPanel ); } } // Quick test with modelPanel4 myEnableVP20( "modelPanel4" );
 
Old 04-25-2013, 08:37 PM   #3
manuaarts
New Member
Allasia Emmanuel
3d-matchmovers
Marseille, France
 
Join Date: Nov 2005
Posts: 11
Keilun, again : Thank you very much

That's great you take time to help me.

I achieve to do as you suggest me (pymel) for all model panel :
Code:
from pymel.core import * for elem in getPanel(typ="modelPanel") : mel.eval( 'setRendererInModelPanel "ogsRenderer" '+ elem.name() )

And it's working fine.

Now I have a new problem. The first time I run the script on a new scene, I get an error here :
Code:
# MelError: Error during execution of MEL script: file: C:/Program Files/Autodesk/Maya2013/scripts/others/createObjectTypeFilters.mel line 146: Object Type Filter name array size does not match value array size # Script: # objectTypeFilterOffCallback 0 #


But after this error, if I run the script again, I have not any error.
The error is when I set in HardwareRenderingGlobals / Batch Render Options / Object Type Filters some values.
Uncheck Nurbs Curve is : "objectTypeFilterOffCallback 0"

To reproduce the problem first do new scene then execute this :
Code:
setRendererInModelPanel "ogsRenderer" modelPanel1; setRendererInModelPanel "ogsRenderer" modelPanel2; setRendererInModelPanel "ogsRenderer" modelPanel3; setRendererInModelPanel "ogsRenderer" modelPanel4; objectTypeFilterOffCallback 0;

At this time you get the error. Again and again, each time you run the previous code.
But if you show in the ui the hardwareRenderingGlobals options windows, then the previous code works fine. It works also if you close the windows !

I guess, perhaps, that is because I need to update something after setting hardware renderer as the renderer.

I see a workaround : Force to show the render option windows by script. Is it possible ?
 
Old 04-25-2013, 08:48 PM   #4
Keilun
Expert
Keilun
Canada
 
Join Date: Aug 2005
Posts: 729
Hi again,

So this is one of those areas where you need to be careful when you just copy paste what's returned via the EchoAllCommands in the ScriptEditor. For methods like:

objectTypeFilterOffCallback

These routines are callbacks tied to the actual UI that runs them. The only technically safe output to copy are ones that refer to actual Maya commands rather than procedures. The way to debug this is to open up the script that it refers to:

scripts/others/createObjectTypeFilters.mel

and have a look at what it really does. You'll see that it does this:

Code:
// Description: // Callback for changing object type filter value set on global proc objectTypeFilterOnCallback(int $id) { setObjTypeFilterValueArrayItem($id, 1); updateObjTypeFilterValueToCheckBox(); } // Description: // Callback for changing object type filter value set off global proc objectTypeFilterOffCallback(int $id) { setObjTypeFilterValueArrayItem($id, 0); updateObjTypeFilterValueToCheckBox(); }

The key thing to note here is that the callback consists of two parts:

1. It sets the filter value.
2. It tries to update the checkbox in the UI (this is where your error comes from).

So really you just want to invoke:

Code:
int $state = 0; // Set to 0/1 depending on the value you care about setObjTypeFilterValueArrayItem( $id, $state );

Make sure the createObjectFiltersType.mel has already been sourced prior to invoking those procedures so that Maya can find them. Until it has been sourced, Maya will only automatically find a script in its path if the procedure's name matches the name of the script.
 
Old 04-25-2013, 08:54 PM   #5
Keilun
Expert
Keilun
Canada
 
Join Date: Aug 2005
Posts: 729
Actually I was wrong. The error is indeed coming from the first part. Which suggests that the filter arrays need to be initialized first. Let me have a look at how it initializes the arrays and see if there's something you can run before you run the code.

[Edit]: Ok so the code should work by invoking the following:

Code:
createObjectTypeFilters(0); // Initialize the filter arrays. int $state = 0; // Set to 0/1 depending on the value you care about setObjTypeFilterValueArrayItem( $id, $state );


The createObjectTypeFilters(0) builds the arrays using a preset array in the same script. The UI uses the preset at index 0 to generate the initial list. So you can do the same. From there you should be able to go off and set the values.

Let me know if that works.

Last edited by Keilun : 04-25-2013 at 09:06 PM.
 
Old 04-25-2013, 10:08 PM   #6
manuaarts
New Member
Allasia Emmanuel
3d-matchmovers
Marseille, France
 
Join Date: Nov 2005
Posts: 11
Yes !

You teach me a lot today Keilun. Thank you again.

As you suggest, I search in createObjectTypeFilters.mel
and I found that "setObjTypeFilterValueArrayItem" is a proc that call an other one : resetObjectTypeFilterArrays

In fact this is some convenient ways to update some values in a list But now I know where to search. So I wrote this :

Code:
values = getAttr("hardwareRenderingGlobals.objectTypeFilterValueArra y") # get the array of values values[0] = 0 # ID 0 is set to OFF for i in range(1,4) : # ID 1-3 are set to ON values[i] = 1 for i in range( 4,15 ) : # ID 4-14 are set to OFF values[i] = 0 setAttr( "hardwareRenderingGlobals.objectTypeFilterValueArra y" , values ) # Finaly put the modified array.


And that works perfectly. Thanks again for your help.
 
Old 04-26-2013, 02:38 PM   #7
Keilun
Expert
Keilun
Canada
 
Join Date: Aug 2005
Posts: 729
Great! Happy to help.
 
Old 04-26-2013, 02:38 PM   #8
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:22 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.