In this tutorial, you will create a Maya node more complex than in the topic "My first Maya node". You will go over the entire development of the node "SaveMayaFile".
(We advise you to do first the tutorial "My first Maya node").
- Create a department block in the vartree. A graph is automatically created.
- Open the graph (ctrl + o)
- Go in the graph viewer, press the tab key then type "Init", select the Maya one
- Next, import the referenced node "CreateLocator".
Connect the output "next" of the "Init" node to the input "previous" of the "CreateLocator" node.
- Import the node "MayaNodeTemplate" to integrate the save scene Maya command.
Connect the output "next" of "CreateLocator" node to the input "previous" of "MayaNodeTemplate" node.
- Change the name of node "MayaNodeTemplate" to "SaveMayaFile"(double-click on the node).
It will save the creation of the created locator of the previous node.
To save a scene in Maya, we need to use the command "file()" that requires the saving path of the scene.
- Create a new plug.
- Rename it "savePath".
Display this plug in the node interface to allow the user to set the saving path of the scene.
- Create widget type "File Browser".
- Connect it to the plug "savePath".
- Change the setting "File mode" into "File for Writing". Thus, the opened browser from the node interface will be set for writing a file.
Now add the command to the node script.
- See the documentation of the "file()" function in the Python Maya API.
- Use a first time this command to set the saving path via the argument "rename". Use the "savePath" plug value for this parameter.
- Use the command a second time to save the scene with the parameter "save".
- Next, specify the saving path of the scene in the "savePath" node parameter. This file can be saved to any folder.
After a first execution, the scene with a locator is saved to the defined path.
However, it can be saved to any folder and thus to the public part of a project. It seems more interesting now to use the system offered by Kurtis, namely that of the working copy and the assets.
We will then change the node "SaveMayaFile", so we can create an asset from the file it saves.
- Go to the tab "Plug UI". Right-click on the widget "File Browser".
- Choose "Edit...". Change the value of the "Location" parameter to "Relative to Asset Directory". The open browser interface of the node will be routed directly to the file of public project assets. Also, it will be automatically converted to a relative path.
In Kurtis, an asset creation is defined by 4 main parameters :
- A name
- A file path
- A publication method
- The number of versions to keep
An asset is defined in the Kurtis Database by a unique ID.
We already have the file path to create this asset. Next, create the other three parameters :
- Create a first input plug. Rename it "assetName".
- Create a second input plug. Rename it "versioned_mode".
Change its type to "list". Set its default value to "".
- Create a last input plug. Rename it "versioned_max".
Change its type to "integer".
Now, integrate these plugs in the node interface.
- Add a widget of type "Separator" to visually separate widgets reserved for the management of the asset.
- Add a second widget type "Line Edit". Connect it to the plug "assetName".
- Create a third widget of type "List". Connect it to the plug "versioned_mode".
Add these elements in its list.
- Versioned / Unversioned / Immediate
- Change the "Output mode" setting in "Indices".
- Create a last widget of type "Slider". Connect it to the plug "versioned_max".
Next, create an asset in the node script.
Use the Kurtis "Asset()" class.
- Line 14: provide the file path as the first parameter.
- Line 15: provide the number of asset version to keep.
- Line 16: provide the publication mode.
- Line 17: set the asset name.
- Lines 19 and 20: create the file folder if it does not exist.
- line 22: Use the function "getResolvedPath()" to get the absolute path of the asset depends to its publication mode to properly operate the Maya "file()" command.
- Click on "OK" or "Apply".
- Next, open the node properties window by double clicking on the "SaveMayaFile" and click on the "Restore Defaults" button to reset all parameters.
- Click on the "..." icon on the "savePath" parameter line, to open the browser interface directly to the directory of assets project and set the new path.
After the execution of the graph, the file is saved first in your working copy, securing the job of the user.
Currently, the asset cannot be published into the public project. You must retrieve the script data relative to the asset in order to transmit it to a node "Assets Out" .
- Add a new output plug.
- Rename it "assetOut". Change its type to "asset".
- Uncheck the "Connectable" and check the "Output" parameter.
Now, assign the asset to this plug in the script.
- Add a node "Assets Out" to the graph. This node enables the publication of the asset in the public part of the project.
- Connect the output "assetOut" of the "SaveMayaFile" node to the input "New assets" of the "Assets Out" node.
- Set the parameters of the asset in the node "SaveMayaFile".
- Finally, execute the graph by right-clicking on the "Assets Out" node.
To finish, we need to check the most important input of the node.
- Import from "Kurtis" the "tools" library.
- Then use the function "checkEmptyValue()" for the "savePath" plug.
Then write a docstring, a main comment, fill in the different properties, set the color and the icon of the node.