Python – Adding parameter to SCOP

Here’s a Python version of the CustomOperator.AddParameter example in the SDK docs, which shows how to add parameters to a scripted operator (SCOP).

from win32com.client import constants
from win32com.client import constants

null1 = Application.GetPrim( "Null" )
f = XSIFactory

s = """def MySOP_Update( ctx, out ):
   xsi = Application
   xsi.logmessage( 'update' )"""

sop = f.CreateScriptedOp( "MySOP", s, "Python" )

sop.AddOutputPort( null1.posx )

param1 = sop.AddParameter( f.CreateParamDef2("text", constants.siString, "hello") )
param2 = sop.AddParameter( f.CreateParamDef2("bool", constants.siBool, True) )
param3 = sop.AddParameter( f.CreateParamDef2("int", constants.siInt4, 10, 0, 100) )
param4 = sop.AddParameter( f.CreateParamDef2("dbl", constants.siDouble, 0.5, 0.0, 1.0) )


Application.InspectObj( sop )

3 thoughts on “Python – Adding parameter to SCOP

  1. This code gave errors on the GetPrim. It expects capitalisation, “Null”, not “null”.

    Also, is there a reason why you’re manually dispatching XSI.Factory when you can use the globally-available “XSIFactory” object? I’ve always used it directly.

    • Thanks for the feedback.
      The code works on Windows, but you’re right it should be “Null”. I assume you’re on Linux, so that’s why the capitalization matters.

      The post is three-years old, so I don’t really remember much, but it looks like a bit of cut and paste from different places…that would be where the old-style dispatch for XSIFactory came from, and probably the lower-case null.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s