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) ) sop.Connect() Application.InspectObj( sop )
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.
Hi, yeah, I was on Linux when I tried the code. Funny how it works in Windows.