Loop one by one

Hi All,

I’ve been working on a rebar export script for a long time. My script is working fine as long as I select 1 beam. The goal is to have an export file for all beams in the project. For that I need to feed my script the beam elements one by one, so not as a list. My complex script can’t handle that.
Is there anyway to do this in Dynamo? For example send element 1, script creates an export file, when finished writing the export file a signal is send to feed element 2.
It’s like a “for…next loop”

1 Like

Processing a list would be the intended way. Adjusting list levels and lacing can be complex but it resolves things in the easiest way.

As an alternate, you could try to create a custom node from the graph; that would reduce memory consumption if built correctly, but the same amount of calculations will be required by the cpu.

1 Like

I know a list is the intended way but my script is very complex and works well for one selected element.
I’m trying to get it to work with a list but it’s hard and it might never work.
Do you have a small example of how to feed a custum node element by element?

Set the input to a single item - ie: framingElement: var. More on this can be found in the custom node section of the Dynamo Primer.

If that fails post your .dyn and a file to run it on with say two or three beams with rebar and I’ll try and have a look.

Thanks Jacob, I’m going to look into that and come back to you.

1 Like

Here’s an idea that is so dumb it might be smart…

At the start of your script put a number slider to cycle through one by one, then at the end set up a mouse clicker to queue up a mouse click on the slider uptick, and the manual run button.

Python has some tools to click the screen at XY coordinates. Ive used some custom implementations if this before in Grasshopper to register vectors into the view at clicked points, but havent tried in dynamo or making the click itself using python.

2 Likes

Could also implement a counter, which would likely be simpler than automating a mouse click (there are a LOT of issues with that around resolution and such).

Check if there is a .txt file with the same name as the active graph in the same path as the dynamo node; if so, open it, read the value, pass that out, and write back one more than the value. If not, make a new file and pass out a 0. The value passed from the Python node can then be used as a ‘get item at index’ node to pull out one item from the total selection. Run by player, and delete the text file when you’re done.

1 Like

Simple Revit file to run it on? Otherwise my setup might not align to yours.

Hi Jacob,
I send you a message with a link to the Revit file.

@jacob.small Hi, did you find some time to take a look at my script?

Hopefully Jacob has time he yust moved to Stockholm

I spent a bit looking this over, but because of the constant shift from Python to Nodes it’d be a big lift. Shifting the Python code sets into a custom node would go a long way here as you’d be able to just manage the collection of rebar via list levels, and would help with long term maintenance of the code base as well.

The other option would be to go pure python - from the initial collection begin to loop over the dataset and do all of the work there, and then pack that in a custom node or leave it loose.

As the graph currently stands it’s too big a lift for me to easily help due to the other stuff I have on my plate (moving, the day job, and the like).

Thanks for your reply Jacob, you’re right I’m going to have rewrite my messy code.
Good luck with moving!

1 Like