Open files from a directory and change a parameter, then re-save the file

Hi there,
I am hoping to get some advice for this graph

What I am Trying to do:
Change the same project parameter in a number of Revit central files within a directory. Basically, I have hundreds of project files located in a specific directory that all have a “Text” project parameter in them for the Exposure Class of Concrete. I would like Dynamo to be able to open all of these files, change this parameter to a user input value, then save and close the file.

What works:
I am able to locate and open all files within the directory and successfully save them. This is evident by the time stamp on the file. I have been able to find the name of the parameter using a node from the “Clockwork” Package (Document.projectParameters), and filter it out.

Where it goes wrong:
There are two potential problem areas (that I see), the first is when I am trying to select the category from the documents. (Here I am using Genius Loci node “SelectByCategory from Document”). Sometimes this identifies the families and other times it won’t. The other problem area is when I try to actually change the parameter value. (Here I am using a node from the Rhythm package “Element.SetParameterByNameTypeOrInstance”). The error that I get is “Warning: Element.SetParameterByNameTypeOrInstance operation failed. Attempt to modify the model outside of transaction.”. Even when the elements are selected with the previous node, I still get the same error. It’s almost like I can’t access this information… Is this because they are opening in the background and are not the active file?

If anyone can provide any direction or insight into what I may be doing wrong or need to adjust, it would be greatly appreciated!

Thanks in advance.

Directory%20Files%20Project%20Parameter%20Change

Level Structure: L2 on the Element.SetParameter. Both parameterValue and Element.
If not, Flatten your lists before adding them to the node. :slight_smile:

Hi @CADifier,

Use the SetParameterByName in Document node.
The SetParameterByName node that you use only works in the current document.

Hi @ CVestesen and, @Alban_de_Chasteigner,
Thank you for your responses. @Alban_de_Chasteigner, I have tried to duplicate your graph as it was definitely a more concise way to get things done. However, there still seems to be a problem. It doesn’t appear to be finding the parameter anymore. It also won’t close the file.

It works well for me.

P.S : Connect the output Document to the input Document in the Applications.CloseDocument node.

1 Like

@Alban_de_Chasteigner, Thank you for your continued help here. The only differences I’ve been able to spot between your graph and mine is the list on the “Applications.OpenDocumentFile” node where mine shows separate lists and Dictionary, and the name of the “SelectByCategory from Document” and yours says “SelectByCategory in Document”. I do also have longest lacing set on this node as well.

@CADifier,

Add a List.Flatten with a amount of 1 after the SetParameterByName in Document node.

Ok, I have tried adding the flatten after that node, and still nothing. It’s almost like it can’t find the parameter from the files. The set parameter node is showing the element as null and the document as null

Hi,

You didn’t exactly reproduce my graph.
You must set the longest lacing on the SetParameterByName in Document node with multiple documents.
Try this:
SetParamInDoc V2.0.dyn (26.9 KB)

Thank you for your graph. I tried it and there were a couple of unresolved nodes that I had to update from the Rhythm package. Once that was done I ran it and still ran into the same problem. It’s like it isn’t seeing the parameters. I was going to send you a stripped down version of one of the Revit files but because I am a new user, I cannot upload attachments yet…

Could the problem possibly be something to do with the fact that all of these files are central models?

Hi,

It does not have to do with being a central file.
You could try a dropbox, wetransfer or google drive link and post that here ?

Well, you created an type parameter and not an instance parameter.
That explains the fails !

Add Element.ElementType+ node of Clockwork package to write a value in the structural framing type.

P.S : Please note that with several documents, the lacing will be different. See previous posts.

1 Like

That seems to have done the trick. Once again, thank you so much for your time. I really appreciate it!
For whatever reason, my nodes show up as empty and blank now, but the end result is completed, and that was the goal. It didn’t work until I set that Element.ElementType+ node to longest lacing.

Need help in that Warning error

@ Alban_de_Chasteigner

Please see this warning i don’t know this type of error

image