anthonyf
2008-04-15, 09:16 AM
Hi,
Does anyone have an example, or can someone point me in the right direction?
I'm trying to find a detail components file name, I can get the type but the file name eludes me, my code below
Public Function Execute(ByVal CommandData As ExternalCommandData, ByRef message As String, ByVal elements As Autodesk.Revit.ElementSet) As Autodesk.Revit.IExternalCommand.Result Implements Autodesk.Revit.IExternalCommand.Execute
Try
Dim app As Autodesk.Revit.Application = CommandData.Application
'get the elements selected
' The current selection can be retrieved from the active
' document via the selection object
Dim seletion As SelElementSet = app.ActiveDocument.Selection.Elements
' check that the user has selected some elements
If seletion.Size >= 1 Then
Dim ElementIter As IEnumerator 'iterator for the element set
ElementIter = CommandData.Application.ActiveDocument.Selection.Elements.ForwardIterator
'Loop through the elements
Do While ElementIter.MoveNext
'Get the current element in the iterator
Dim objElement As Autodesk.Revit.Element = ElementIter.Current
'Text is not a Type (symbol), so filter those out
If Not (TypeOf objElement Is Autodesk.Revit.Symbol) Then
'Check the element's category
Dim Category As Autodesk.Revit.Category = objElement.Category
If Not (Category Is Nothing) Then
If Category.Name = "Detail Items" Then
'Display selected item name
MsgBox(objElement.Name)
End If
End If
End If
Loop
End If
Catch ex As Exception
'return a failed result and show the user the error
message = ex.Message
Return IExternalCommand.Result.Failed
End Try
End Function
Does anyone have an example, or can someone point me in the right direction?
I'm trying to find a detail components file name, I can get the type but the file name eludes me, my code below
Public Function Execute(ByVal CommandData As ExternalCommandData, ByRef message As String, ByVal elements As Autodesk.Revit.ElementSet) As Autodesk.Revit.IExternalCommand.Result Implements Autodesk.Revit.IExternalCommand.Execute
Try
Dim app As Autodesk.Revit.Application = CommandData.Application
'get the elements selected
' The current selection can be retrieved from the active
' document via the selection object
Dim seletion As SelElementSet = app.ActiveDocument.Selection.Elements
' check that the user has selected some elements
If seletion.Size >= 1 Then
Dim ElementIter As IEnumerator 'iterator for the element set
ElementIter = CommandData.Application.ActiveDocument.Selection.Elements.ForwardIterator
'Loop through the elements
Do While ElementIter.MoveNext
'Get the current element in the iterator
Dim objElement As Autodesk.Revit.Element = ElementIter.Current
'Text is not a Type (symbol), so filter those out
If Not (TypeOf objElement Is Autodesk.Revit.Symbol) Then
'Check the element's category
Dim Category As Autodesk.Revit.Category = objElement.Category
If Not (Category Is Nothing) Then
If Category.Name = "Detail Items" Then
'Display selected item name
MsgBox(objElement.Name)
End If
End If
End If
Loop
End If
Catch ex As Exception
'return a failed result and show the user the error
message = ex.Message
Return IExternalCommand.Result.Failed
End Try
End Function