Thursday 19 July 2012

Using Forms in an Add-in

I decided to create a command that would allow me to walk through the worksets within a project, the idea being that a form can show a list of the worksets in the active document then as you pick one of them it will turn off the display of all other worksets in the active view. This will allow you to check quickly if objects are on the wrong workset, for example if you select Shared Levels and Grids and you can see walls in the view, then you have a problem!

I created my form with a listview box as you can see to the right, however I came across a problem when trying to access the Application within the code.

So far I have used the following to reference the application:

Public Function Execute(ByVal commandData As ExternalCommandData............
        Dim uiapp As UIApplication = commandData.Application

However in the form code there is no commandData, so I had to change the definition of the uiapp to a Shared item.

Public Class AdskCommand
    Implements IExternalCommand
    Public Shared uiapp As UIApplication
    Public Function Execute(ByVal commandData As ExternalCommandData,........
    uiapp = commandData.Application

This allows me to reference the uiapp in the Execute function when the command starts and also with this code:

Private Sub lstWorkSets_Click(sender As Object, e As System.EventArgs) Handles lstWorkSets.Click
    Dim uidoc As UIDocument = AdskCommand.uiapp.ActiveUIDocument

So this refers back to the Public Shared uiapp.
Notice that I have none of the correct terminology for what I am describing, I am hoping this will come with time and practise!
Here is a video of what I managed to make, a form that controls the visibility of the current Worksets in a project:

5 comments:

  1. Thank you Sir, you're iDeas are excellent. i am learning Revit API, being a beginner your tutorials are Excellent.

    ReplyDelete
  2. Is this Application .ddl is available for download.

    ReplyDelete
  3. Hi, Nice description about Revit API vb.Net.Thanks, its really helped me......

    -Aparna
    Theosoft

    ReplyDelete
  4. me too i really like it... and going through step by step.... i hope you keep posting on your blog :)

    -Moustafa
    GAJ

    ReplyDelete