Have you ever wondered how to access shared parameter file, i.e. SharedParameterFile.txt, via dynamo? Well, you’ve come to the right place. Here, I’m going to share two different ways of accessing that .txt file.
1) Accessing through File.ReadText
The picture above shows a simple workflow on how to parse the SharedParameterFile.txt file into readable data in dynamo.
In order to parse any data or information, we are required to understand the underlying format of that particular data/information, similar concept to decoding JSON data as discussed in the earlier post. So let’s open the SharedParameterFile.txt file and observe how the data is being formatted.
From the picture above, we can observe that the data are formatted in way whereby it can be split by lines and after which split by ‘tab’ to sort and group relevant data together. Headers were also given, for example “PARAM” and “GROUP”, to allow better organizing of data. The splitting of data is computed through the python script (Python Script | Split by new line and tab) and the code can is as shown below:
# Import python library import sys pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib' sys.path.append(pyt_path) import os import shutil import math # Import math library from math import * #Preparing input from dynamo to revit ShareParameterStr = IN.split('\n') newlist =  for Str in ShareParameterStr: StrGroup = Str.split('\t') StrGroup.append(StrGroup.pop()[:-1]) Str.split('\t')[:-1].insert(-1,Str.split('\t')[-1][:-1]) newlist.append(StrGroup) #Final output OUT = newlist
The code shown above are quite straight forward, whereby we split the text by lines and “tab”, at the same time removing unwanted spaces.
The video below shows each set of data after being parsed by the python script.
After splitting the data according, we were left with beautiful sets of data and whats left is the extraction of relevant data and vola, the final output is as per shown in the first picture above. The extracting of data is computed through the python script (Python Script | Split by new line and tab) and the code can is as shown below:
# Import python library import sys pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib' sys.path.append(pyt_path) import os import shutil import math # Import math library from math import * #Preparing input from dynamo to revit ShareParameterStr = IN grplist =  guidList,nameList,datatypeList,dataCatList,Grouplist,visList,descripList,userModList = ,,,,,,, newlist = range(0,max([int(x) for x in ShareParameterStr if x=="GROUP"])+1) for ss in newlist: grplist.append(None) for Str in ShareParameterStr: if Str == "GROUP": grplist[int(Str)]=Str if Str == "PARAM": guidList.append(Str) nameList.append(Str) datatypeList.append(Str) dataCatList.append(Str) Grouplist.append(grplist[int(Str)]) visList.append(Str=="1") descripList.append(Str) userModList.append(Str=="1") #Final output OUT = guidList,nameList,datatypeList,dataCatList,Grouplist,visList,descripList,userModList
The code above are not as straight forward as the previous one as it requires some process thinking but to put it in simple term, I’m using the first item in the nested list as an indicator to check if it is a parameter data or group and hence, appending the relevant data according.
That is all on how to access SharedParameterFile.txt file using File.ReadText (part 1). I believe that is enough content for this post. Don’t worry, access SharedParameterFile.txt file (part 2) will be out, soon i guess, in the next post.
All the relevant files can be found in the download link below.
As always, if there is any uncertainty in the content, feel free to comment down your question below and I will try my best to answer them. Happy coding~