Categories of families

Please send a link to the categories of families. how to access them programmatically, for example I need cable trays.

Check that out. You have an example here for walls


and you will find the enumeration of builtin categories here
https://apidocs.co/apps/revit/2022/ba1c5b30-242f-5fdc-8ea9-ec3b61e6e722.htm

Hi,
Categories are accessed from Autodesk.Revit.DB.BuiltInCategory.<enumeration>, see the list of enumerations here.

See this small example for reference. It will look for all the cable trays in your model and will prints if its a channel or a ladder:

from Autodesk.Revit import DB

doc = __revit__.ActiveUIDocument.Document

cable_tray_collector = DB.FilteredElementCollector(doc)\
                   .OfCategory(DB.BuiltInCategory.OST_CableTray)\
                   .WhereElementIsNotElementType()

for tray in cable_tray_collector:
	print(tray.GetShapeType())

how to take a value from a given parameter?

while it comes out like this.
image

I’m not exactly sure that I understand what you mean, my guess is you want to search your parameter by name. If so you can use LookupParameter("<parameter name>")
See if you can get some useful information from this:

from Autodesk.Revit import DB

doc = __revit__.ActiveUIDocument.Document

cable_tray_collector = DB.FilteredElementCollector(doc)\
                   .OfCategory(DB.BuiltInCategory.OST_CableTray)\
                   .WhereElementIsNotElementType()

for tray in cable_tray_collector:
	length=tray.LookupParameter("Length").AsValueString()
	id=tray.Id
	print("Cable Tray {}: Length = {} mm".format(id,length))

Just note that if you are using Russian, the parameter name should also be in Russian when using LookupParameter

1 Like

your code seems fine except the .format(total_lenghth) in lieu of .format(total_volume) line 24

Hi.Jean-Marc,what could be the reason for the incorrect length of the tray?

unit types
check the units
revit is in imperial internally
@Andrey-SPGR

check the raw data with revitlookup

I have installed ReitLookUp .
It turns out in the properties one number, and in the revitlookup


another

Hi @Andrey-SPGR ,

try my code:

from pyrevit import revit, DB

doc = revit.doc

cable_tray_collector = DB.FilteredElementCollector(doc)\

                   .OfCategory(DB.BuiltInCategory.OST_CableTray)\

                   .WhereElementIsNotElementType()

for tray in cable_tray_collector:

    length=tray.get_Parameter(DB.BuiltInParameter.CURVE_ELEM_LENGTH).AsValueString()

    id=tray.Id

    print("Cable Tray {}: Length = {} mm".format(id,length))
  • i’d rather import pyrevit modules, personal preference here.
  • not use LookupParameter as it is a snake’s pit whenever you don’t use revit in ENU (English US)
  • revit doc with pyrevit can be grabbed by revit.doc
  • what you were looking at in RevitLookup tool seemed wrong (but I might be wrong)


it turns out to output the length separately. how now to get the total for the selected items?

@Andrey-SPGR

quick and dirty like so

from pyrevit import revit, DB

doc = revit.doc

cable_tray_collector = DB.FilteredElementCollector(doc)\

                   .OfCategory(DB.BuiltInCategory.OST_CableTray)\

                   .WhereElementIsNotElementType()

total_length = 0

for tray in cable_tray_collector:

    length=tray.get_Parameter(DB.BuiltInParameter.CURVE_ELEM_LENGTH).AsValueString()

    id=tray.Id

    total_length = total_length + length

    print("Cable Tray {}: Length = {} mm".format(id,length))


print("Total length for Cable Trays : {} mm".format(id,total_length))
    

but simpler: use the sum total builtin tool in pyrevit :slight_smile:

Jean-Marc, sorry for the importunity, but I get an error. :weary:

from pyrevit import revit, DB

doc = revit.doc

cable_tray_collector = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_CableTray).WhereElementIsNotElementType()

total_length = 0

for tray in cable_tray_collector:

    length=tray.get_Parameter(DB.BuiltInParameter.CURVE_ELEM_LENGTH).AsValueString()

    id=tray.Id

    total_length = total_length + length

    print("Cable Tray {}: Length = {} mm".format(id,length))

print("Total length for Cable Trays : {} mm".format(total_length))

code formatting in discourse… I did fix a small typo too

I get an empty window

from pyrevit import revit, DB

doc = revit.doc

cable_tray_collector = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_CableTray).WhereElementIsNotElementType()

total_length = 0

for tray in cable_tray_collector:

    length=tray.get_Parameter(DB.BuiltInParameter.CURVE_ELEM_LENGTH).AsValueString()

    id=tray.Id

    total_length = total_length + int(length) # forgot to convert to int earlier

    print("Cable Tray {}: Length = {} mm".format(id,length))

print("Total length for Cable Trays : {} mm".format(total_length))

1 Like

thanks, Jean-Marc, it works. and how to output the trays selected by the frame, for example, if I select 2 trays?

Please close this topic and start a new one. Let’s not mix topics