See the top rated post in this thread. Click here

Page 1 of 5 12345 LastLast
Results 1 to 10 of 45

Thread: API Project - Count Selected Elements

  1. #1
    Revit Forum Manager Steve_Stafford's Avatar
    Join Date
    2001-12
    Location
    Irvine, CA
    Posts
    7,567
    Login to Give a bone
    0

    Default API Project - Count Selected Elements

    Is anyone interested in creating a routine to count the elements that are selected? Has anyone already made one? Should be doable, yes?

  2. #2
    100 Club dtownsend's Avatar
    Join Date
    2006-06
    Location
    Atlanta, GA
    Posts
    163
    Login to Give a bone
    0

    Default Re: API Project - Count Selected Elements

    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.ExternalCommandDataByRef message As StringByVal 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 " " elements.")

    ' finish up.

    Return IExternalCommand.Result.Succeeded



    Catch ex As Exception

    message = ex.Message

    Return IExternalCommand.Result.Failed

    End Try

    End Function

     

     

    End Class 

  3. #3
    AUGI Addict
    Join Date
    2003-11
    Location
    New Zealand
    Posts
    1,116
    Login to Give a bone
    0

    Default Re: API Project - Count Selected Elements

    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

  4. #4
    100 Club dtownsend's Avatar
    Join Date
    2006-06
    Location
    Atlanta, GA
    Posts
    163
    Login to Give a bone
    0

    Default Re: API Project - Count Selected Elements

    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...
    PHP Code:
    Public Class Command
    Implements IExternalCommand

    Public Function Execute(ByVal commandData As Autodesk.Revit.ExternalCommandDataByRef message As StringByVal 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 
    or even this if you are using the selection set for more than just couting

    PHP Code:
    Public Class Command

    Implements IExternalCommand

    Public Function Execute(ByVal commandData As Autodesk.Revit.ExternalCommandDataByRef message As StringByVal 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 

  5. #5
    AUGI Addict
    Join Date
    2003-11
    Location
    New Zealand
    Posts
    1,116
    Login to Give a bone
    1

    Default Re: API Project - Count Selected Elements

    Quote Originally Posted by Steve_Stafford
    Has anyone already made one?
    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.

    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
    Attached Files Attached Files

  6. #6
    Revit Forum Manager Steve_Stafford's Avatar
    Join Date
    2001-12
    Location
    Irvine, CA
    Posts
    7,567
    Login to Give a bone
    0

    Default Re: API Project - Count Selected Elements

    Hey thanks Guy! I'll check er out! Cheers!

  7. #7
    Aussie Revit Moderator Mr Spot's Avatar
    Join Date
    2004-05
    Location
    Brisbane
    Posts
    1,115
    Login to Give a bone
    0

    Default Re: API Project - Count Selected Elements

    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?
    Chris Price
    Co-Founder/BIM Manager/Product Designer
    Xrev Pty Ltd

    Revit Rants BLOG

  8. #8
    AUGI Addict
    Join Date
    2003-11
    Location
    New Zealand
    Posts
    1,116
    Login to Give a bone
    0

    Default Re: API Project - Count Selected Elements

    Quote Originally Posted by Mr Spot
    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.

    Guy

  9. #9
    Revit Forum Manager Steve_Stafford's Avatar
    Join Date
    2001-12
    Location
    Irvine, CA
    Posts
    7,567
    Login to Give a bone
    0

    Default Re: API Project - Count Selected Elements

    Quote Originally Posted by GuyR
    ...Which should be fine for Steve.... Will look at it if there are a few metric heads who would find this useful...
    umm...I like Metric too and work in it quite often.

  10. #10
    AUGI Addict
    Join Date
    2003-11
    Location
    New Zealand
    Posts
    1,116
    Login to Give a bone
    2

    Default Re: API Project - Count Selected Elements

    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
    Attached Images Attached Images
    Attached Files Attached Files

Page 1 of 5 12345 LastLast

Similar Threads

  1. Print Count when multiple sheets selected
    By Wish List System in forum Revit Architecture - Wish List
    Replies: 1
    Last Post: 2015-03-06, 12:38 PM
  2. Print Count when multiple sheets selected
    By Wish List System in forum Revit Architecture - Wish List
    Replies: 1
    Last Post: 2014-12-11, 08:49 PM
  3. Count Nested Elements
    By JotaG in forum Revit Architecture - Families
    Replies: 6
    Last Post: 2010-08-31, 08:52 AM
  4. [2010] Keep Elements Selected (OPEN)
    By mwiggins121466 in forum Revit MEP - Wish List
    Replies: 1
    Last Post: 2009-06-26, 10:27 PM
  5. Filter selected elements?
    By Elizabeth Shulok in forum Revit - API
    Replies: 12
    Last Post: 2008-06-09, 11:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •