simple exemple that create structure of var tree+graph+template+variables+execute

Post Reply
Message
Author
arnaud
Posts: 8
Joined: Thu Jun 01, 2017 1:19 pm

simple exemple that create structure of var tree+graph+template+variables+execute

#1 Post by arnaud » Thu Nov 30, 2017 8:42 am

Code: Select all

from kurtis import api
import kurtis
from kurtis import logError, logInfo
import kurtis

# get the root block of the varTree
root = api.getRootBlock()
# create a timeline parent it to the root
test = root.findChild("MyTimeline")
if test.isValid():
    try:
        # just delete resources if already existes
        test.delete()
        templates = root.findChild("Templates")
        mytemp = templates.findChild("MyTemplate")
        mytemp.delete()
    except:
        logError("Please delete the 'MyFirstTimeline' and MyFirstTemplate in the template block in the vartree")
myTimeline = api.addTimeline("MyTimeline", parent=root)
logInfo("Create Timeline")
# create a Sequence parent it to the timeline
mySequence = api.addSequence("MySequence", parent=myTimeline)
logInfo("Create sequence")
# create a Shot parent it to the Sequence
myShot = api.addShot("MyShot", parent=mySequence)
logInfo("Create shot")
# create a Departement parent it to the Shot
myDept = api.addBlock("MyDept", parent=myShot, department="Modeling")
logInfo("Create department")
# create graph for the departement
myGraph = myDept.createGraph()
logInfo("Create department graph")

# load some referenced presets
init = myGraph.referencePreset("Maya/Init/Init.kgn", location=api.INSTALL_DIR)
createCube = myGraph.referencePreset("Maya/Others/CreateCube.kgn", location=api.INSTALL_DIR, x=init.getPosition()[0]+300)
saveMayaFile = myGraph.referencePreset("Maya/Files/SaveMayaFile.kgn", location=api.INSTALL_DIR, x=createCube.getPosition()[0]+300)
assetsOut = myGraph.referencePreset("Kurtis/Asset/AssetsOut.kgn", location=api.INSTALL_DIR, x=saveMayaFile.getPosition()[0]+300)
execute = myGraph.referencePreset("Kurtis/Execution/Execute.kgn", location=api.INSTALL_DIR, x=assetsOut.getPosition()[0]+300)
# create connection between nodes
myGraph.connect(init,init.findPlug('next'),createCube,createCube.findPlug('previous'))
myGraph.connect(createCube,createCube.findPlug('next'),saveMayaFile,saveMayaFile.findPlug('previous'))
myGraph.connect(saveMayaFile,saveMayaFile.findPlug('asset'),assetsOut,assetsOut.findPlug('assets'))
myGraph.connect(assetsOut,assetsOut.findPlug('assets_out'),execute,execute.findPlug('input'))

# Create variable in variableTree that I going to use in this graph
myDept.addVar2('saveFileName','block_path[1:] + "/" + block_name + ".ma"')
# use this variable in saveMayaFile node on plug savePath
saveMayaFile.setPlugValue(saveMayaFile.findPlug('savePath'),"vars.saveFileName",is_expr=True)
# set the number of verion limit to 10
saveMayaFile.setPlugValue(saveMayaFile.findPlug('versioned_max'),10)

# create a group for the environment.
myTimeline.addVar2('environment.Modeling.graph_env','"maya-2016.bat"')
myTimeline.addVar2('environment.Modeling.graph_cmd','"mayapy.exe"')

# create a subgraph with CreateCube and saveMayafile inside
position = createCube.getPosition()
subgraph = myGraph.addSubgraph("MySubGraph",contents=[createCube, saveMayaFile],x=position[0],y=position[1])

# publish the graph add ignore_warnings=True because graph is not process so asset
#are not processed and will not be publish 
myDept.publishGraph(comment="Graph generated from api", ignore_warnings=True)

# Create a template from this graph
api.addTemplate(myDept, name="MyTemplate")

allShots=[myShot]

# create 3 copy of the shot
for e in range(3):
    allShots.append(myShot.duplicate(rank=len(mySequence.getChildren())))

# process all the graphs (uncomment to process graphs)
'''
for shot in allShots:
    block = shot.findChild("MyDept")
    graph = block.openGraph()
    graph.execute()
'''

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest