Multiple values for multiple families

Hi, I am pretty new to Dynamo, started a couple of weeks ago and I am trying to manage some things to make my job faster with some automation.

I am trying to open each family document from a folder and add a parameter and then add some value for this parameter. I was able to do that using just a string, replacing the group “Import Parameters from Excel” with just a string node, but then when I tried to do that importing some data from excel it does no work. I think that what is happening is that dynamo is reading all the values each time it opens a document instead of reading the first line for the first document opened and so on.

When I run there is an error in the “Set the Values for the Parameters”
Warning: Parameter.SetValue operation failed.
Looks up a localized string similar to Number of items does not match the number of keys. Length of parameterName and values must be the same

Edit:

Add Parameters Multiple Families + Values.dyn (60.7 KB)
Dynamo - Parâmetros.xlsx (17.0 KB)

I just tried to create a script that finds the index for the family inside the excel file, but apparently, it keeps the first match instead of changing each time a document opens in the background.

Could you please share the excel file?

1 Like

Sorry, I was reading the post on mibile phone and did not notice your attachments.

However, I dont think you can open and manipulate documents in batch mode within dynamo. The issue here is that dynamo works within the current document and cannot access the database of other documents as it is runs at the “document level”. But to process multiple documents, you would require an “application level” automation, using Python Scripting or C#. Then in that script, you have to use a TransactionGroup Please check out Jeremy’s Post on his blog;

May be I am wrong. Let other veterans on this platform advise…

Creating a parameter for a family is so easy with Revit API’s FamilyManager Class. There is a method called AddParameter. Something like;

try:
    t = Transaction(doc, "addParameter")
    t.Start()
    fm = doc.FamilyManager
    new_parameter = fm.AddParameter("Test Parameter", BuiltInParameterGroup.PG_CONSTRAINTS, ParameterType.Text, False)
    t.Commit()
    print("Parameter Created")
except Exception as e:
    print(str(e))

Could explain the reason for using Transaction Groups? I have never used it and I quite don’t understand how it works.

Besides that, I was able to do something similar to what I want, I could open all the documents and then add a parameter and a value for it, what I am trying now is to change this value, so basically I am adding the “parameter X” and I want the “value 1” to family 1 and so on. I tried to create a script that could give me the right index for a specific family. Is that a way to do that? Everytime I do it it gives me just 0 as index since it finds just the first document in the table, I though it was possible to find a different index for each of the documents that were opened.

Say,
You have some .rfa files in a folder.
You want to;

  1. Open each file
  2. Add a Parameter to the family file (.rfa)
  3. Set a default value for the parameter as per the excel file
  4. Save the file
  5. Close the file

Is this what you need to do?

Exactly, I have an excel file with all the values for that specific parameters.

This is what I tried in the image, but I can just put a fixed value for all families, I can’t get the values from the excel file and add it.

Getting value from excel is so easy. There is a default node for that. Check out this image attached.

Now you need to do the required list manipulations, based on the list structure of the output of Data.ImportExcel node.

If you see the first image I uploaded, I do that twice, one to get all the parameters and one to get all the values, my doubt is related to how dynamo works while opening the documents in the background. I want to get the first line of the value table and add it to the first family and then get the second line of the value table and add it to the second table, but when I do that it does not work, the group “Importing Values from Excel” just returns the first line for all the families

Basically you want to remove the header row of parameters list. There is a node called RestOfItems. That will omit the first item in a list and would get you the rest of them.

1 Like

No, I could do that just directly into excel. I just want to be able to add those values in the families, but every time I get just the first line. This is my question since the beginning.

I do not know if it is a language barrier or something, is so, sorry for my english, I will try again.

I created this flowchart to explain.

I am able to do until the number 3 withou problems and I can do the number 4 with just one value, so I could put a string and then I would be able to do everything, but my goal is to add a description to each of the families, so the descriptions are diferent.
Because they are different I created the table using the same order as the families appears inside the folder, so evey N family matchs to every N value.

The place where I am stuck right now is that when I get to num 4 the node just gets the first value, I want to know how to make it get the N value from the table based on the N family that is being opened in the background.