How to create your own build-in command

How to create your own build-in command

Anonymous
Not applicable
466 Views
1 Reply
Message 1 of 2

How to create your own build-in command

Anonymous
Not applicable

I have built a button on a customized tab and I want to create customized functions for this button. How should I define this button?

 

for example, I have define the button with an internal name "OpenStepCmd". How should I associate it with my own code? For example, to count component number of an assembly. From my understanding, each controldefinition is referenced with its only internal name, but it is a string. How to add functions to it?

 

 

 m_sampleButton = controlDefs.AddButtonDefinition("Open STEP", "OpenStepCmd", CommandTypesEnum.kFileOperationsCmdType, AddInClientID, "", "Open a STEP file", largeIcon)

 

Thanks 

 

0 Likes
467 Views
1 Reply
Reply (1)
Message 2 of 2

AlexFielder
Advisor
Advisor

Hi @Anonymous,

 

If you take a look in C:\Users\Public\Documents\Autodesk\Inventor 2017\SDK you should find two .msi files:

 

developertools.msi

 

&

 

usertools.msi

 

I am assuming you have already found developertools.msi since you have an add-in loaded. But if not, it includes an add-in template that has a bunch of commented-out code starting at around line 12 of standardaddinserver.vb; uncomment the following lines:

 

'Private WithEvents m_sampleButton As ButtonDefinition

&

 

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

&

 

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

&

 

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

And you will have a button that when clicked displays a message to the user.

 

This series of articles by Autodesk explains further:

 

http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=17324828

 

Cheers,

 

Alex.

 

 

 

0 Likes