Custom Transfer

The extension CustomTransfer implements a custom transfer from a producing task group to a consuming task group, creating connections between custom tasks (no ANSYS installed products). It also demonstrates the creation of single-task task group versus a multi-task task group.

 

XML Extension Definition File

The XML extension definition file CustomTransfer.xml defines task groups named Producer, Consumer, and CompleteTransfer, all of which appear in the Workbench Toolbox.

 

This XML file performs the following actions:

  • References the IronPython script customtransfer.py.

  • Defines two tasks in the <tasks> block: Producer and Consumer.

  • Defines three task groups in the <taskgroups> block: Producer, Consumer, and CompleteTransfer. The task groups Producer and Consumer each contain a single task. The task group CompleteTransfer contains two tasks.

The file CustomTransfer.xml contains the following code:

<extension version="1" name="CustomTransfer">
    <guid shortid="CustomTransfer">69d0095b-e138-4841-a13a-de12238c83f3</guid>
    <script src="customtransfer.py" />
    <interface context="Project">
        <images>images</images>
    </interface>
      <workflow name="wf4" context="Project" version="1">
        <tasks>
            <task name="Producer" caption="Producer" icon="test_component" version="1">
                <callbacks>
                    <onupdate>producer_update</onupdate>
                </callbacks>
                <inputs>
                    <input/>
                </inputs>
                <outputs>
                    <output format="" type="MyData"/>
                </outputs>
            </task>
            <task name="Consumer" caption="consumer" icon="test_component" version="1">
                <callbacks>
                    <onupdate>consumer_update</onupdate>
                </callbacks>
                <inputs>
                    <input/>
                    <input format="" type="MyData"/>
                </inputs>
                <outputs/>
            </task>
        </tasks>
        <taskgroups>
            <taskgroup name="Producer" caption="Producer" icon="producer_system" 
category="ACT Custom Workflows" abbreviation="Producer" version="1">
                <includeTask name="Producer" caption="Producer"/>
            </taskgroup>
            <taskgroup name="Consumer" caption="Consumer" icon="consumer_system" 
category="ACT Custom Workflows" abbreviation="Consumer" version="1">
                <includeTask name="Consumer" caption="Consumer"/>
            </taskgroup>
            <taskgroup name="CompleteTransfer" caption="CompleteTransfer" icon="consumer_system" 
category="ACT Custom Workflows" abbreviation="CompleteTransfer" version="1">
                <includeTask name="Producer" caption="Producer"/>
                <includeTask name="Consumer" caption="Consumer"/>
            </taskgroup>
        </taskgroups>
      </workflow>
</extension>

IronPython Script

The IronPython script customtransfer.py contains the code that provides update instructions for the producing task group and for the consuming task to obtain the output data from the upstream producer.

def consumer_update(task):
    container = task.InternalObject
    #obtain input data
    upstreamData = container.GetInputDataByType(InputType="MyData")
    fileRef = None
    upstreamDataCount = upstreamData.Count
    if upstreamDataCount > 0:
        fileRef = upstreamData[0]  
        AssociateFileWithContainer(fileRef, container)
        ExtAPI.Log.WriteMessage("Recieved file "+fileRef.Location+" from producer.")
    #if no new data...nothing to process from upstream sources.
def producer_update(task):
    container = task.InternalObject
    extensionDir = ExtAPI.ExtensionManager.CurrentExtension.InstallDir
    filePath = System.IO.Path.Combine(extensionDir, "Sample_Materials.xml")
    fileRef = None
    isRegistered = IsFileRegistered(FilePath=filePath)
    if isRegistered == True:
        fileRef = GetRegisteredFile(filePath)
    else:
        fileRef = RegisterFile(FilePath=filePath)
        AssociateFileWithContainer(fileRef, container)
    outputRefs = container.GetOutputData()
    outputSet = outputRefs["MyData"]
    myData = outputSet[0]
    myData.TransferFile = fileRef

Release 18.2 - © ANSYS, Inc. All rights reserved.