Get Parameter via python?

Hello,

How can i see my Parameter Names?:

elements = UnwrapElement(myDoors)

test = []

for i in elements:
    for j in i.Parameters:
	    test.append(j)
OUT = test

and how do i call a specific one like “Comments” and his values?

:)KR

Andreas

https://www.revitapidocs.com/2020/ce77c924-9e80-7668-cce8-c3be02b1d254.htm

You have to get the Definition and then get the Name

elements = UnwrapElement(myDoors)

test = []

for element in elements:
    for parameter in element.Parameters:
        parameterName = parameter.Definition.Name
            test.append(parameterName)
   OUT = test    

And if you want a specific one, do it like this:

elements = UnwrapElement(myDoors)

test = []

for element in elements:
    parameter = element.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
    test.append(parameter)
   OUT = test

How’s the second example work? I just tried it and got

image

i got the same issue

Yes that is the Parameter API object for the Parameter “Comments”.

from there you can get the name of the parameter → “Comments” or the Value of the parameter of the storage type. If you want the name, follow my first example:

Get the name via Parameter → Definition → Name

name = parameter.Definition.Name

2021-01-28_16h23_31
no it worked


for getting this parameter i can index it or call? asString, toString

for element in elements:
for parameter in element.Parameters:
	parameterName = parameter.Definition.Name
	test.append(parameterName.AsString())

for element in elements:
    parameter = element.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
    test1.append(parameter.AsString())

the reason is i also want call the values from the parameter “comments”! so the output should be strings

The AsString() methode behind the parameterName is a bit unnessecery since ParameterName is already a string

^This is the right way to get the value for the Comments parameter via the api


one pice of puzzle more !

Hello,

I made this zip-loop - it works well! i want to make dictionary that keys and values match.
And when they the symbols got placed.

for i in zip(Types,sym):
    dic.append(i)

Can i say in the for-loop alredy which is Key and Value?

{ Key : Value, "Type" : "Comment", DetailComponent : Door}
if Comment "Gelb":
  place.Symbol"Gelb" to centerpoint of coresponding door

Thats the “psychoCode”


hmmmm

KR

Andreas

Easiest way would be to first create a dictionary with only keys:

types = ["Gelb","Blau","Rot"]
dictionary = dict()
for color in types:
    dictionary.add(color, [])

This will give you an dictionary with Blau, Gelb, Rot

The loop thru your elements with comments:

for element in elements:
    parameter = get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
    value = parameter.AsString()
    if dictionary.Keys.Contains(value):
        dictionary[value].append(element)

This will give you a dictionary with the elements sorted in yellow, red and blue

full code:

types = ["Gelb","Blau","Rot"]
dictionary = dict()
for color in types:
    dictionary.add(color, [])

for element in elements:
    parameter = get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
    value = parameter.AsString()
    if dictionary.Keys.Contains(value):
        dictionary[value].append(element)

need i any special library?
2021-02-01_15h58_34
how do i difine “add”?2021-02-01_15h59_34

add has to be Add (didn’t test the code before hand, just typing it off the top of my head)

But you need to import the dictionary from the System.Collections.Generic
After you can use “Add()”
I always use:

from "namespace" import * #to import everything in the namespace 

2021-02-02_12h39_25

it still says i have an index error?

import sys
import clr

from "namespace" import *

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

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



doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

TransactionManager.Instance.EnsureInTransaction(doc)

types = ["Blau","Gelb","Rot"]
myDoors = FilteredElementCollector(doc).

OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType().ToElements()
Symbl = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_DetailComponents).WhereElementIsElementType().ToElements()

elements = UnwrapElement(myDoors)
points =[]
test = []
dic = dict()
	
for element in elements:
parameter = element.get_Parameter

(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
test.append(parameter.AsString())

for color in types:
dic.add(color, [])

for element in elements:
    parameter = get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
    value = parameter.AsString()
if dic.Keys.Contains(value):
    dic[value].append(element)


for e in elements:
bb = e.get_BoundingBox(None)
	if not bb is None:
    	centre = bb.Min+(bb.Max-bb.Min)/2
    	points.append(centre.ToPoint())

for s in Symbl:
try:
	if types.Contains(s.Family.Name):
		output.append(s)
except:
	pass
	
TransactionManager.Instance.TransactionTaskDone()

OUT = test,dic

#Get Location points

He means `“namespace” as an infill :slight_smile:

Just use
from System.Collections.Generic import *
and make sure you use Add() in stead of add().

is there any redundency?.. i think my libraries still not conform
2021-02-02_14h18_05


i got “new Errors!”

hello

  • there is an indentation problem at lines 60, 61, 62
  • element.get_Parameter(…) at line 52

Note:
avoid try… except:pass (unless you have no other solution)

As far as I know its GetParameterValue?
ElementID is the BuiltIn enum that was previously mentioned

Please read through some of the API. Also a quick search on the docs never hurt.

i use this coment severial times, it works fine!

when i delete my Dic-block. all workes fine

The 3rd for loop you are calling get_Parameter without element.
Make sure it says element.get_Parameter.


these are my pices right now.

one piece in python would be get view f.e. floor one

how can i get this together in the dictionary? In the dictionary there is still an errortest.dyn (5.6 KB)

KR

AndreasProjekt_.rvt (1.2 MB)