add-in OnStartUp

add-in OnStartUp

Anonymous
Not applicable
1,851 Views
5 Replies
Message 1 of 6

add-in OnStartUp

Anonymous
Not applicable

Hello !
I have a little problem while creating my firts plugin. In fact my OnStartUp() function seems to not working ....
But when I transfer my code to the execute() function it work !
I think the problem is from my add-in but I haven't been able to find a guide to understood how it work.
here is the code of my add-in :

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
  <AddIn Type="Command">    
    <Assembly>
      C:\Users\maxime\Documents\Visual Studio 2015\Projects\ClassLibrary3\ClassLibrary3\bin\Debug\ClassLibrary3.dll
    </Assembly>
    <ClientId>502fe383-2648-4e98-adf8-5e6047f9dc35</ClientId>
    <FullClassName>Class1</FullClassName>
    <Text>ClassLibrary3</Text>
    <VendorId>ADSK</VendorId>
    <VisibilityMode>AlwaysVisible</VisibilityMode>
  </AddIn>
</RevitAddIns>

 

And here the code of my OnStartUp function :

 

 

 

  public Result OnStartup(UIControlledApplication a)
    {
        System.Windows.Forms.MessageBox.Show("test");
        adWin.RibbonControl ribbon
          = adWin.ComponentManager.Ribbon;

        foreach (adWin.RibbonTab tab in ribbon.Tabs)
        {
            System.Windows.Forms.MessageBox.Show("test");
            if (tab.Id == "Analyse")
            {
                
                foreach (adWin.RibbonPanel panel
                  in tab.Panels)
                {
                    if (panel.Source.Id == "cea_shr")
                    {
                        adWin.RibbonButton button
                          = new adWin.RibbonButton();

                        button.Name = "TbcButtonName";
                       // button.Image = Image.FromFile("C:\\Users\\a\\Downloads\\12347734_10204048769899926_1746719051843979140_n.jpg");
                        //button.LargeImage = image;
                        button.Id = "ID_TBC_BUTTON";
                        button.AllowInStatusBar = true;
                        button.AllowInToolBar = true;
                        button.GroupLocation = Autodesk.Private
                          .Windows.RibbonItemGroupLocation.Middle;
                        button.IsEnabled = true;
                        button.IsToolTipEnabled = true;
                        button.IsVisible = true;
                        button.ShowImage = true;
                        button.ShowText = true;
                        button.ShowToolTipOnDisabled = true;
                        button.Text = "Export vues";
                        button.ToolTip = "Open The Building "
                          + "Coder blog on the Revit API";
                        button.MinHeight = 0;
                        button.MinWidth = 0;
                        button.Size = adWin.RibbonItemSize.Large;
                        button.ResizeStyle = adWin
                          .RibbonItemResizeStyles.HideText;
                        button.IsCheckable = true;
                        button.Orientation = System.Windows
                          .Controls.Orientation.Vertical;
                        button.KeyTip = "TBC";

                        adWin.ComponentManager.UIElementActivated
                          += new EventHandler<
                            adWin.UIElementActivatedEventArgs>(
                            ComponentManager_UIElementActivated);

                        panel.Source.Items.Add(button);

                        return Result.Succeeded;
                    }
                }
            }
        }
        return Result.Succeeded;
    }

 

 

0 Likes
Accepted solutions (1)
1,852 Views
5 Replies
Replies (5)
Message 2 of 6

Mustafa.Salaheldin
Collaborator
Collaborator

This is clearly obvious:

 

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
  <AddIn Type="Command">    change this line to be <AddIn Type="application">
    <Assembly>addin path</Assembly>
    <ClientId>502fe383-2648-4e98-adf8-5e6047f9dc35</ClientId>
    <FullClassName>Class1</FullClassName> add the name space before the class name <FullClassName>Namespace.Class1</FullClassName>
    <Text>ClassLibrary3</Text>
    <VendorId>ADSK</VendorId>
    <VisibilityMode>AlwaysVisible</VisibilityMode>
  </AddIn>
