Get Type Parameters using Python Script

Hi everyone!
Does anybody have an idea on how to get Type Parameters using Python Script. I don’t have any trouble getting instance parameters, but for Type Parameters I only get empty lists.
I have a list of elements in the input and then iterate over them unwraping the elements so that I can use the GetParameters or LookupParameters method. What is missing?
Thank You!

I don’t know anything about Python, but in Dyanmo you need to get the Element from the element, I mean, Get the Type of the element before reading the type parameters… I supose python should not be that different

I’ve tried to use GetType method and then iterate over the types, applying both GetParameters and LookupParameters methods but only get this Error Message: “AttributeError: ‘RuntimeType’ object has no attribute 'GetParameters”

again, I have no idea of python yet, but have you tried “t.GetParameter” (without the final “s”)?

There is no “GetParamater” method in the RevitAPI. Anyways, thank you for taking your time in answering me and trying to help :slight_smile:

EDIT: Added conditionals to account for null values

Hi David, try something like this:

import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

elementos = UnwrapElement(IN[0])
descripciones = []

for elemento in elementos:
    # Get ElementId of ElementType
    tipo_id = elemento.GetTypeId()
    # Get actual Element from Document
    tipo = doc.GetElement(tipo_id)
    if tipo:
        parametro = tipo.LookupParameter('Description')
        if parametro:
            descripcion = parametro.AsString()
            descripciones.append(descripcion)
    else:
        descripciones.append('')

OUT = descripciones
4 Likes

@cgartland
I tried your code but I don’t know why it returns this Error Message: “AttributeError: ‘NoneType’ object has no attribute 'LookupParameter”.
I don’t know if it has something to do with the fact that the list in IN[0] is a list of elements retrieved from a linked model.

This will get the Type Parameter Width from a Wall:

WallType = UnwrapElement(IN[0])

WidthWall = UnitUtils.ConvertFromInternalUnits(WallType.get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM).AsDouble(), unit)

@Nico_Stegeman
I think “Description” is a string parameter which has no BuiltInParameter Enumeration :confused:

Hello,
you need get the document of the linkinstance

import clr

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


linkinstance = UnwrapElement(IN[0])
doclink = linkinstance.GetLinkDocument()
elementos = FilteredElementCollector(doclink).OfCategory(BuiltInCategory.OST_Roofs).WhereElementIsNotElementType().ToElements()


descripciones = []

for elemento in elementos:
    # Get ElementId of ElementType
    tipo_id = elemento.GetTypeId()
    # Get actual Element from Document
    tipo = doclink.GetElement(tipo_id)
    descripcion = tipo.LookupParameter('Description')
    descripciones.append(descripcion.AsString())

OUT = descripciones

for information GetType() is a dotnet method not a RevitAPI method

4 Likes

@c.poupin
That’s very helpful. Also I’ve managed to freely change the category of the elements.
Now the issue is that I actually have several link instances as you can see in the image.
How do you iterate over the list of links relating them with the list of elements extracted from the links? :open_mouth:

@DavidMena try this

import clr

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

import System
from System.Collections.Generic import *


linkRvt = UnwrapElement(IN[0])
category = UnwrapElement(IN[1])

bip = System.Enum.ToObject(BuiltInCategory, category.Id.IntegerValue)

if not hasattr(linkRvt, '__iter__'):
	linkRvt = [linkRvt]


descripciones = []
for link in linkRvt:
	if not "ifc" in link.Name:
		doclink = link.GetLinkDocument()
		elementos = FilteredElementCollector(doclink).OfCategoryId(category.Id).WhereElementIsNotElementType().ToElements()
		#or 
		elementos = FilteredElementCollector(doclink).OfCategory(bip).WhereElementIsNotElementType().ToElements()
		
		for elem in elementos:
			elemType = doclink.GetElement(elem.GetTypeId())
			descripcion = elemType.get_Parameter(BuiltInParameter.ALL_MODEL_DESCRIPTION)
			descripciones.append(descripcion.AsString())    

OUT = descripciones

6 Likes

@c.poupin
Excellent! It worked absolutely great. I made some modifications to your code in order to obtain a parameter that is Shared Parameter instead of BuiltIn Parameter. But it gave me a starting point and a lot of light about this ‘extraction of parameters inside links’ issue.
Again, Thank You guys!

1 Like

Hi @c.poupin, I have similar set of codes with different functionality which is returning null list. Could you please have a look.

import System
import sys
import clr

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
from System.Collections.Generic import *

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import Transaction

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('DSCoreNodes')
from DSCore import *

# Get doc, uiapp and app
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# input .rfa file paths
RFAfilepaths = UnwrapElement(IN[0])
# Input .sat file paths
SATfilepaths = UnwrapElement(IN[1])
SATfilepaths_name = [i[:-4] for i in SATfilepaths]

# SAT Import options
SAT_IOption = SATImportOptions()
SAT_IOption.VisibleLayersOnly = True
SAT_IOption.Placement = ImportPlacement.Origin
SAT_IOption.ColorMode = ImportColorMode.Preserved
SAT_IOption.Unit = ImportUnit.Default
# Save as options
Save_Option = SaveAsOptions()
Save_Option.OverwriteExistingFile = True
Save_Option.Compact = True
Save_Option.MaximumBackups = 1

TransactionManager.Instance.ForceCloseTransaction()

# list of updated .rfa files
updated = []

for RFAfilepath in RFAfilepaths:
	RFAfilepath_name = RFAfilepath[:-4]
	if RFAfilepath_name in SATfilepaths_name:
		# Find corresponding SAT filepath
		SATfilepath = SATfilepaths[SATfilepaths_name.index(RFAfilepath_name)]

		# Open .rfa file
		RFAopen = app.OpenDocumentFile(RFAfilepath)

		# Start transaction
		trans = Transaction(RFAopen, RFAfilepath_name)
		trans.Start()

		# Get all elements from open .rfa document
		collector = FilteredElementCollector(RFAopen)

		# delete existing elements
		allElements = collector.OfCategory(BuiltInCategory.OST_GenericModel).ToElements()
		for i in allElements:
			RFAopen.Delete(i.Id)

		# Import .sat file
		#RFAopen.Import(SATfilepath, SAT_IOption, view)
		shapeImporter = ShapeImporter()
		shapeImporter.InputFormat = ShapeImporterSourceFormat.SAT
		shapes = shapeImporter.Convert(RFAopen, SATfilepath)
		dsImportedSat = DirectShape.CreateElement(RFAopen, ElementId(BuiltInCategory.OST_GenericModel))
		dsImportedSat.SetShape(shapes)

		# Commit transaction changes
		trans.Commit()
		trans.Dispose()

		# Save .rfa file
		RFAopen.SaveAs(RFAfilepath, Save_Option)
		RFAopen.Close(False)
		updated.append(RFAfilepath)

#Save resulting Revit file to the destination path:
OUT = updated;

Start a new topic, this code is not the same.

2 Likes