Right click pop out button? Inventor add-in

Right click pop out button? Inventor add-in

Curtis_Waguespack
Consultant Consultant
2,449 Views
21 Replies
Message 1 of 22

Right click pop out button? Inventor add-in

Curtis_Waguespack
Consultant
Consultant

 

I have been successful in adding a right click button within an add-in... see the "Hello World" button below.

 

I'm wondering if we can add a "pop out" button like the built in Rotate button ( this example is shown when right clicking on a parts list) as shown below.

 

I tried a few things but have come up empty, but I might have missed something.

 

See the attached *.zip file for a very basic add-in example I created and tested in Inventor 2023, in case that helps understand the question, hopefully that will allow you to explore the right click menu API functions without having to spin up something from scratch.

 

Thank you, Curtis

 

Curtis_Waguespack_2-1680277248799.png

 

EESignature

0 Likes
2,450 Views
21 Replies
Replies (21)
Message 2 of 22

Curtis_Waguespack
Consultant
Consultant

.

EESignature

0 Likes
Message 3 of 22

Michael.Navara
Advisor
Advisor
Accepted solution
Message 4 of 22

josh.nieman
Advocate
Advocate

Apologies for not trying my suggestion before .. suggesting.  But, you're adding a plain button and I think you need a different control object type to get the features you desire.

 

If the linear marking menu is like other UI elements I've extended, I think what you want is ".addSplitButton" function, for which you assign an ObjectCollection as the ButtonDefinitions property, which should appear on the popup you're intending to create.
From 

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=CommandControls_AddSplitButton :


Syntax

CommandControls.AddSplitButtonDisplayedControl As ButtonDefinitionButtonDefinitions As ObjectCollection, [UseLargeIcon] As Boolean, [ShowText] As Boolean, [TargetControlInternalName] As String, [InsertBeforeTargetControl] As Boolean ) As CommandControl


So you'd have something like

 

 

 

Dim HWB as ButtonDefinition = MyCoolButton
Dim HWBsubItems as ObjectCollection
'--<add your cool stuff to the HWBsubItems ObjectCollection>

HWB.ButtonDefinitions = HWBsubItems

Dim LMM as LinearMarkingMenu = WhateverMarkingMenuYouWant
LMM.addSplitButton(HWB, HWB.subItems)

 

 

 

 

So you'd have "Hello World" show up with the right-pointing triangle/arrow on your main LinearMarkingMenu
Upon click/hover (I forget) of "Hello World" it would fly out with a new LinearMarkingMenu-style-object with a row for each object in "ButtonDefinitions" as ObjectCollection.


API doc for CommandControls shows the possible types:

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=CommandControls

0 Likes
Message 5 of 22

josh.nieman
Advocate
Advocate
Accepted solution

Alternatively, have you tried this function from up on the top RadialMarkingMenu object?
https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=RadialMarkingMenu_CreateRadialSubMenu

