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
2 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

2 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

2 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!