Hello all.
Relatively new into the Dynamo world. Pretty much self teaching.
I’ve got a bit going on to take a bunch of elements, create polygons, look for text within the polygon, truncate the text found, and assign the substring as a parameter to a narrowed down list of elements meeting certain criteria. The list is correct. However, upon running, only the first element of the list is changed. I realize it could be a timing issue. Just not sure if it goes back to do something else after the first element is changed. I can put a basic string output with the text I want and it changes every element. I’m trying to keep it dynamic based on the text found within the polygon. I’ve tried putting a pause node in various places but have had no luck.
Bottom half of the script develops polygons from connected model lines and searches within each for model text and truncates it to reassign to the parameter above.
Upper half provides list of elements within the polygons based on specified criteria and forms the list that the parameter will be changed on. (Note: there are 4 polygons and the pics show action on 1 for the moment until I get it working. (Sorry…new users only allowed to embed a single pic)
Much thanks for any assistance or advice.
Try setting the list level of the value parameter in Element.SetParameterByName node to @L1. [click on the > to get the list level options]
Coz Lacing auto is Shortest.
Right click to node: Element.SetParameterByName
→ then set Lacing to “Longest”
Both suggestions above will work. List levels is the more modern and generally preferred approach while lacing tends to be a quick fix for most things but less flexible.
The actual issue here is that your substring, the value input, is a list. The SetParameterByName node sees that you’re providing a list of elements and a list of values and assumes that those structures should be aligned. Since you only have one substring value, only the first element gets set. The above suggestions work because they tell the node (in different ways) how to handle those list structures. The easiest and most complete solution would be to remove the list structure from the substring value. We can’t see the rest of your graph, but this list structure is likely coming from an upstream input. You can attempt to fix the issue there or anywhere before the SetParameterByName node. All you need is GetItemAtIndex or a code block with some shorthand code: list[0];
yeah or maybe try List.FirstItem
Thank you! Worked perfectly. Now, to find a primer on how list levels work.
Question(s): Do inputs not work by default @L1? Besides understanding deeper, how would one know it could be a possible list level issue? Besides the (2) circled areas and, obviously, the full correct output/result, everything looks the same. Another column to the list ‘tree’ (@3) is present now. Again, I really appreciate you and others being willing to share your knowledge.
This is what I tried to explain above. List levels and lacing will “fix” your problem of only one output, but it won’t fix the list structure issue. To fix that, you need to remove the list structure issue - which is the extra dimension in your substring output.
Node inputs have an inherent list structure. For the SetParameterByName node, each of its inputs expects a single value (by default). We know this because the input ports specify structure ([] means singular list, [][] means multi-dimensional list). (Sometimes you will have to guess with custom nodes though.)
Dynamo is smart enough to replicate node functionality across lists though. That’s why you can provide a list of inputs to a node expecting a singular value and it correctly returns a list of outputs. However, these “assumptions” Dynamo makes only work for one degree of variance. If you have a node like
SetParameterByName with multiple inputs expecting a singular value and you provide more than one of them with lists, the node doesn’t know it should handle replication anymore. Do you treat one input as the controlling parameter and replicate across all other variations (
a*b) or do you treat each list as a set of inputs and replicate on length (
a=b)? List Levels allow you to specify that replication so you get the correct mapping of values and the correct structure - assuming that the mapping and structure is possible based on the inputs provided.
It is definitely worth spending more time getting familiar with this concept and working through the Primer like you suggested. As soon as you get into list management, list levels becomes incredibly important and powerful.
Thank you, this makes sense. Although, I will say (and I could be wrong because I’ve tried so many things) that I feel like I took the substring node, cut off all inputs from it and fed it ‘constant’ inputs by using a basic string and numbers to trim it down. That idea worked and is what led me to believe it was something to do with timing.
All that said, your explanation was amazing and easy to follow. Now that I know I shouldn’t feed a list into a single, stable input node (for most purposes), your suggestion of GetItemAtIndex is what I’ll likely use going forward. Thanks again.
Somewhere you have something that’s seeing an extra list level. This has nothing to do with how many items you have (as you’ve seen above, you can have a list containing only one item) but could be built into the inherent structure of a node you’re using.
See if the explanation I added above helps you identify it. The substring node uses a singular list structure for each of its inputs, so the structure is coming from something upstream of that node.