(ok now I'm curious and have to try it out because a submenu seems like a pretty fundamental UI necessity)

Message 6 of 22

josh.nieman
Advocate
Advocate

Sorry, I take back everything I said 😂

API documentation makes it look trivial to accomplish, but every method I tried resulted in 'System.NotImplementedException' errors.

Pretty sure that means that while the LinearMarkingMenu (which is .. apparently a psuedo object?  An object without API support?  Only RadialMarkingMenus appear in the API documentation)  is type 'CommandControls ' it apparently does not implement all the methods/objects/functions OF the 'CommandControls' interface 😞

Message 7 of 22

nmunro
Collaborator
Collaborator

Both radial and linear marking menus are available. The old school linear menus (no radial) have to be activated in the UI to enable API access.

 

nmunro_0-1680629814282.png

 

        


https://c3mcad.com

0 Likes
Message 8 of 22

Curtis_Waguespack
Consultant
Consultant

@nmunro wrote:

Both radial and linear marking menus are available. The old school linear menus (no radial) have to be activated in the UI to enable API access.


I'm still not seeing that this works ( Inventor 2023) ... attached is my updated simple example project.

 

I tried adding a popup, split button, split button MRU, and a button popup... all with and the radial menu option disabled.

 

With this option selected, so that the radial menu is disabled... (and still using the OnLinearMarkingMenu event) , I get the not implemented error still.

 

Curtis_Waguespack_1-1680631882224.png

 

I also attempted to use the OnContextMenu Event and the OnContextMenuOld events.

 

In those cases there was no error, but the events did nothing. ( I tried these events with and without the radial menu option enabled.)

 

Curtis_Waguespack_2-1680631978913.png

 

 

 

EESignature

0 Likes
Message 9 of 22

Curtis_Waguespack
Consultant
Consultant

Thanks for having a look, these were the results that I was seeing last week when trying to get this to work, as well.

 

 

EESignature

0 Likes
Message 10 of 22

Curtis_Waguespack
Consultant
Consultant
Accepted solution

 


@josh.nieman wrote:

Alternatively, have you tried this function from up on the top RadialMarkingMenu object?
https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=RadialMarkingMenu_CreateRadialSubMenu

(ok now I'm curious and have to try it out because a submenu seems like a pretty fundamental UI necessity)


 

 

Thanks for this as well. This does work, and seems to be our best option.

 

Attached is a *.zip file with my updated simple project with this implemented, as shown below working in Inventor 2023.

 

and here's a related link showing how to add a custom radial menu depending upon the object type that is selected:

 

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/adding-a-custom-radial-marking-menu/...

 

Curtis_Waguespack_0-1680633763259.png

Curtis_Waguespack_1-1680633786535.png

 

 

 

 

EESignature

Message 11 of 22

g.georgiades
Advocate
Advocate

Slightly off topic - but the hidden onContextMenu event is the only way to add entries to some menus that don't fire the OnLinearMarkingMenu event. I did also try using the old API CommandBars to generate a sub menu  (ThisApplication.UserInterfaceManager.CommandBars.Add) - but it just errors out when making a new commandbar...

 

Affected items I've found:

Drawing and Presentation Top level browser nodes, some top level folders in assembly and part files e.g. Relationships Folder in assemblies.

 

The vault addin manages to access this API though? - so there must be something the devs are not sharing, unless they put in a vault specific override for just vault.

 

ggeorgiades_1-1680637531409.pngggeorgiades_2-1680637686373.png

 

 

 

Message 12 of 22

jjstr8
Collaborator
Collaborator

@Curtis_Waguespack :  I think you're looking to do this.

 

jjstr8_0-1689011004487.png

If that's the case, use @g.georgiades 's suggestion of the OnContextMenu event.  I'm not sure why adding a CommandBar produced an error.  It didn't for me.  There's a few issues with it though.

  • OnContextMenu doesn't actually give any real context information.  You don't know what object was right-clicked on.  Fortunately, OnLinearMarkingMenu fires right after it and gives you a chance to delete what you added if it doesn't apply to the actual object that was right-clicked.  It also gives you a chance to add context-specific buttons. 
  • Only a partial menu is available in the event.  The rest is generated after you're done handling the event.  This can complicate specifying where your menu goes relative to the rest of the menu.

In my example, I created a new CommandBar in the OnContextMenu handler and added an empty ButtonPopup to it, then added it to the CommandBar passed into OnContextMenu.  I added the Open and Save buttons while in OnLinearMarkingMenu.  Just loop through the CommandControls passed in to find the ButtonPopup you added in OnCentextMenu.

 

I haven't done much testing with it, but it looks like a good place to start.

 

- Jeremy

Message 13 of 22

ngdnam88
Advocate
Advocate

Could you please share your code to us @jjstr8 

Thanks!

0 Likes
Message 14 of 22

jjstr8
Collaborator
Collaborator

@ngdnam88 :  Sorry, I didn't save the code.  It was just a quick test.  There wasn't much to it, so start with the description I posted.  I'll see if I can find some time to whip something up.

Message 15 of 22

yuzeaa
Advocate
Advocate
Accepted solution

Here is a sample code for you which could be tested in ilogic.

2024-01-12 113040.png

Class ThisRule
	Private SizeA0,SizeA1,SizeA2,SizeA3,SizeA4 As ButtonDefinition
    Private SheetSize As CommandBar
	Sub main
		If SharedVariable.Exists("Drawingsize") Then Return
		SharedVariable("Drawingsize") = 1
		SheetSize = ThisApplication.UserInterfaceManager.CommandBars.Add("Drawingsize","DrawingSizeCmd",CommandBarTypeEnum.kPopUpCommandBar)
        Dim oControls = ThisApplication.CommandManager.ControlDefinitions
		SizeA0 = oControls.AddButtonDefinition("     A0", "ChangeSheetSizeA0Cmd", CommandTypesEnum.kShapeEditCmdType)
        SizeA1 = oControls.AddButtonDefinition("     A1", "ChangeSheetSizeA1Cmd", CommandTypesEnum.kShapeEditCmdType)
		SizeA2 = oControls.AddButtonDefinition("     A2", "ChangeSheetSizeA2Cmd", CommandTypesEnum.kShapeEditCmdType)
		SizeA3 = oControls.AddButtonDefinition("     A3", "ChangeSheetSizeA3Cmd", CommandTypesEnum.kShapeEditCmdType)
		SizeA4 = oControls.AddButtonDefinition("     A4", "ChangeSheetSizeA4Cmd", CommandTypesEnum.kShapeEditCmdType)
		SheetSize.Controls.AddButton(SizeA0)
		SheetSize.Controls.AddButton(SizeA1)
		SheetSize.Controls.AddButton(SizeA2)
		SheetSize.Controls.AddButton(SizeA3)
		SheetSize.Controls.AddButton(SizeA4)

        AddHandler SizeA0.OnExecute, AddressOf OnCLickA0
		AddHandler SizeA1.OnExecute, AddressOf OnCLickA1
		AddHandler SizeA2.OnExecute, AddressOf OnCLickA2
		AddHandler SizeA3.OnExecute, AddressOf OnCLickA3
		AddHandler SizeA4.OnExecute, AddressOf OnCLickA4
        AddHandler ThisApplication.CommandManager.UserInputEvents.OnContextMenu, AddressOf OnContextMenu
	End Sub
	
	Private Sub OnContextMenu(SelectionDevice As SelectionDeviceEnum, AdditionalInfo As NameValueMap, CommandBar As CommandBar)
		Dim doc = ThisApplication.ActiveDocument
		If Not TypeOf doc Is DrawingDocument Then Return
        If doc.selectset.count <> 1 Then Return
		If doc.selectset(1) IsNot doc.ActiveSheet Then Return
		CommandBar.Controls.AddPopup(SheetSize, 2)
    End Sub
     
	Private Sub OnCLickA0
		MsgBox("A0 is clicked")
	End Sub

	Private Sub OnCLickA1
		MsgBox("A1 is clicked")
	End Sub

	Private Sub OnCLickA2
		MsgBox("A2 is clicked")
	End Sub

	Private Sub OnCLickA3
		MsgBox("A3 is clicked")
	End Sub

	Private Sub OnCLickA4
		MsgBox("A4 is clicked")
	End Sub
End Class
Message 16 of 22

ngdnam88
Advocate
Advocate

Thanks! @yuzeaa 
It's really very good!

0 Likes
Message 17 of 22

ngdnam88
Advocate
Advocate

It'll be perfect if can add an button for this:

ngnam1988_0-1705052995867.png

Do you have any idea?
Seem as with UserInterfaceManager.CommandBars.Add() - Can't add an icon

0 Likes
Message 18 of 22

ngdnam88
Advocate
Advocate

Hi @yuzeaa
Could you help me how to make this icon dynamic change follow active sheet size?

ngnam1988_0-1705458421549.png

I tried add one but it's not automatic changed.

ngnam1988_1-1705458608114.png

I'm working with VB.NET. I tested your code and saw the menu didn't show at first mouse right-click time.

ngnam1988_2-1705458847178.png

The second right-click time I got this error.

ngnam1988_3-1705458975588.png

But menu show correct

ngnam1988_5-1705459414519.png

Thanks,

0 Likes
Message 19 of 22

yuzeaa
Advocate
Advocate

I generally use iLogic instead of add-ins because iLogic is more convenient for modifications. I will write an add-in for you as an example and then post it later.

Message 20 of 22

ngdnam88
Advocate
Advocate

Great! @yuzeaa 
If you done it in iLogic, could you share it here - it'll not take more your time than you create an new add-in. As you see, I'm trying convert your code into VB.NET
Thanks

0 Likes