Batch export shared parameters

I am looking for a graph to batch export all shared parameters from a revit family to a shared parameters text file. I have found on here and put it together the below graph, and works well to export to excel. But i am struggling to find a way to write / add to the text file.

Thanks for your help in advance

Are you trying to create an actual shared parameters .txt file? The shared parameters files have very specific formatting which would probably be done best using Python.

You can probably start off with this as the base for your file:

# This is a Revit shared parameter file.
# Do not edit manually.
*META	VERSION	MINVERSION
META	2	1

Actually writing to the file is a bit more complicated. Each of the values are separated by a tab character, but the file format itself is not a .tsv

Yes, if possible to add the shared parameters to the “Shared parameter file” that we use in Edit Shared Parameters dialog box

This was actually a lot simpler than I thought. See below:

import System
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

param_name = IN[0]
param_guid = IN[1]
param_type = ParameterType.Text
group_name = IN[3]

definition_file = app.OpenSharedParameterFile()
definition_groups = definition_file.Groups

for group in definition_groups:
	if group.Name == group_name:
		ops = ExternalDefinitionCreationOptions(param_name, param_type)
		# Construct a Guid from a string
		ops.GUID = System.Guid(param_guid)
		group.Definitions.Create(ops)

I haven’t implemented any loops or exception handling in the above code, so if a parameter by the given name is already in the parameter group or if the GUID is already in use, it will raise an exception. I have also hard-coded the ParameterType for now since I’m not sure if your node is passing the actual ParameterType or just the name of it.

1 Like

Hello and thanks for your reply,
I have tried your script and can’t get it to work.
I doesn’t give any error, but doesn’t write anything to the text file neither.
Capture2

Hello,

I think that you are using the bad shared parameter Group. It must be the Group name as in the example and not the Parameter Group Name as PG_IDENTITY DATA …etc

In my way to the same issue resolution, I’m blocked when we need a loop to get all the list of parameters, and not only one of them…

The script I wrote is just a functional example, but it can be easily modified to accept a list of parameters. Before the for group in definition_groups, an additional for loop may be used, e.g.:

param_names = IN[0]
param_guids = IN[1]
param_types = IN[2]
group_names = IN[3]

for p_name, p_guid, p_type, g_name in zip(
    param_names,
    param_guids,
    param_types,
    group_names):
    for group in definition_groups:
        etc.

The above modification also assumes all inputs are the same length. This also isn’t the most efficient way to perform this task (the inner loop could probably be replaced with a dictionary containing the names of the definition groups as the keys and the actual definition groups as the values)

Hello,

With the new loop, and a bypass for handling exceptions, we have a problem with the sharedParameter file that becomes Unreadable …

We had to modify @zhukoven 's node SharedParameters.Info to not Output a string from the SharedParameterType output …

Any idea of how to resolve it ?

000-Paramètre partagés-2019 4 essai.txt (96.0 KB)

import System
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

p_names = IN[0]
p_guids = IN[1]
p_types = IN[2]
g_name = IN[3]

alreadyusednames = []

definition_file = app.OpenSharedParameterFile()
definition_groups = definition_file.Groups

for p_name, p_guid, p_type in zip(p_names, p_guids, p_types):
	for group in definition_groups:
		if group.Name == g_name and not p_name in alreadyusednames:
			ops = ExternalDefinitionCreationOptions(p_name, p_type)
			# Construct a Guid from a string
			ops.GUID = System.Guid(p_guid)
			group.Definitions.Create(ops)
			alreadyusednames.append(p_name)