MEP datas

Hi, with this code i can extract all Lights, but how can i extract id or others parameters of Datas ?

Daniel OLIVES

Version:0.9 StartHTML:00000097 EndHTML:00004985 StartFragment:00000199 EndFragment:00004947 #Import libraries
import clr
clr.AddReference(“ProtoGeometry”)
from Autodesk.DesignScript.Geometry import *

Import RevitAPI

clr.AddReference(“RevitAPI”)
from Autodesk.Revit.DB import *
clr.AddReference(“RevitAPIUI”)
from Autodesk.Revit.UI import TaskDialog

Import DocumentManager and TransactionManager

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

Import ToProtoType, ToRevitType geometry conversion extension methods

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
from Autodesk.Revit.DB.Events import *
from Autodesk.Revit.DB.Architecture import *
from Autodesk.Revit.DB.Structure import *
from Autodesk.Revit.DB.Mechanical import *
from Autodesk.Revit.DB.Electrical import *
from Autodesk.Revit.DB.Plumbing import *

Access the the Revit Document/Application

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

Select Elements

#walls = FilteredElementCollector(doc).OfClass(Wall).WhereElementIsNotElementType().ToElements()
#walls = FilteredElementCollector(doc).OfClass(Wall).ToElements()
#walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Furniture).WhereElementIsNotElementType().ToElements()
Datas = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_LightingFixtures).WhereElementIsNotElementType().ToElements()

OUT = Datas, dir(Datas[0])
#Return the Data and the methods that can be used

Hi Daniel, here is a simplified version of your code which achieves essentially the same result:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

# Collect all Lighting Fixtures in current document
elements = FilteredElementCollector(doc)\
    .OfCategory(BuiltInCategory.OST_LightingFixtures)\
    .WhereElementIsNotElementType()

# Access ElementId (Id property) of each Element    
ids = [e.Id for e in elements]
# Get 'Mark' Parameter for each Element
parameters = [e.LookupParameter('Mark') for e in elements]

OUT = elements, ids, parameters

Most of the imported libraries and namespaces aren’t being referenced (ProtoGeometry, Events, Mechanical, Electrical, Plumbing), so I’ve removed them in order to show only what is necessary. Currently, only elements from the Lighting Fixtures category are being collected, but this can be changed by replacing BuiltInCategory.OST_LightingFixtures with another member of the BuiltInCategory Enumeration, e.g. OST_ElectricalEquipment.

Currently, this script only outputs the actual Parameter object, so you will need to use the appropriate method (AsString(), AsValueString(), AsElementId(), AsInteger(), AsDouble()) to get its value. The proper method can typically be determined by looking at the Parameter’s StorageType property.

Hi, Thank you very much, it’s my first python code, you help me.
I can continue to work.
Daniel OLIVES
French user

revitapidocs.com is your friend.

Hi, just a litle question how can i read type name and parameters of type ?
Daniel OLIVES

Hi modify the code for get name and Type name,

"# Access Element Name (Name property) of each Element
name = [e.Name for e in elements]

"# Access Element Id (Id property) of each Element
ids = [e.Id for e in elements]

"# Access Element Type(Id property) of each Element
type = [e.Document.GetElement(e.GetTypeId()) for e in elements]

But in Type i obtain 3 values:

Family Type: 2400mm - 277V, Family: ‘family name’ id

Is it possible to obtain only theType = “2400mm - 277V”

And second point:
All my parameters ‘Mark’ are null value, if i modify Mark by ‘“Numéro de circuit”’ = I have also ‘null’ value
Daniel OLIVES

@daniel82KGE

for type name only:
elem.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString()

for Mark:
elem.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).AsString()

for any others:
https://www.revitapidocs.com/2019/fb011c91-be7e-f737-28c7-3f1e1917a0e0.htm

Hi, Thank’s i read one more time the answer and link and now i undestand
Daniel OLIVES
(French “senior” user)

Hi,
I try:

type = [e.Document.GetElement(e.GetTypeId()).LookupParameter(“Type Name”) for e in elements]

But i have only Null value

(REVIT 2020)
Daniel OLIVES

Hi, yesterday i search some help for REVIT Python and Dynamo.
I have install IronPython, very goog API to debug Python, with rps_init.py from gtalarico i can easely
list all methods usable.
And RevitLookup i can now be sure that all my syntax are correct.

The correct line code is:
type_names = [e.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString for e in elements]
Daniel OLIVES

Hi, here is the last code with all case.

Blockquote
#Import libraries
import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import * #FilteredElementCollector, BuiltInCategory
clr.AddReference(‘RevitServices’)
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

Collect all Lighting Fixtures in current document

elements = FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_LightingFixtures)
.WhereElementIsNotElementType()

Access Element Type(Id property) of each Element Family Type: and Family: and Id

#only for test
stype = [e.Document.GetElement(e.GetTypeId()) for e in elements]

Access Element type name = ‘600x600 - 277’

Type_NameL =
for e in elements:
Type_Name = e.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString()
Type_NameL.append(Type_Name)

Access Element Family name = ‘M_Pendant Light - Linear - 2 Lamp’

Family_NameL = [e.LookupParameter(‘Famille’).AsValueString() for e in elements]

Access Element Name (Name property) of each Element

name = [e.Name for e in elements]

Access Element Id (Id property) of each Element

ids = [e.Id for e in elements]

Access Element parameters ‘Commentaires’

parameters = [e.LookupParameter(‘Commentaires’).AsString() for e in elements]

OUT = Family_NameL, Type_NameL, name, ids, parameters

< Blockquote

Hi Daniel, rather than using a blockquote, you can use the “preformatted text” option so that your code appears correctly:

image

#Import libraries
import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import * #FilteredElementCollector, BuiltInCategory
clr.AddReference(‘RevitServices’)
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

# Collect all Lighting Fixtures in current document

elements = FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_LightingFixtures)
.WhereElementIsNotElementType()

# Access Element Type(Id property) of each Element Family Type: and Family: and Id

#only for test
stype = [e.Document.GetElement(e.GetTypeId()) for e in elements]

# Access Element type name = ‘600x600 - 277’

Type_NameL = 
for e in elements:
Type_Name = e.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString()
Type_NameL.append(Type_Name)

# Access Element Family name = ‘M_Pendant Light - Linear - 2 Lamp’

Family_NameL = [e.LookupParameter(‘Famille’).AsValueString() for e in elements]

# Access Element Name (Name property) of each Element

name = [e.Name for e in elements]

# Access Element Id (Id property) of each Element

ids = [e.Id for e in elements]

# Access Element parameters ‘Commentaires’

parameters = [e.LookupParameter(‘Commentaires’).AsString() for e in elements]

OUT = Family_NameL, Type_NameL, name, ids, parameters