Join our discord community

Please or Register to create posts and topics.

plugin On publish

Hi,

I'm using Prism for a few month now. It's really great, thank you for it.

I'm starting to add some extra custom python script. I know the basics of python but I'm not a dev.

My first question is : I want to add an extra action to the publish action. To do that, I created a new custom plugin in 'C:\Prism\Plugins\Custom\myPluggin\Scripts' (using the prism plugin manager). I notice the 'origin' object by default in the function is a stateManager Class. My question is, how to get information like the taskname, the objects list etc displayed on the stateManager UI ? I try to look into the C:\Prism\Scripts\ProjectScripts/StateManager.py but I'm quite lost.

My second question is : how to get the main pCore instance, created when opening maya, in an another custom personal module ?

Thank you

Jax

 

Hey Jax,

regarding your first question:

You can use the "onPublish" or "postPublish" functions or the "preExport", "postExport" functions in your custom plugin as you probably figured out already.

The Statemanager itself has no taskname, only a comment. If you want to access the taskname of a state you need to access the state first like this:

origin.states[0]

which is equivalent to:

self.core.sm.states[0]

states is a list of all states, which exists currently in the statemanager.

When you have the state, you need to know the name of the widget you want to access. In this case that would be the "l_taskName" for an export state:

origin.states[0].ui.l_taskName.text()

You can check the .ui files to get the name of the widgets for the state settings like this:

C:\Prism\Scripts\ProjectScripts\StateManagerNodes\StateUserInterfaces\default_Export.ui

You can open it in the QtDesigner or in a texteditor.

For the objects in the object list, you can read the object names from the listwidget, but you can also use the "nodes" property of the export state instance to get a list of all connected objects.

Have a look at the "getStateProps" function of each state class to see how Prism accesses the state settings:

https://github.com/RichardFrangenberg/Prism/blob/c0bd8399bb40b579d108cc0b6f2b89b33baca1b8/Prism/Scripts/ProjectScripts/StateManagerNodes/default_Export.py#L850

 

To your second question:

If you check the code of the Prism shelf tools you'll see that "pcore" is a global variable, which stores the Prism Core instance in Maya. So from the Maya script editor you can execute this (if you have an export state in the State Manager):

print pcore.sm.states[0].ui.l_taskName.text()

 

Hope that helps.

Richard

Hi Richard !

Thanks you for the answer ! It helps for my first question. Now I'm wondering if I change in a pre export command the 'nodes' attribut value of my state Class, will it make a difference during the export ?

I mean, imagine : In the UI object list, I have my 'model_grp' containing all my mesh. But what I really want to export is all the shading Engine connected to the mesh inside my model_grp.  The current value of the 'nodes' attribut should be 'model_grp'. So what is going to happen, if I change that value by my list of shaders during the onPublish or prePublish action ? Will it update the ui ? Will it work ? Is there a workaround ?

For my second question, I'm going to give an exemple, it will be more specific.

I have a module called mayaMenu.py. It create a menu in maya. Recently, I wanted to add the 'pcore.reloadPlugins()' function to this menu. My problem is :

I can't just call pcore.reloadPlugins() in the function called by my menu. It's obviously not working. It's saying I need to define pcore.

So what I could do, is import PrismCore and then create a pcore instance like so 'pcore = PrismCore.PrismCore(app="Maya")'. But it seems quite messy, it's opening a new project browser and I really feel like, it's not the way I should get a pcore instance. So my question is, from my mayaMenu.py module, what is the best way to get the pcore instance ? if there is a way.

 

Thanks,

Jax

 

Each export state creates a set in the Maya Outliner, which is named like the export state taskname. To add objects to the export state, just put your objects in that set. You can also use the "addObjects" method of the export state instance to do that. The "nodes" property gets recreated regularly from the content of the set. So if you can put your shading nodes in that set they will show up in the list in the export state settings.

It seems like there is no good way to access the existing PrismCore instance from other modules in Maya. What you can do is to add "global pcore" in the prismInit function in the PrismInit.py. Then you can use this in your mayamenu.py:

import PrismInit
print PrismInit.pcore.projectPath

 

Thanks !

I going to see what I'm going to do but this definitely helps.