It’s possible to create a python script that is executed after an asset has been imported from Warehouse Browser. This makes it easy to do additional setup of a scene, change attributes or add + connect nodes that are needed or just simply display a dialog box with some text etc. This makes the import very versitile and it could even make the Warehouse Browser a script source and run tool.
In SPMP 0.4 a “Post Import Python Script” option has been added to the Warehouse Create – so only use the guide below if you want to do it manually.
Create a post import script
- Create an asset from the Warehouse Create
- Go to the newly created asset in the warehouse directory
- Create a .py file with exactly the same name as the asset (eg. The asset is named “CoolShader.mb”, then create a file called “CoolShader.py”)
- Write a python script in the .py file
- Import the asset from the Warehouse Browser
Example 01 – Simple Stuff
# CoolShader.py
print '-------------------------- Running Import Script --------------------------'
# Print the nodes of newly imported asset
print cmds.ls(selection=True)
# Prompt a confirm dialog via the SundayDialogPy
SundayDialogPy.SundayDialogConfirm('Warning', 'This shader is so very cool', 'OK')
Example 02 – Render Settings
# Load Mental ray (will throw an error if exists, use e.g. try-except to get around that)
cmds.loadPlugin('Mayatomr', quiet=True)
# Autoload Mental ray
cmds.pluginInfo('Mayatomr', edit=True, autoload=True)
# change render drop down
cmds.setAttr('defaultRenderGlobals.ren', 'mentalRay', type='string')
# example on render settings change
#Change samples
cmds.setAttr('miDefaultOptions.maxSamples', 2);
# Set filter to Mitchell
cmds.setAttr('miDefaultOptions.filter', 3);
#Enable final gather
cmds.setAttr('miDefaultOptions.finalGather', 1)
Example 03 – Render Settings That Uses Imported Asset
#Select imported asset
selObj = cmds.ls(selection=True)
#Look for the Mental Ray Image Based Light Sphere and connect it to mentalrayGlobals
for curObj in selObj:
if ((curObj.split(':')[len(curObj.split(':'))-1] == 'mentalrayIbl') or (curObj.split('|')[len(curObj.split('|'))-1] == 'mentalrayIbl')):
ibl = cmds.listRelatives(curObj, fullPath=True)[0]
try:
cmds.connectAttr(ibl + '.message', 'mentalrayGlobals.imageBasedLighting', force=True)
cmds.setAttr('miDefaultOptions.finalGather', 1)
except:
SundayDialogPy.SundayDialogConfirm('Script Error
Warehouse Asset Example Scene
Go to the Warehouse Resources Page to download Warehouse compliant scenes that has post script python files.
error using your examples, i’m sure i just need to import a module but now i need to go find which one
example 01:
# Error: name ‘SundayDialogPy’ is not defined
# Traceback (most recent call last):
# File “”, line 1, in
# File “/Users/cea/Dropbox/PipelinePublic/SundayMaya/SundayPython/SundayWarehousePy.py”, line 536, in SundayWarehouseBrowserImport
# File “P:/CGI/3D_Assets/sunday_asset_library/XYZ_MR_shaderLibrary/Metal/MTL_matCaps/MTL_matCaps.py”, line 8, in
# SundayDialogPy.SundayDialogConfirm(‘Warning’, ‘This shader is so very cool’, ‘OK’)
# NameError: name ‘SundayDialogPy’ is not defined #
little snooping around and i found i needed the line
import SundayDialogPy
pretty obvious i guess but it should probably be in your example shouldn’t it?
Hi Matt
I think you are right. I will check it out. I have re-written the core of the pipeline tool so it’s it not working in that way anymore. I will check it out and update the post. Thanks for the heads up!!
Regarding Example2:
# Load Mental ray (will throw an error if exists, use e.g. try-except to get around that) cmds.loadPlugin(‘Mayatomr’, quiet=True)
As I have no glue what I have to do to use “try-except” and as I am no programmer I used a simple if-then statement. Maybe this helps someone:
# Load Mental ray
if cmds.pluginInfo (“Mayatomr”, query=True, loaded=True) != 1 :
cmds.loadPlugin(‘Mayatomr’, quiet=True)
else :
print “Mental Ray is loaded”
thx,
mickna