Plugin Auto Start When Revit Is Opened

Plugin Auto Start When Revit Is Opened

oguzkomcu
Enthusiast Enthusiast
681 Views
6 Replies
Message 1 of 7

Plugin Auto Start When Revit Is Opened

oguzkomcu
Enthusiast
Enthusiast

I have an application that I developed myself. Actually in this application I am trying to convert rvt file to svf or gltf file format. In line with the request for this, I want the desired rvt file to be opened and the ExportGltf plugin to start automatically and complete the export process. How can I do that ?

0 Likes
682 Views
6 Replies
Replies (6)
Message 2 of 7

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @oguzkomcu ,

 

Please take a look at the below code

class App : IExternalApplication
    {
        public static UIControlledApplication uiControlledApp = null;
        public static UIDocument uidoc = null;
        public static Document doc = null;
        public Result OnStartup(UIControlledApplication application)
        {
            uiControlledApp = application;
            uiControlledApp.Idling += onIdling;
            return Result.Succeeded;
        }

        private void onIdling(object sender, IdlingEventArgs e)
        {
            
            UIApplication uiapp = sender as UIApplication;
            {                
                uiapp.OpenAndActivateDocument(@"C:\Program Files\Autodesk\Revit 2023\Samples\rst_basic_sample_project.rvt");
                /*
                 * 
                 * Code to export Revit to gltf
                 * 
                 */
            }
            uiControlledApp.Idling -= onIdling;
        }

        public Result OnShutdown(UIControlledApplication application)
        {
            
            return Result.Succeeded;
        }
    }

Also, I found the below link

https://github.com/weiyu666/RevitExportObjAndGltf 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 7

oguzkomcu
Enthusiast
Enthusiast

1- There is no addin file in this github repo. Do I create the addin file? Or is there a different method?

2- I am very new to developing Revit Api. I've been dealing with this for weeks. How exactly do I need to process the gltf code there? Is there a sample code?

0 Likes
Message 4 of 7

jonathan.taVCBM2
Enthusiast
Enthusiast

Hi , 

Have a look at this part of the guide , you can find it in the link here 

 

Developers add functionality by creating and implementing External Commands and External Applications. Revit identifies the new commands and applications using .addin manifest files.

  • External Commands appear under the External Tools menu-button on the Add-Ins tab.
  • External Applications are invoked when Revit starts up and unloaded when Revit shuts down

 

Jonathan Talisman
BIM Developer
0 Likes
Message 5 of 7

oguzkomcu
Enthusiast
Enthusiast
Hello good day. Even though I gave the correct namespaces of the classes and they are marked in green, I get a reference error, is it because of the revit version? Or is there another reason?

Error : The type or namespace name 'UIControlledApplication' could not be found (are you missing a using directive or an assembly reference?)
0 Likes
Message 6 of 7

jonathan.taVCBM2
Enthusiast
Enthusiast

Hi @oguzkomcu ,

It's really hard to tell with no code sample, screen shots or anything of that sort.
Are you trying to run the code that @naveen.kumar.t  posted ? I am guessing you are missing some using statement. 

Jonathan

Jonathan Talisman
BIM Developer
0 Likes
Message 7 of 7

oguzkomcu
Enthusiast
Enthusiast

image.png

As you can see, I'm not actually missing a using statement. When I searched the internet for this problem, I saw that it was related to the .Net Freamwork version. When I upgraded my class library to 4.8, the errors went away. I then ran revit but got this error.
Error : System.TypeLoadException Could not load type ' RevitGltfDeneme3.App ' from assembly ' RevitGltfDeneme3 , Version 1.0.0.0 , Culture = neutral , PubliKeyToken = null " .

0 Likes