Need to add a custom button in ribbon for Inventor 2021

Need to add a custom button in ribbon for Inventor 2021

muaslam
Enthusiast Enthusiast
2,323 Views
6 Replies
Message 1 of 7

Need to add a custom button in ribbon for Inventor 2021

muaslam
Enthusiast
Enthusiast

Hello,

 

I am a new starter with development of add-in for Inventor, I need to add a custom button in the ribbon. I have been able to create a simple add-in project and it performs any operations specified in Activate method.

 

I have gone through below link to see the method to add a custom ribbon button, https://knowledge.autodesk.com/support/inventor-engineer-to-order/learn-explore/caas/CloudHelp/cloud...

 

but I cannot find Autodesk.ETO.UI and any of the assemblies mentioned anywhere on my machine. From where can I get these assemblies is not mentioned anywhere. Could anyone help me on this? 

 

Regards,

Umar

0 Likes
2,324 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor

Hi @muaslam 

Those asseblies are for Inventor ETO I believe. You shouldn't have to reference them to add a button.

Have you installed the SDK from C:\Users\Public\Documents\Autodesk\Inventor XXXX\SDK?

Then you'll get an addin-template for VS with a lot of comments in it with instructions of how to create button 🙂

 

 

Message 3 of 7

JhoelForshav
Mentor
Mentor

You can also use this Addin-template from @BrianEkins that already has a button to begin with:

https://ekinssolutions.com/nifty_addin_template/

 

0 Likes
Message 4 of 7

muaslam
Enthusiast
Enthusiast

There are a few things to mention,

 

I have installed trial of Inventor 2019 and SDK directory just contained a help document.

muaslam_1-1597822470728.png

 

 

So, I have downloaded SDK from internet. Now, that I have installed the SDK, I can see options in my Visual Studio as "Autodesk inventor 2019 AddIn" while the link that you shared is for Nifty Add-in Inventor 2018.

muaslam_0-1597822391505.png

 

 

Now, that I have created a project of the template that is shown in Visual Studio, I am seeing the following items in it,

muaslam_2-1597822567752.png

 

And following the comments in the StandardAddInServer does not help in adding a new ribbon button anyhow. Although, if I show a MessageBox in StandardAddInServer.Activate method, it appears up while launching Inventor. Now, the issue is to display a button in the ribbon, that I cannot see anywhere.

0 Likes
Message 5 of 7

JhoelForshav
Mentor
Mentor

Hi @muaslam 

I don't know about the C#-template. I don't have it installed so maybe you're right that there are no instructions in that one. The Visual Basic template however has comments instructing you how to create a button. Maybe you can translate it if you want to use C#.

 

Also, event though the Nifty Addin Template uses the 2018 interop it still works for later versions. You can change this reference aswell if you want to. That is in Visual Basic as well though.

 

What you need to do:

Declare the ButtonDefinition in your StandardAddinServer Class:

Private WithEvents m_sampleButton As ButtonDefinition

In your Activate class, create the button definition and call AddToUserInterface if first time:

' Sample to illustrate creating a button definition.
Dim largeIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.YourBigImage)
Dim smallIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.YourSmallImage)
Dim controlDefs As Inventor.ControlDefinitions = g_inventorApplication.CommandManager.ControlDefinitions
m_sampleButton = controlDefs.AddButtonDefinition("Command Name", "Internal Name", CommandTypesEnum.kShapeEditCmdType, AddInClientID)

' Add to the user interface, if it's the first time.
If firstTime Then
	AddToUserInterface()
End If

Then your AddToUserInterface can look something like this to add the button:

Private Sub AddToUserInterface()
	'This Is where you'll add code to add buttons to the ribbon.

	'** Sample to illustrate creating a button on a New panel of the Tools tab of the Part ribbon.

	' Get the part ribbon.
	Dim partRibbon As Ribbon = g_inventorApplication.UserInterfaceManager.Ribbons.Item("Part")

	' Get the "Tools" tab.
	Dim toolsTab As RibbonTab = partRibbon.RibbonTabs.Item("id_TabTools")

	' Create a new panel.
	Dim customPanel As RibbonPanel = toolsTab.RibbonPanels.Add("Sample", "MysSample", AddInClientID)

	' Add a button.
	customPanel.CommandControls.AddButton(m_sampleButton)
End Sub
Message 6 of 7

JhoelForshav
Mentor
Mentor

For some reason I can't edit my reply. But just to make sure there's no confusion - I meant to say "In your Activate Sub" not "In your Activate Class"....

0 Likes
Message 7 of 7

JhoelForshav
Mentor
Mentor

And a sample handler for that button:

Private Sub m_sampleButton_OnExecute(Context As NameValueMap) Handles m_sampleButton.OnExecute
    MsgBox("Button was clicked.")
End Sub