List of things I shouldn't do because soft says so
-
iamVFX
- Posts: 697
- Joined: 24 Sep 2010, 16:28
Re: List of things I shouldn't do because soft says so
I'm just tired of dealing with workarounds for shit like this, sorry. You can happily close this thread, I'm not interested in it anymore 
-
EricTRocks
- Moderator
- Posts: 754
- Joined: 25 Nov 2009, 00:41
Re: List of things I shouldn't do because soft says so
How is it a workaround? You're trying to have the SDK return objects that it doesn't understand...
-
csaez
- Posts: 253
- Joined: 09 Jul 2012, 13:31
- Skype: csaezmargotta
- Location: Sydney, Australia
Re: List of things I shouldn't do because soft says so
There's an internet slang for this kind of threads... don't waste your time here, Eric.EricTRocks wrote:How is it a workaround? You're trying to have the SDK return objects that it doesn't understand...
-
xsisupport
- Posts: 713
- Joined: 09 Jun 2009, 09:02
- Location: Montreal Canada
Re: List of things I shouldn't do because soft says so
I can't remember anymore if I tested returned Python objects from commands, but I'm pretty sure you cannot pass them in. The famous example is trying to store dictionaries with SetGlobal and SetGlobalObject.
Something similar here:
http://xsisupport.com/2011/01/11/python-using-plugin-userdata-to-pass-data-to-ppg-callbacks/
Something similar here:
http://xsisupport.com/2011/01/11/python-using-plugin-userdata-to-pass-data-to-ppg-callbacks/
-
EricTRocks
- Moderator
- Posts: 754
- Joined: 25 Nov 2009, 00:41
Re: List of things I shouldn't do because soft says so
If I (or anyone else) shouldn't waste my time on this thread, then we should delete the thread as it has no purpose on the programming board.
A little while ago I tried returning multiple objects from commands such a a single object, and a python list and I couldn't return multiple values which spurred the realization that you cannot return Python objects. I tried with a collection too but could not get multiple objects returned either way.
This is a troubling thread as it seems to be a place where the poster just wants to rant about things they run into while trying to learn to code and use the Softimage Object model. Which is not a useful thread on a forum that is supposed to be about useful information and discussions about programming. Which this thread is not.
I'm trying to shift it into one but it seems that it is futile. In which case if it doesn't get on to something soon I'm going to remove it. I'm hoping I don't have to do that. Instead I'd love to help the poster get some understanding of what they are running into and ways (valid not workarounds) to get it to work.
A little while ago I tried returning multiple objects from commands such a a single object, and a python list and I couldn't return multiple values which spurred the realization that you cannot return Python objects. I tried with a collection too but could not get multiple objects returned either way.
This is a troubling thread as it seems to be a place where the poster just wants to rant about things they run into while trying to learn to code and use the Softimage Object model. Which is not a useful thread on a forum that is supposed to be about useful information and discussions about programming. Which this thread is not.
I'm trying to shift it into one but it seems that it is futile. In which case if it doesn't get on to something soon I'm going to remove it. I'm hoping I don't have to do that. Instead I'd love to help the poster get some understanding of what they are running into and ways (valid not workarounds) to get it to work.
-
scaron
- Posts: 119
- Joined: 08 Jul 2009, 03:16
Re: List of things I shouldn't do because soft says so
i don't really see an issue here. yes we know the python implementation has quirks and we know this because of python on windows and com/dispatch stuff.
so just use collection argument handler, softimage will do the work and whenever you want to modify it like a list, just wrap list() around it. it is no different really than going from list to a dictionary since collections are key values and not simple lists. yes this means you aren't using all native python data types, but this is the cost of having support for multiple languages. sure you might not agree or care that softimage has to support these other languages but this is how you cope with it...
here is the new commands...
here is the new usage script...
here is some output...
so just use collection argument handler, softimage will do the work and whenever you want to modify it like a list, just wrap list() around it. it is no different really than going from list to a dictionary since collections are key values and not simple lists. yes this means you aren't using all native python data types, but this is the cost of having support for multiple languages. sure you might not agree or care that softimage has to support these other languages but this is how you cope with it...
here is the new commands...
Code: Select all
from sipyutils import *
si = si()
def XSILoadPlugin(reg):
reg.Name = "close enough?"
reg.RegisterCommand("ACommand", "ACommand")
reg.RegisterCommand("BCommand", "BCommand")
def ACommand_Init(ctxt):
ctxt.Source.ReturnValue = True
ctxt.Source.Arguments.AddWithHandler("selection", "Collection")
def BCommand_Init(ctxt):
ctxt.Source.ReturnValue = True
ctxt.Source.Arguments.AddWithHandler("list_arg", "Collection")
def ACommand_Execute(selection):
log("ACommand class name : %s" % si.ClassName(selection))
log("ACommand count : %i" % selection.Count)
log("ACommand get as text : %s" % selection.GetAsText())
return list(selection)
def BCommand_Execute(list_arg):
log("BCommand class name : %s" % si.ClassName(list_arg))
log("BCommand count : %s" % list_arg.Count)
# conver to a list if you want to use it like one
list_arg = list(list_arg)
log("BCommand converted : %s" % type(list_arg))
return list_argCode: Select all
from sipyutils import *
si = si()
artn = si.ACommand(si.Selection)
# comes back as a tuple
log("ACommand return : %s" % type(artn))
# convert it to a list if you need to modify it
artn = list(artn)
log("ACommand return converted : %s" % type(artn))
# pass in a list
brtn = si.BCommand(artn)
log("BCommand return : %s" % type(brtn))
# you can loop over tuples if you want
for item in brtn:
log("%s : %s" % (si.ClassName(item),item))Code: Select all
# INFO : ACommand class name: Selection
# INFO : ACommand count : 2
# INFO : ACommand get as text: arc,sphere1
Application.ACommand("arc,sphere1")
# INFO : ACommand return : <type 'tuple'>
# INFO : ACommand return converted : <type 'list'>
# INFO : BCommand class name: Object
# INFO : BCommand count : 2
# INFO : BCommand converted : <type 'list'>
Application.BCommand("arc,sphere1")
# INFO : BCommand return : <type 'tuple'>
# INFO : X3DObject : arc
# INFO : X3DObject : sphere1
