Jump to content
Developer Wiki and Function Reference Links ×

Confused on how Pop Front / Pop Back / Rotate / etc. can be used to repeat actions


Recommended Posts

I have an almost completed nod network that works so well, but the final step is causing problems for me. I do not understand how to loop the logic to run through a full list.

Attaching a screenshot showing part of the area:


In short, I have a dynamic number of possible inputs. It could need to be done once, 5 times, or 500 times.


I have a portion of my marionette that tells me how many times I need to run it, but I can't figure out how to loop the network that many times.

In the attached screenshot, you will see that I have manually done it to work 3 times by using Pop Front / Split List, but there has to be a better way? With this method, it "works" with less than 3, but gives an error about a blank list, and then it doesn't work over 3... but it works exactly as I want when it is 3! Any suggestions would be awesome.

Link to comment

Alright, so I've been messing with more simplistic examples for the past few hours. What seems like it should be so easy is proving to be stopping me in my tracks.


I am attaching a simple example (saved back in v2022). If I can get assistance solving this one, I think I can apply the same logic to my main problem.


In the attached example, there are multiple shapes with a record attached. The record is an ID that matches the number (1-5) shown on the shapes.


I want to create a marionette network that says, "Sum/Add together the AREA of any shapes with the same ID". The network needs to support if the number of input shapes is different though (If you duplicate or delete some of the shapes, the same marionette network will still work. It will also work if you add ID 6 or higher...).


I am confident this is possible, but the "looping/repeating" methodology required is breaking my brain. Any help would be greatly appreciated.

Example v2022.vwx

Link to comment

Hi @ASag,

First off: your example file only contains what is visible in the screenshot you posted: text and rectangle objects. Unless it's well hidden, there are no Marionette Nodes in there.

Then: please have a look at this wonderful Marionette tool by @DomC:


This might be all you need, because this looks pretty similar.


From the partial screenshot of the network I cannot tell what you are trying to accomplish. Could you maybe post a document with the network?

Link to comment

@Antonio Landsberger 


Thank you for the reply!


I downloaded and looked through the exact example you posted yesterday, but I wasn’t able to determine a solution from it. If I tracked this correctly, this example works in a way where 1 object gets a single object output which I have gotten working successfully in other node networks I've created. (Please tell me I’m wrong if I traced my way through the above example improperly…)


In the example document (in my 2nd post), I intentionally didn’t include a network cause I felt like I might be attacking the issue incorrectly, so I didn’t want to start off the discussion on the wrong beginning logic. I have attached a new copy that includes a bit of what I’m trying, but I’m kind of stuck and might have attacked it incorrectly. In this copy, you will find that I am getting all 17 objects, and I am getting their ID from their record format. I’ve tried attaching another set of IDs to them, but I think I’m running in circles. In the end, what I want the script in this sample file to do is sum the area of all the shapes with t he same IDs.


Thanks for any feedback!

Example v2022.vwx

Link to comment

I should also specify - I realize that getting the above answer through a worksheet/report is very simple; however, the goal for the project involves pushing values into further networks, so I am trying to solve this through Marionette as opposed to using worksheets which is how I've typically done these types as asks in the past.

Link to comment

It's not a simple problem to solve I'm afraid - if you depend on the regular Marionette Nodes that is.

I tried my hand, but it's getting quite convoluted and compared to this one here it might not even be possible to solve with the default Node library.

Example v2022b.vwx


If I had to do this, I would most likely write my own node.



Maybe @DomC or @Letti R know how to tame this network to do their bidding.

@Marissa Farrell This network would also benefit from a modified Chunk Node that can take a list instead of a single integer.

  • Like 1
Link to comment



your example reminds me of a problem @DomC posted some years ago. You can solve it by using the node "add sequence". But i would never recommend solving this kind of problems like this. It is a much better solution to just write your own node with a little bit of Python. For comparison, creating the Marionette (even though i had a rough idea of the solution) took me some hours. Writing the solution in Python code took me less than 10 minutes (it is just 3 lines of code).


