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:

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"

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 ?

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:

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.

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.

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.

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.

Follow Us On:

The CGSociety

The CGSociety is the most respected and accessible global organization for creative digital artists. The CGS supports artists at every level by offering a range of services to connect, inform, educate and promote digital artists worldwide. More about us on TheArtSociety.com