Create button to execute local file with Revit api

Create button to execute local file with Revit api

Anonymous
Not applicable
824 Views
1 Reply
Message 1 of 2

Create button to execute local file with Revit api

Anonymous
Not applicable

Hey,

 

I have written a Java program which processes an exported file from Revit. I want to start this program via a button in Revit. Since I can not really use  C# I hope you can help me.

I have created a dll in Visual Studio that creates a push button in Revit and displays it (like the ADSK tutorial )

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using System.Windows.Media.Imaging;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using System.IO;
using System.Diagnostics;

[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
class MyClass : Autodesk.Revit.UI.IExternalApplication
{

    public Autodesk.Revit.UI.Result OnStartup(UIControlledApplication application)
    {
        // add new ribbon panel
        RibbonPanel ribbonPanel = application.CreateRibbonPanel("MyClass");
        //Create a push button in the ribbon panel "NewRibbonPanel"
        //the add-in application "HelloWorld" will be triggered when button is pushed
        PushButton pushButton = ribbonPanel.AddItem(new PushButtonData("MyClass",
        "MyClass", @"C:\MyClass\MySecClass.dll", "MySecClass.execMyclass")) as PushButton;
        // Set the large image shown on button
        Uri uriImage = new Uri(@"C:\MyClass\img\39_globe.png");
        BitmapImage largeImage = new BitmapImage(uriImage);
        pushButton.LargeImage = largeImage;
        return Result.Succeeded;
    }
    public Result OnShutdown(UIControlledApplication application)
    {
        return Result.Succeeded;
    }
    
}



This button is connected to another dll which I have written to execute a .bat. This .bat then starts my Java program.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;


namespace MySecClass
{
    [TransactionAttribute(TransactionMode.ReadOnly)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    public class execMyClass : IExternalCommand
    {
       static void Main(string[] args)
            {
                System.Diagnostics.Process.Start(
                 @".\src\execMyClass.bat");
            }

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            throw new NotImplementedException();
        }
    }

}



This way I had to go, because I do not know exactly how I call a method in the file of the button that says: When actuating button, execute.

Would someone please help? That would be great!

Cheers!

Steve

0 Likes
Accepted solutions (1)
825 Views
1 Reply
Reply (1)
Message 2 of 2

augusto.goncalves
Alumni
Alumni
Accepted solution
I never tried it.. but the Start should be inside the Execute:

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
System.Diagnostics.Process.Start(
@".\src\execMyClass.bat");

return Result.Succeeded;
}

And make sure all the paths are correct, or avoid the Absolute and make then Relative.
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes