Fill parameter with sequence plus prefix

revit
dynamo

#1

Hello,

I’m new to Dynamo. I was trying to fill some object parameters with an unique number. But i have a few object groups.
So I thought i first select the objects with i want to give a prefix “A”, and start numbering 1, 2, 3, etc.
After that i wanted to select the next group of objects and go for “B” numbering, 1, 2, 3, etc.

But i get errors, “Warning: String.Insert operation failed.
Specified argument was out of the range of valid values.
Parameter name: startIndex”

maybe someone could help me?


#2

Welcome to the community and Dynamo in general! It looks like you’ve put in some efforts but don’t really know how to best execute what you’re after, so let me try and shed some light. Before I do though, let me give some quick advice: after you get this graph to work, take some time to run through the dynamo primer, cover to cover. Don’t skip anything and if anything is confusing do the exercise a second time and if you’re still confused after that post a question to the forum. I say this often, but I feel like it’s not quite often enough. It’s set up and organized to walk you through all the important concepts and methods you’ll need to get going, and will certainly save you more time than it takes to get though. Now then, onto the issue.

You are feeding a list of elements and a list of numbers into the Lost.IndexOfNode, so you have mismatched object type so nothing will ever match. You also haven’t set up lacing or levels so you’re looking for a list in the list (the primer will explain this), so I believe the result is a single -1 value. A -1 index value indicates that the thing you are looking for (the list of selected Revit elements)) doesn’t exist in the list you are looking in (a number sequence from 1 to 100). You are then feeding that single -1 value into the String insert node, and as a string can’t have a negative index you get the “index out of range” error. A tip to keep things straight in the future is to use more previews and watch nodes to flag issues earlier in the process.

That said, I’m a little lost as to why you’re getting the “PrefabNumber” parameter value from the elements as the empty value isn’t doing much. You can continue to do so if it’s pertinent to your workflow but if you’re looking for a clean number sequence with a prefix as you described above then it isn’t really useful and can be skipped. While I am admittedly lost as a result of that bit of the graph, you could try this:

  1. Wire the “select model elements node” into a List.Count node, and wire that into a code block which reads 1…X. This will generate a sequence as long as the list of selected elements starting at 1.
  2. Use String From Object node to turn the output of this into a string.
  3. Wire that into the str input of a String.Insert node. The index input should be a single 0, and the toInsert value should be your desired prefix (“A” in this case).
  4. You can then send the output of your initial select model elements node to an Element.SetParameterValueByName node, with the parameterName input being the name of your parameter, and the output of the String.Insert node in step 3 is the value input.

It is also possible to do steps 1-4 in a code block, with a single in line bit of code, but this shouldn’t be explored until after you get a hang on using nodes and have completed the primer. Give it a shot and let us know if you get stuck.


#3

Thanks Jacob,

I did it! (well you did it). I will first go trough the primer.
And then i will create filters that will color my prefab sets different. (aka, i have many ideas)

Thanks!


#4

Cool! Please mark the solution so others can find it in the future. :smile: