How to get the shared parameter discipline from file in different revit versions 2019,2021 and beyond

basically I want to extract the discipline from the shared parameter property from the txt file of shared parameters.

I thought it could be like: UnitType Property is until Revit 2020 but in revit 2021 is updated to GetUnitTypeId(), although any of those are available beyond revit 2021?
image

essentially I want to get the properties of shared parameters in the txt external file of shared parameters, they are not used yet in the project or family editor, not added as project/family parameters.

Hey,

This seems unchanged in the API?

Hope that helps,

Mark

I tried this suggestion based in the link provided

//tmpParam is  a Family Parameter
string getDateTypeId = tmpParam.Definition.GetDataType().TypeId;

string Discipline = getDateTypeId.Split(':')[0].Split('.').Last();
string TypeOfParameter = getDateTypeId.Split(':')[1].Split('-')[0];

but a shared parameter from a txt file does not have this property I believe, I do not have results for this, essentially I want to get the properties of shared parameters in the txt external file of shared parameters, they are not used yet in the project or family editor, not added as project/family parameters.

Hey,

Can you path to the shared parameter file and read the part of the .txt. you need? they have a constant structure?

It appears to be an integer which relates to this enumeration?

Updated to…

But still, 1 appears to represent Architecture?

*PARAM	GUID	NAME	DATATYPE	DATACATEGORY	GROUP	VISIBLE	DESCRIPTION	USERMODIFIABLE	HIDEWHENNOVALUE
PARAM	62792403-ad7f-40a0-b10f-01adc8e38abc	OBE_Project_UValue_Walls	TEXT		**1**	1	The thermal performance for walls (W/m2K)	1	0

I might be wrong :slight_smile:

Mark

Hi,

here an example with Revit 2022+

import sys
import clr
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
sdkNumber = int(app.VersionNumber)

out = []
spf = app.OpenSharedParameterFile() 
if spf is not None :
    #
    spfGroups = spf.Groups
    for group in spfGroups:
        setExternalDef = group.Definitions
        for ext_def in setExternalDef:
            specTypeId = ext_def.GetDataType()
            # set default discipline
            discipline = LabelUtils.GetLabelForDiscipline(DisciplineTypeId.Common)
            if UnitUtils.IsMeasurableSpec(specTypeId):
                disciplineTypeId = UnitUtils.GetDiscipline(specTypeId)
                discipline = LabelUtils.GetLabelForDiscipline(disciplineTypeId)
            out.append([discipline, ext_def.Name, ext_def])

OUT = out
1 Like

is there any way to get this done compatible for any Revit version from 2019 to 2023?

I am getting this error in Revit 2019 for example:

 Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. 
Traceback (most recent call last):
  File "<string>", line 26, in <module>
AttributeError: 'ExternalDefinition' object has no attribute 'GetDataType'

I tried something like that but the results read like: UT_Custom,UT_Number, UT_Length, but I was asking the Discipline instead not that

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

# Get the current document and application instances
doc = DocumentManager.Instance.CurrentDBDocument
app = doc.Application

# Open the shared parameters file
spfile = app.OpenSharedParameterFile()

# Initialize a list to collect dictionaries of parameter details
paramDetails = []

if spfile:  # Check if the shared parameters file is not None
    for group in spfile.Groups:
        groupName = group.Name  # Get the name of the group
        for definition in group.Definitions:
            # Ensure we're working with ExternalDefinition to access specific properties
            if isinstance(definition, ExternalDefinition):
                details = Dictionary[str, object]()

                # Check for UnitType in API versions prior to Revit 2021
                if hasattr(definition, "UnitType"):  # Older API versions
                    details.Add("UnitType", definition.UnitType.ToString())
                # For Revit 2021 and later, use GetUnitTypeId
                elif hasattr(definition, "GetUnitTypeId"):  # Revit 2021+
                    unitTypeId = definition.GetUnitTypeId()
                    # Use the LabelUtils to get a more readable string
                    unitTypeString = LabelUtils.GetLabelFor(unitTypeId)
                    details.Add("UnitType", unitTypeString)
                
                
                paramDetails.append(details)

# Preparing output to Dynamo
OUT = paramDetails

for Revit 2022-, you can do this with UnitType property and GetUnitGroup() method

import sys
import clr
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
sdkNumber = int(app.VersionNumber)

out = []
spf = app.OpenSharedParameterFile() 
if spf is not None :
    #
    spfGroups = spf.Groups
    for group in spfGroups:
        setExternalDef = group.Definitions
        for ext_def in setExternalDef:
            if sdkNumber > 2021:
                specTypeId = ext_def.GetDataType()
                # set default discipline
                discipline = LabelUtils.GetLabelForDiscipline(DisciplineTypeId.Common)
                if UnitUtils.IsMeasurableSpec(specTypeId):
                    disciplineTypeId = UnitUtils.GetDiscipline(specTypeId)
                    discipline = LabelUtils.GetLabelForDiscipline(disciplineTypeId)
                out.append([discipline, ext_def.Name, ext_def])
            else:
                unitType = ext_def.UnitType 
                discipline = UnitUtils.GetUnitGroup(unitType).ToString()
                out.append([discipline, ext_def.Name, ext_def])


OUT = out
3 Likes

hello, I really appreciate the answers which are awesome. I tried in Revit 2019 and get this error:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. 
Traceback (most recent call last):
  File "<string>", line 36, in <module>
Exception: unitType is an invalid unit type.  See UnitUtils.IsValidUnitType() and UnitUtils.GetValidUnitTypes().
Parameter name: unitType

Discipline is not something that exists in the shared parameters txt file, but we could understand that if parameter type is length that means its discipline is under “Common”, I did not imagine something so simple like this can cause trouble.

try to implement this control as mentioned in the traceback, if not you can set it to Common.