Here is what you want to do to create the Marionette:

  1. Sort the data. In this case the data is already sorted, so i skipped this part. If you need to sort your data you can write the id and the area of the object into tuples via the "Point 2D" node and then just sort the resulting list.
  2. Use the "add sequence" node on the list with the values. "add sequence" works like this: If you for example enter a list like [1,2,3,4] it will return this list [1,3,6,10] where each value is the sum of all values that came before.
  3. This means that the sums you want to calculate are somewhere in this list, you just have to pick the right ones and than subtract the sum of all the sums that came before.
  4.  To get the indices of the correct sum you can make a list with the occurances of the ids, subract 1 from the first item of the list (because indices are counted from 0) and then use "add sequence" on this list, you get the indices of the sums that you want to pick from the list that we calculated in 2.
  5. Now you have a list where the first value is the first sum, the second value is the first sum plus the second sum, the third value is the first sum plus the second sum plus the third sum and so on
  6. Now you have to create a list with the correct values that you have to subtract from the sums we just picked.
  7. To do that we rotate the list from 5. by -1 and set the first item of the list to 0.
  8. Like this you subtract nothing from the first sum we picked (because it already was correct), than you subtract the value of the first sum from the second sum, than  the value of the first two sums from the third sum and so on.

And here is a screenshot of this Marionette:



And here is how i would do the same thing (but better) with some Python code when writing a custom Marionette node:

class Params(metaclass = Marionette.OrderedClass):
	this = Marionette.Node( 'sum by id' )
	this.SetDescription( 'sum by id' )

	#Input Ports
	list_values_input = Marionette.PortIn( [] )
	list_values_input.SetDescription('The values input list')
	list_ids_input = Marionette.PortIn( [] )
	list_ids_input.SetDescription('The ids input list')

	#OIP Controls

	#Output Ports
	list_sums_values_output = Marionette.PortOut() 
	list_sums_values_output.SetDescription('The sums list')
	list_sums_ids_output = Marionette.PortOut() 
	list_sums_ids_output.SetDescription('The ids list') 


def RunNode(self):
	list_values = self.Params.list_values_input.value
	list_ids = self.Params.list_ids_input.value

	sums_dict = {}
	for id, value in zip(list_ids, list_values):
		sums_dict[id] = sums_dict.get(id, 0) + value

	self.Params.list_sums_values_output.value = list(sums_dict.values())
	self.Params.list_sums_ids_output.value = list(sums_dict.keys())

(i know this is more than 3 lines of code, but the code that does something with the data is only between "#script" and "#outputs". Everything else ist just the node appearance and so on)





  • Like 2
Link to comment

The few times I've posted here, I have received excellent and helpful feedback in learning how marionette works! Thank you both for your responses! I am going to go through them in detail here in the next day or two!



I do not have a programming background. Marionette has been a perfect way to mess around with what could be possible with more advanced programming knowledge. Both times I've posted here, the answer seems to be that it would be significantly more straightforward to solve where I am stuck with coding it directly... May be time to try learning code again...

Link to comment

@Antonio Landsberger @Letti R - I wanted to report back. I dove into both of your examples yesterday for a bit. The example of getting the sum of the areas was a simplistic example of where I was getting stuck. By reviewing your replies and repurposing some of the logic ideas, I got my network working successfully! Over the past few months, I've been able to connect a bunch of these networks together to automate a lot of my workflow. I still have some work to do before I will consider it completed, but the progress has been so exciting! Thank you both again!

  • Like 1
Link to comment

Hello @ASag




Both times I've posted here, the answer seems to be that it would be significantly more straightforward to solve where I am stuck with coding it directly... May be time to try learning code again...


I think Marionette and a little bit of programming go very well together, however for most things you dont need to write nodes / code on your own.

In my answers i usually try to show multiple ways on achieving a set goal (because there often is not just one "correct" way on how to do stuff), so that you can choose the solution that suits you best.



I do not have a programming background. Marionette has been a perfect way to mess around with what could be possible with more advanced programming knowledge.


Me neither. Actually it was Marionette that got me into learning how to program.





  • Like 1
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.

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