Jump to content

Creating workflows from another python workflow


Recommended Posts

This example is the same as 

but this time, we will create the workflow during the execution of another workflow with a python node.

Please Note you will need Wf Version 10.4.1 or later to execute this code

 

The behaviour will be very silimar to the previous example, but in this case, 3 properties are added to the node to parametrize them;

  • wfName:  to store the name to use when creating the new workflows
  • inputFile: to set the input file path
  • ftpDst: to set the final ftp destination

 

the node will also check that the inputFile exists before allowing you to execute the workflow

 

So, with those changes, the python node would look like this:

import Mistika
from Mistika.classes import CbaseItem
from Mistika.classes import Cconnector
from Mistika.QtCore import QPointF



def init(self):
    self.addProperty("wfName","My Test")
    self.addProperty("inputFile","G:/MATERIAL/formatos/EXR/CU_BIC_FX008_BICHA_V3_0035.exr")
    self.addProperty("ftpDst","ftp://ftp.sgo.es/")
    return True
    
def isReady(self):
    if len(self.inputFile)==0:                    #no empty file supported
        return self.critical("myTest:isReady:len","input file can not be empty")
    return True
    
def process(self):
    #create the example workflow
    wf=Mistika.workflows.addWorkflow(self.wfName)                                            # creates a workflow 
    file=wf.importFile(self.inputFile,True)                                                  #automatically create a node from a file (the node created depends on the file type (It is similar to droping a file into the workflow editor. The second parameter says if the file comes from a sequence
    print file
    file.pos=QPointF(0,0)
    prores=wf.addNode("ProRes",CbaseItem.NODETYPE_TASK)                                      # add a prores file (From the Tasks group. this helps to diferenciate nodes that appear in more than one group (such us FTP)
    print prores
    prores.pos=QPointF(300,0)                                                                # reposition the prores node (just for clarity)
    ftp=wf.addNode("FTP",CbaseItem.NODETYPE_OUTPUT)                                          # add an ftp output node
    print ftp
    ftp.pos=QPointF(600,0)                                                                   # reposition the prores node (just for clarity)

    file.getFirstConnectorByName("VideoOut").link(prores.getFirstConnectorByName("VideoIn")) # connect the nodes
    prores.getFirstConnectorByName("VideoOut").link(ftp.getFirstConnectorByName("File"))     # connect the nodes

    #populate node properties
    file.gamma="Linear"                       # define source color space
    file.gamut="ACES (AP1)"
    prores.colorSpace="Rec2020"               # define destination Color Space
    prores.resolution="HD 1080 (1920x1080)"   # define destination resolution
    prores.displayFilter="watermark"          # set a display filter called watermark
    ftp.url=self.ftpDst                       # set the destination ftp address
    wf.giveBackAffinity()                     # this function will be needed in versions >= 10.4.0 to give the management of the created workflow back to the system
    return True

 

To create the node with the code above you can paste the node in the script editor, and using Right Mouse Button->Save In ibrary

and call it "myExample". that will create a myExample.py in the SGOAppData/shared/workflowsLibrary directory and a myexample.xsd in the SGOAppData/shared/config/schemas directory.

 

the myexample.xsd needs to be edited in order to add the properties defined in the python script.

here you have an example of a myexample.xsd file with the properties added

<xsd:schema xmlns:sgo="http://www.sgo.es/2017/sgo.xsd" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element sgo:categoryType="categoryCollapsible" name="myExample" sgo:visibility="0" sgo:sortOrder="0">
    <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="objectName" type="xsd:string" sgo:visibility="0" sgo:sortOrder="0"/>
          <xsd:element name="color" type="color" sgo:visibility="0" sgo:sortOrder="1"/>
          <xsd:element name="wfName" type="xsd:string" sgo:visibility="0" sgo:sortOrder="10"/>
          <xsd:element name="inputFile" type="universalPath" sgo:properties="readOnly|urlVisibleButtonBrowser|pathNameFilters('All Files (*.*)')|fileDialogWindowTitle('Select a File')" sgo:visibility="0" sgo:sortOrder="11"/>
          <xsd:element name="ftpDst" type="xsd:string" sgo:visibility="0" sgo:sortOrder="12"/>
          <xsd:element name="code" type="textEditor" sgo:visibility="0" sgo:sortOrder="51"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>
</xsd:schema>

As soon as you write this xsd file in the schemas folder you will see the new properties appearing in the properties editor, like this:

image.png.fc34ddb8e3865736b00490bfda6b9186.png

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.