How execute a VB.NET 2012 class from a Button on my form - Revit addin

How execute a VB.NET 2012 class from a Button on my form - Revit addin

Anonymous
Not applicable
571 Views
1 Reply
Message 1 of 2

How execute a VB.NET 2012 class from a Button on my form - Revit addin

Anonymous
Not applicable

Hello everyone
I am developing a Revit addin using Vb.net 2012 I made a class to create a project (rvt) based on a template (rte). Now I need to execute or call my class from a button on my form. How I execute the class? someone has an example ?. this is my code.

 

In The Form1

 

Private Sub Btt_Crear_Click(sender As Object, e As EventArgs) Handles Btt_Crear.Click

     

  Dim plt As New PLT_ARQ

  plt.Execute()

 

End Sub

 

in the Class PLT_ARQ

 

Imports System

Imports System.IO

Imports System.Diagnostics

Imports System.Collections.Generic

Imports Autodesk.Revit.ApplicationServices

Imports Autodesk.Revit.Attributes

Imports Autodesk.Revit.DB

Imports Autodesk.Revit.UI

Imports Autodesk.Revit.UI.Selection

 

<Transaction(TransactionMode.Manual)>

Public Class PLT_ARQ

    Implements IExternalCommand

 

    Public Function Execute(

      ByVal commandData As ExternalCommandData,

      ByRef message As String,

      ByVal elements As ElementSet) _

    As Result Implements IExternalCommand.Execute

 

        Dim uiapp As UIApplication = commandData.Application

        Dim uidoc As UIDocument = uiapp.ActiveUIDocument

        Dim app As Application = uiapp.Application

 

         If form.SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

                Dim CurrentPath As String = "C:\"

                Dim TemplateFile As String = "model.rte"

                Dim templateFullPath As String = System.IO.Path.Combine(CurrentPath, TemplateFile)

                Dim newDoc As Document = app.NewProjectDocument(templateFullPath)

                Dim newFileName As String = System.IO.Path.Combine(form.SaveFileDialog1.InitialDirectory, form.SaveFileDialog1.FileName)

                newDoc.SaveAs(newFileName)

                newDoc.Close()

                uiapp.OpenAndActivateDocument(newFileName)

        End If

 

        Return Result.Succeeded

    End Function

 

End Class

 

0 Likes
572 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Hi marcosmateo!

From your original post it's unclear if you created a class that extends IExternalApplication. This is a class that is automatically/manually loaded when Revit starts up. Also in this class you define "RibbonTab"s, "RibbonPanel"s, "RibbonButton"s and assign IExternalCommand classes (like the one you created) to those buttons. A simple example can be shown in the sticky thread in Revit API subforum (MyFirstRevitPlugin).

0 Likes