</RevitAddIns>

 It would be better if you submit the full could so I can help.

 

If this satisfies your need please don't forget to mark this reply as an answer.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes
Message 3 of 6

Anonymous
Not applicable

not working .... Revit didn't even find it now ....

Here is the code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using System.Reflection; // for getting the assembly path
using System.Windows.Media; // for the graphics
using System.Windows.Media.Imaging;

// use an alias because Autodesk.Revit.UI 
// uses classes which have same names:

using adWin = Autodesk.Windows;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;

namespace ClassLibrary3
{
    [TransactionAttribute(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    public class Class1 : IExternalCommand
    {
        Worker workerObject = new Worker();
        Thread workerThread;
        string resultat = "hello";
        public Result OnStartup(UIControlledApplication a)
        {
            System.Windows.Forms.MessageBox.Show("test");
            adWin.RibbonControl ribbon
              = adWin.ComponentManager.Ribbon;

            foreach (adWin.RibbonTab tab in ribbon.Tabs)
            {
                System.Windows.Forms.MessageBox.Show("test");
                if (tab.Id == "Analyse")
                {

                    foreach (adWin.RibbonPanel panel
                      in tab.Panels)
                    {
                        if (panel.Source.Id == "cea_shr")
                        {
                            adWin.RibbonButton button
                              = new adWin.RibbonButton();

                            button.Name = "TbcButtonName";
                            // button.Image = Image.FromFile("C:\\Users\\maxime\\Downloads\\12347734_10204048769899926_1746719051843979140_n.jpg");
                            //button.LargeImage = image;
                            button.Id = "ID_TBC_BUTTON";
                            button.AllowInStatusBar = true;
                            button.AllowInToolBar = true;
                            button.GroupLocation = Autodesk.Private
                              .Windows.RibbonItemGroupLocation.Middle;
                            button.IsEnabled = true;
                            button.IsToolTipEnabled = true;
                            button.IsVisible = true;
                            button.ShowImage = true;
                            button.ShowText = true;
                            button.ShowToolTipOnDisabled = true;
                            button.Text = "Export vues";
                            button.ToolTip = "Open The Building "
                              + "Coder blog on the Revit API";
                            button.MinHeight = 0;
                            button.MinWidth = 0;
                            button.Size = adWin.RibbonItemSize.Large;
                            button.ResizeStyle = adWin
                              .RibbonItemResizeStyles.HideText;
                            button.IsCheckable = true;
                            button.Orientation = System.Windows
                              .Controls.Orientation.Vertical;
                            button.KeyTip = "TBC";

                            adWin.ComponentManager.UIElementActivated
                              += new EventHandler<
                                adWin.UIElementActivatedEventArgs>(
                                ComponentManager_UIElementActivated);

                            panel.Source.Items.Add(button);

                            return Result.Succeeded;
                        }
                    }
                }
            }
            return Result.Succeeded;
        }

        void ComponentManager_UIElementActivated(
          object sender,
          adWin.UIElementActivatedEventArgs e)
        {
            if (e != null
              && e.Item != null
              && e.Item.Id != null
              && e.Item.Id == "ID_TBC_BUTTON")
            {
                // Perform the button action
                ClassLibrary3.Form2 form = new ClassLibrary3.Form2();



                if (form.ShowDialog() == DialogResult.OK)
                {

                    resultat = form.resultat;
                    workerObject.Str(resultat);
                    System.Windows.Forms.MessageBox.Show(resultat);
                }
            }
        }

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


        public Result Execute(
        ExternalCommandData commandData,
        ref string message,
        ElementSet elements)
        {


            return Result.Succeeded;
        }

When i put it in execute() it's working...

 

the new addin code :

 

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
  <AddIn Type="application">   
    <Assembly>
      C:\Users\maxime\Documents\Visual Studio 2015\Projects\ClassLibrary3\ClassLibrary3\bin\Debug\ClassLibrary3.dll
    </Assembly>
    <ClientId>502fe383-2648-4e98-adf8-5e6047f9dc35</ClientId>
    <FullClassName>ClassLibrary3.Class1</FullClassName>
    <Text>ClassLibrary3</Text>
    <VendorId>ADSK</VendorId>
    <VisibilityMode>AlwaysVisible</VisibilityMode>
  </AddIn>
</RevitAddIns>
0 Likes
Message 4 of 6

Charles.Piro
Advisor
Advisor
Accepted solution

Hi,

 

I just test this, and all it's ok for me :

 

 

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
  <AddIn Type="Application">
    <Name>Application Test_ForumRevitAPI</Name>
    <Assembly>Test_ForumRevitAPI.dll</Assembly>
    <FullClassName>Test_ForumRevitAPI.App</FullClassName>
    <AddInId>F8817612-C881-4429-8E26-6B0DE9819AC0</AddInId>
    <VendorId>CPI_</VendorId>
  </AddIn>
</RevitAddIns>

 

I just changed "Analyse" with "Analyze".

 

 

public class App : IExternalApplication
{
public Result OnStartup(UIControlledApplication application) { System.Windows.Forms.MessageBox.Show("test"); adWin.RibbonControl ribbon = adWin.ComponentManager.Ribbon; foreach (adWin.RibbonTab tab in ribbon.Tabs) { //System.Windows.Forms.MessageBox.Show(tab.Id); if (tab.Id == "Analyze") { foreach (adWin.RibbonPanel panel in tab.Panels) { //System.Windows.Forms.MessageBox.Show(panel.Source.Id); if (panel.Source.Id == "cea_shr") { adWin.RibbonButton button = new adWin.RibbonButton(); button.Name = "TbcButtonName"; // button.Image = Image.FromFile("C:\\Users\\a\\Downloads\\12347734_10204048769899926_1746719051843979140_n.jpg"); //button.LargeImage = image; button.Id = "ID_TBC_BUTTON"; button.AllowInStatusBar = true; button.AllowInToolBar = true; button.GroupLocation = Autodesk.Private .Windows.RibbonItemGroupLocation.Middle; button.IsEnabled = true; button.IsToolTipEnabled = true; button.IsVisible = true; button.ShowImage = true; button.ShowText = true; button.ShowToolTipOnDisabled = true; button.Text = "Export vues"; button.ToolTip = "Open The Building " + "Coder blog on the Revit API"; button.MinHeight = 0; button.MinWidth = 0; button.Size = adWin.RibbonItemSize.Large; button.ResizeStyle = adWin .RibbonItemResizeStyles.HideText; button.IsCheckable = true; button.Orientation = System.Windows .Controls.Orientation.Vertical; button.KeyTip = "TBC"; //adWin.ComponentManager.UIElementActivated // += new EventHandler< // adWin.UIElementActivatedEventArgs>( // ComponentManager_UIElementActivated); panel.Source.Items.Add(button); return Result.Succeeded; } } } } return Result.Succeeded; }

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

 



PIRO Charles
Developer

PIRO CIE
Linkedin


0 Likes
Message 5 of 6

Anonymous
Not applicable

Well ... Now it work !!! 😄
Thanks a lot guys !!!

0 Likes
Message 6 of 6

Mustafa.Salaheldin
Collaborator
Collaborator

You are mixing between IExternalCoammand and IExternalApplication.

 

The code provided by @Charles.Piro has corrected this by implementing IExternalApplication interface instead of the IExternalCoammand interface as you did, this was the first correction.

 

The second one: You stated that your code runs when you put it in the Execute method, this is because it is implemented for the IExternalCoammand interface, the IExternalApplication which has the declaration for the OnStartup method is the one where you should put your code in first place to make it run correctly as you wanted and adjust your manifest file as I indicated in my previous post to startup from the ExternalApplication not the ExternalCommand.

 

Thanks


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn