Accessing Shared Parameter Part 2

Accessing Shared Parameter Part 2

Hello all, I’m here to continue on the previous post of Accessing Shared Parameter Part 1. In this post, I’m going to share with you guys an alternative method to access the shared parameter file in your Revit model. The picture below shows the complete dynamo graph, it is basically similar to the previous graph posted in the previous, but different approach is being adopted in the python script.

import clr  
from Autodesk.DesignScript.Geometry import *  
# Import DocumentManager and TransactionManager  
import RevitServices  
from RevitServices.Persistence import DocumentManager  
from RevitServices.Transactions import TransactionManager  
# Import RevitAPI  
from Autodesk.Revit.DB import *  
# Import ToDSType(bool) extension method  
import Revit  
# Import ToProtoType, ToRevitType geometry conversion extension methods  
# Import DSCore nodes in Dynamo  
import DSCore  
from DSCore import *  
# Import python library  
import sys  
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'  
import os  
import shutil  
import math  
# Import math library  
from math import *  
#Import Data and Time  
from datetime import datetime  
now =  
#Import System Library  
import System  
from System.Collections.Generic import *  
from System.IO import Directory, Path  
doc = DocumentManager.Instance.CurrentDBDocument  
uiapp = DocumentManager.Instance.CurrentUIApplication  
app = uiapp.Application
#Preparing input from dynamo to revit  
SharedParameterFilePath = IN[0]  
app.SharedParametersFilename = SharedParameterFilePath  
SharedParamFile = app.OpenSharedParameterFile()  
grs = SharedParamFile.Groups   
guidList,nameList,datatypeList,dataCatList,Grouplist,visList,descripList,userModList = [],[],[],[],[],[],[],[]  
for grp in grs:  
    GroupName = grp.Name  
    defs = grp.Definitions  
    for definition in defs:  
#Final output  
OUT = guidList,nameList,datatypeList,dataCatList,Grouplist,visList,descripList,userModList  

Whereas the code above shows what is happening inside the python script. 

Essentially, we are utilizing Revit API to achieve this. 

app.SharedParametersFilename = SharedParameterFilePath refers to this API doc whereby we set the file path of the shared parameter file to desire location. Thereafter, we just open the shared parameter file using the OpenSharedParameterFile() method , getting the DefinitionFile data as output. Thus, finally, access its groups data through this API doc. Afterwhich, we can simply loop through each group to obtain its definition, and for each definition, append the required information or parameters as the output.

The output data is as per shown in the picture above and the downloadable files are below:

RVT file

DYN File

TXT file

If there’s any unclear information or things that is unclear, feel free to drop a comment down below. Else, as always, happy coding~

This Post Has 2 Comments

  1. Stephen Cheung

    May I access to the revit files and dynamos of both part1 and part2?
    Thank you!

    1. JunKang

      Hello Stephen, the link had been updated. Sorry for any inconvenience caused.

Leave a Reply