har Posted May 2, 2016 Share Posted May 2, 2016 Hi all, not sure if this belongs here or on the Vectorscript board... I'm pretty new to Marionette and Vectorscript and have only limited experience with Python in general - Please be very slow with me My task: Inputs are an array of strings and a string. I want to output an array of all indices in the array that match the input string. My code: @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): this = Marionette.Node( 'Indices' ) this.SetDescription ('Find all Indices in List that equal Item') this.SetListAbsorb() list = Marionette.PortIn( [] ) list.SetDescription( "The input list" ) item = Marionette.PortIn( None ) item.SetDescription( "The item to be searched" ) outlist = Marionette.PortOut() outlist.SetDescription( "The result index list" ) def RunNode(self): item = self.Params.item.value lst = self.Params.list.value outlist = [i for i, x in enumerate(lst) if x == item] self.Params.outlist.value = outlist My problem: the item value seems to be casted to a "wrong" type, resulting in no output. converting it with "str()" won't help either. As soon as I hardcode item to some string, the function will work as expected. What am I doing wrong here? Thanks a lot in advance for any answer! Quote Link to comment
Patrick Winkler Posted May 2, 2016 Share Posted May 2, 2016 Hello har, You can solve this nealry with pure marionette. Take a look into the attached file. (The Equal 2 node in the Example is not native.) Quote Link to comment
har Posted May 2, 2016 Author Share Posted May 2, 2016 Hi Patrick, thanks a lot, that works for me. Also, greetings from Austria I deleted the GetItem node as I couldn't see any purpose and the network still works. Was there a specific reason for it? Aside from that, I'd still be interested why my script wouldn't work. Can anyone give some insight here? Quote Link to comment
Patrick Winkler Posted May 2, 2016 Share Posted May 2, 2016 (edited) You are right, GetItem is needless. I just didn't notice in the hurry... Finding the bug in your code was a real brainteaser: SetListAbsorb() will convert item 'A' for example to a list: ['A'] You can solve this by declaring list as PortInLits: @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): this = Marionette.Node( 'Indices' ) this.SetDescription ('Find all Indices in List that equal Item') #this.SetListAbsorb() list = Marionette.PortInLists ( [] ) list.SetDescription( "The input list" ) item = Marionette.PortIn( None ) item.SetDescription( "The item to be searched" ) outlist = Marionette.PortOut() outlist.SetDescription( "The result index list" ) def RunNode(self): item = self.Params.item.value lst = self.Params.list.value print (type (item)) outlist = [i for i, x in enumerate(lst) if x == item ] self.Params.outlist.value = outlist Edited May 2, 2016 by Patrick Winkler Quote Link to comment
har Posted May 3, 2016 Author Share Posted May 3, 2016 Hi Patrick, thanks for the insight! That actually helps me a great deal with another project... Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.