PDA

View Full Version : Elements by Category



fwp
2006-12-23, 02:52 AM
All,

Is it possible to pull all elements belonging to a category, say rooms? Iterating all elements is too slow. Thanks

Frank

GuyR
2006-12-24, 12:46 AM
No, why is it too slow? Scales reasonably well with big projects ==fast hardware. You can multi-thread the walking the tree as long as you don't try and write anything. Also depending how you are walking the tree will see >50%reductions in speed.

Post how you're doing the walking the elements for comment.

Guy

fwp
2006-12-24, 04:17 AM
Thanks, the code uses an IEnumerator to walk the elements. I use the code to add the room elements to a Hashtable. The loop takes about 90 seconds to run. Hardware is not an issue. Here's the code: (sorry, not sure how to post code correctly)

Do While (Iter.MoveNext())
Dim objElement As Autodesk.Revit.Element = Iter.Current

If Not (TypeOf objElement Is Autodesk.Revit.Symbol) Then
Dim objcategory As Autodesk.Revit.Category = objElement.Category


If Not objcategory Is Nothing Then
' Me.TB_Type.Text = objcategory.Name
If objcategory.Name = "Project Information" Then
' Read the Revit project number as the building number
project = objElement.Parameter(Parameters.BuiltInParameter.PROJECT_NUMBER).AsString
Me.TB_REVIT_BLDGNUM.Text = project
' Get the building name from UF-STARS and update the Revit Param
' Me.TB_Revit_Bldg_Name.Text = GetProjectFromDB(project)
Dim bnameParm As Autodesk.Revit.Parameter = objElement.Parameter(Parameters.BuiltInParameter.PROJECT_NAME)
bnameParm.Set(Me.TB_Revit_Bldg_Name.Text)
' Exit the loop as we have the building info
' Exit Do
ElseIf objcategory.Name = "Rooms" Then
Try
RoomHash.Add(objElement.Parameter(Parameters.BuiltInParameter.ROOM_NUMBER).AsString, Iter.Current)
Catch ex As Exception
MsgBox(objElement.Parameter(Parameters.BuiltInParameter.ROOM_NUMBER).AsString & " already in hash")
End Try
End If
End If
End If
Loop