Is anyone interested in creating a routine to count the elements that are selected? Has anyone already made one? Should be doable, yes?
|
Is anyone interested in creating a routine to count the elements that are selected? Has anyone already made one? Should be doable, yes?
You could try something like this...it will count the selected elements and display the number in a message box.
PHP Code:
#Region " Options"
Option Explicit On
Option Strict On
#End Region
#Region " Imports "
Imports Autodesk.Revit
Imports System.Windows.Forms
#End Region
Public Class Command
Implements IExternalCommand
Public Function Execute(ByVal commandData As Autodesk.Revit.ExternalCommandData, ByRef message As String, ByVal elements As Autodesk.Revit.ElementSet) As Autodesk.Revit.IExternalCommand.Result Implements Autodesk.Revit.IExternalCommand.Execute
Try
' Revit = Application
Dim rvtApp As Autodesk.Revit.Application = commandData.Application
' get a list of selected elements.
Dim selSet As Autodesk.Revit.ElementSet = rvtApp.ActiveDocument.Selection.Elements
' declare elements as elem
Dim elem As Autodesk.Revit.Element
' set the counter
Dim i As Integer = 0
' loop threw each selected object
For Each elem In selSet
i = i + 1
Next
' show a messagebox with the number of selected elements
MessageBox.Show("You selected " & i & " elements.")
' finish up.
Return IExternalCommand.Result.Succeeded
Catch ex As Exception
message = ex.Message
Return IExternalCommand.Result.Failed
End Try
End Function
End Class
You don't need to count the number of elements. SelElementSet has a size property, so it's as simple as :
int NumElementsSelected = commandData.Application.ActiveDocument.Selection.Elements.Size;
Guy
Good catch Guy. I was thinking about something like that at first, but I was looking for "Count" and not "Size".
So you can do something similar to this...
or even this if you are using the selection set for more than just coutingPHP Code:
Public Class Command
Implements IExternalCommand
Public Function Execute(ByVal commandData As Autodesk.Revit.ExternalCommandData, ByRef message As String, ByVal elements As Autodesk.Revit.ElementSet) As Autodesk.Revit.IExternalCommand.Result Implements Autodesk.Revit.IExternalCommand.Execute
Try
Dim NumElementsSelected As Integer = commandData.Application.ActiveDocument.Selection.Elements.Size
MessageBox.Show("You selected " & NumElementsSelected & " elements.")
Return IExternalCommand.Result.Succeeded
Catch ex As Exception
message = ex.Message
Return IExternalCommand.Result.Failed
End Try
End Function
End Class
PHP Code:
Public Class Command
Implements IExternalCommand
Public Function Execute(ByVal commandData As Autodesk.Revit.ExternalCommandData, ByRef message As String, ByVal elements As Autodesk.Revit.ElementSet) As Autodesk.Revit.IExternalCommand.Result Implements Autodesk.Revit.IExternalCommand.Execute
Try
Dim rvtApp As Autodesk.Revit.Application = commandData.Application
Dim selSet As Autodesk.Revit.ElementSet = rvtApp.ActiveDocument.Selection.Elements
Dim NumElementsSelected As Integer = selSet.Size
MessageBox.Show("You selected " & NumElementsSelected & " elements.")
Return IExternalCommand.Result.Succeeded
Catch ex As Exception
message = ex.Message
Return IExternalCommand.Result.Failed
End Try
End Function
End Class
Since no one has compiled this for you, here's a quick lunchtime hack Steve. Added area subtotals for floors,walls and roofs because I'd like element properties to do this (along with length etc). Adds toolbar and menu to Revit.Originally Posted by Steve_Stafford
Needs icon for toolbar and threading if you're selected >1000 elements.
Zip contains compiled binaries for RAC2008 and .ini text to add to your Revit.ini. Modification of path probably required and dll's must go in the same directory.
HTH,
Guy
Hey thanks Guy! I'll check er out! Cheers!
Handy little tool! I just have a question regarding the units its calculating the areas in? Is it smart enough to use the project units or is it using square feet or something?
AH!! Damn majority of the world Sorry it doesn't currently take any notice of units. So the area is the default Revit unit which is imperial and therefore decimal feet. Which should be fine for Steve.... Will look at it if there are a few metric heads who would find this useful.Originally Posted by Mr Spot
Guy
umm...I like Metric too and work in it quite often.Originally Posted by GuyR
0.6 build: Unit handling is basic. If the project is imperial then it does nothing but add the suffix, if it's metric then it converts it to metres with the appropriate suffix ,see attached image.
If you're only interested in the binaries then to upgrade you just need to replace the NumElement.dll in your chosen directory.
Guy