How to add item to StringVectorParameter in python

19 views
Skip to first unread message

Dawei Sun

unread,
Dec 10, 2014, 2:59:15 PM12/10/14
to cort...@googlegroups.com
Hello, 

We are developing tools using cortex, we created a few Ops which has StringVectorParamenter, I know we can add an item using the "Add Item" button in the UI, but we need add items in python or C++, how do we add items using script to StringVectorParameter?


thanks


Andrew Kaufman

unread,
Dec 10, 2014, 3:22:57 PM12/10/14
to cort...@googlegroups.com
You need to set the value of the entire parameter at once:

value = p.getValue()
value.append( "new string" )
# setValue isn't strictly necessary in this case, because value above is actually a pointer to the data still being held by the parameter, so you've already edited it in place.
p.setValue(
value )

--
--
You received this message because you are subscribed to the "cortexdev" group.
To post to this group, send email to cort...@googlegroups.com
To unsubscribe from this group, send email to cortexdev-...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cortexdev?hl=en
---
You received this message because you are subscribed to the Google Groups "cortexdev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cortexdev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dawei Sun

unread,
Dec 10, 2014, 3:39:56 PM12/10/14
to cort...@googlegroups.com, and...@image-engine.com
I tried this, 

            fnPH = IECoreMaya.FnParameterisedHolder(self.node[0])
            curves = cmds.getAttr("%s.parm_curve"%self.node[0])
            
            with fnPH.parameterModificationContext():
                curve_parm = fnPH.getParameterised()[0].parameters()["curve"]
                print repr(curve_parm.getValue())
                v = curve_parm.getValue()
                v.append(shape_c[0])
                curve_parm.setValue(v)

when I use with fnPH.parameterModificationContext(): maya crashes immediately, if I do not use with fnPH.parameterModificationContext(): the UI does not update and maya crashes when I refresh the Op.  

Andrew Kaufman

unread,
Dec 10, 2014, 3:45:07 PM12/10/14
to Dawei Sun, cort...@googlegroups.com
I'm assuming curve_parm is a StringVectorParameter, but is it possible that shape_c[0] isn't actually a string? Maybe its unicode instead and that's causing issues?

Andrew

Dawei Sun

unread,
Dec 10, 2014, 4:12:31 PM12/10/14
to cort...@googlegroups.com, sundawe...@gmail.com, and...@image-engine.com
curve_parm is StringVectorParameter,

and I change the code to:

            print repr(shape_c[0])  # unicode
            v.append(str(shape_c[0])) # convert to string before append to vlaue

still crash maya.

John Haddon

unread,
Dec 11, 2014, 4:42:28 AM12/11/14
to cort...@googlegroups.com, sundawe...@gmail.com, Andrew Kaufman
Could you set the MAYA_DEBUG_ENABLE_CRASH_REPORTING environment variable to 1, and then send us the stack trace you get when Maya crashes?
Cheers...
John


From: cort...@googlegroups.com [cort...@googlegroups.com] on behalf of Dawei Sun [sundawe...@gmail.com]
Sent: Wednesday, December 10, 2014 1:12 PM
To: cort...@googlegroups.com
Cc: sundawe...@gmail.com; Andrew Kaufman
Subject: Re: [cortex] How to add item to StringVectorParameter in python

Dawei Sun

unread,
Dec 11, 2014, 4:39:45 PM12/11/14
to cort...@googlegroups.com, sundawe...@gmail.com, and...@image-engine.com, jo...@image-engine.com
We found out why it is crashing, it is not the cortex code, it is our custom procedure that connect to the curveOp result.  thanks for all the help.
Reply all
Reply to author
Forward
0 new messages