Jump to content

Need help with a new Marionette node


Recommended Posts

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).

 

Untitled-1.thumb.png.6fb2d28a677e1b8288b548e8215f6548.png

 

 

Link to comment

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.

grafik.thumb.png.137c428b833807d635d36af399f88f06.png

 

There are certainly better ways to build the node, but the above one works, which in my opinion, is the most important thing.

  • Like 2
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...