How Can I Create a Loop in Dynamo?

Hi,

When making a PDF, I want to make the file extension variable dependent. It works when you use the node in the image for a single file, but when you use it for 3 different files, it gives an error? Why do you think?

In this case, the custom node was setup for a specific list structure - a single item. If you give it a list it fails. List levels allow you to specify the @L1 item as the intended input from the list. The node would then “loop” for each item found at Level 1.

This example isn’t your exact scenario, but it shows how list levels work.


Without list levels, the multiplication node assumes a list structure (two lists) and iterates over both in parallel. The looping ends when one of the inputs runs out.
With list levels, we’ve specifically told the node to treat each item @L1 (at level 1 of our list structure) as a separate input for x. This means that 1 gets treated as an input for all three y values, then 2 gets treated as an input for all three y values, then 3… and so on.

I don’t understand exactly how to do it for file paths. they text

Object type doesn’t matter. It’s about controlling the list structure. You would provide the list of files with list levels @L1 to ensure that each item is iterated separately. If you’re still unclear then I recommend going back to the primer and working through the list levels protion.

Maybe I didn’t explain it, I’m sorry. I was converting some pages into PDF automatically. Afterwards, I wanted to open a new folder with the file names and put my file in the folder with the same name. That’s why I need to make the “DirectoryPath” part variable. However, there is no problem in single use, it gives an error in multi use.

That sounds like a problem with list levels.

You have the list of variable paths and you want each one to be used for a new PDF, right? If the PDF node only takes a single item as an argument then you need to use list levels to force that node to recognize each item in your list of paths as a new argument. Depending on the structure of other inputs to that node, you may have to do the same thing for them. (Hovering over an input will tell you if they have an expected list structure.)

EDIT: In the case of this node, it looks like it’s actually setup to take sublists, not individual items, as the arguments. When you send a single item, the node interprets that as a single list, but when you send an actual list of items, the structure doesn’t actually match what you need (or so I’m assuming based on the error). If you’re sending a list of individual arguments, then you need to specify each one of them as such using @L1.


(I don’t have this setup correctly, so I’m getting an export error, but you can see it’s executing three times - once per item.)

1 Like

It looks like you are trying to create or use a directory for each file - I’ve highlighted the trailing backslashes which indicate that filename is a folder. What happens if you just feed the DirectoryPath to the export node?

That node only indicates the main path.

Thanks I understand now and it works.

1 Like