Author Topic: Create a connection  (Read 208 times)

Hi, how Do I create a connection between two nodes?? via python of course

I have this code working to create the nodes :

Code: [Select]
from PySide2 import QtGui
from sd.api.sduimgr import SDUIMgr
import sd

class CompNodeCreator(object):
    def __init__(self):
        # Get app and UI manager.
        ctx = sd.getContext()
        app = ctx.getSDApplication()
        self.ui_manager = app.getQtForPythonUIMgr()
       
 
   
    def add_node(self, name, pos):
     
        # Get the comp graph.
        sd_graph = self.ui_manager.getCurrentGraph()
       
        # Create a node.
        node_def_id = 'sbs::compositing::{definition}'.format(definition=name)
        sd_node = sd_graph.newNode(node_def_id)
        sd_node.setPosition( sd.api.sdbasetypes.float2(pos[0],pos[1]))
       
        return sd_node

# Run

pos = [200,0]
pos2 = [400,0]
name = 'blend'
node_creator = CompNodeCreator()
node = node_creator.add_node(name,pos)
node2 = node_creator.add_node(name,pos2)

Ok get it!, it was a problem of naming the input output correctly  ;D ::)

Code: [Select]
import sd
from PySide2 import QtGui
from sd.api.sduimgr import SDUIMgr
from sd.api.sdproperty import SDPropertyCategory
from sd.api.sdapplication import SDApplicationPath

class CompNodeCreator(object):
    def __init__(self):
        # Get app and UI manager.
        ctx = sd.getContext()
        app = ctx.getSDApplication()
        self.ui_manager = app.getQtForPythonUIMgr()
       
 
   
    def add_node(self, name, pos):
     
        # Get the comp graph.
        sd_graph = self.ui_manager.getCurrentGraph()
       
        # Create a node.
        node_def_id = 'sbs::compositing::{definition}'.format(definition=name)
        sd_node = sd_graph.newNode(node_def_id)
        sd_node.setPosition( sd.api.sdbasetypes.float2(pos[0],pos[1]))
       
        return sd_node

# Run

pos = [200,0]
pos2 = [400,0]
name = 'blend'
node_creator = CompNodeCreator()
nodeA = node_creator.add_node(name,pos)
nodeB = node_creator.add_node(name,pos2)

definition = nodeA.getDefinition()
nodeId = nodeA.getIdentifier()
#get Output names
nodePropsA = nodeA.getProperties(SDPropertyCategory.Output)
for i in range(len(nodePropsA)):
print(nodePropsA[i].getId())
print(nodePropsA[i].getType())
#get input names
nodePropsB = nodeB.getProperties(SDPropertyCategory.Input)
for i in range(len(nodePropsB)):
print(nodePropsB[i].getId())
print(nodePropsB[i].getType())

#Make Connection
nodeA.newPropertyConnectionFromId('unique_filter_output', nodeB ,'source')