Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1 REPLY 1
Reply
Message 1 of 2
Anonymous
492 Views, 1 Reply

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

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

 

1 REPLY 1
Message 2 of 2
raunoveb
in reply to: Anonymous

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).

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community