Dali Khalifa Posted May 22, 2020 Share Posted May 22, 2020 Hello everyone I need your help guys. i'm working on a new tool using marionettes , i used to modify some nodes to get what i want , but at this level i don't know what to do , so i need someone (who know scripting) to build a node for me. the job of the wanted node is to calculate the minimum number in a portions of the input "list" , the length of portion is defined by the input "step" , and as result it returns a list of booleans (true if the item is the min number , false if not) and a list of indexes of the minimum numbers in each portion (the index related to the input list not the portion). Quote Link to comment
Dali Khalifa Posted May 22, 2020 Author Share Posted May 22, 2020 Here an example to make it clear Quote Link to comment
Dali Khalifa Posted May 23, 2020 Author Share Posted May 23, 2020 I'm trying with this script , but still can't reach any result. Could someone help me to fix it Quote Link to comment
MRoth Posted May 23, 2020 Share Posted May 23, 2020 Because I am using a student version, I can't send you the finished node. So here's the code that does what you want. #MRoth #V1.0 20200523 @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): #APPEARANCE #Name this = Marionette.Node( 'Get Part Min' ) this.SetDescription( 'Break the list into a list of lists of length n' ) #Input Ports inList = Marionette.PortIn( [], "list" ) inList.SetDescription( "The input list" ) n = Marionette.PortIn( 1, 'nStep' ) n.SetDescription('Number of items per split list') #OIP Controls #Output Ports list = Marionette.PortOut('lists') list.SetDescription( "The result lists" ) mi = Marionette.PortOut('nMin') mi.SetDescription( "The min value per list" ) bo = Marionette.PortOut('iIndex') bo.SetDescription( "A bool that indicates whether it is the min value in the list." ) ind = Marionette.PortOut('bMin') ind.SetDescription( "The indexes of all min values." ) #BEHAVIOR this.SetListAbsorb() def RunNode(self): #inputs list = self.Params.inList.value n = self.Params.n.value #script n = n[0] newList = [list[x:x+n] for x in range(0, len(list), n)] mins = [] bools = [] index = [] for x in range(len(newList)): l = newList[x] m = min(l) mins.append(m) for y in range(len(l)): item = l[y] if m == item: bools.append(True) index.append(n * x + y) else: bools.append(False) #outputs self.Params.list.value = newList self.Params.mi.value = mins self.Params.bo.value = bools self.Params.ind.value = index And here how the node is installed. There are certainly better ways to build the node, but the above one works, which in my opinion, is the most important thing. 2 Quote Link to comment
Dali Khalifa Posted May 23, 2020 Author Share Posted May 23, 2020 Thank you very much @MRoth , i appreciate your help. Regards 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.