Modify Inventor dialogs & context-menus

Modify Inventor dialogs & context-menus

Anonymous
Not applicable
4,448 Views
14 Replies
Message 1 of 15

Modify Inventor dialogs & context-menus

Anonymous
Not applicable
I have two questions: 
 
(1) May I modify Inventor provided dialogs and how? For example, add an item and icon "Cut & New Solid" as below, which not only cuts the existing solids but also keeps the tool shape (which is sphere here) as a new solid.
 
Inline image 2
 
(2) May I add a menu item to Inventor provided context menu and how? The menu item "EM Properties" is used to show the solid's electromagnetic properties like refractive index.
 
Inline image 4
0 Likes
Accepted solutions (1)
4,449 Views
14 Replies
Replies (14)
Message 2 of 15

Owner2229
Advisor
Advisor

Hi, can you please post the images again? They won't load for us from your GMail.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 15

Anonymous
Not applicable

Images here also

 

For question 1

 

For question 2

0 Likes
Message 4 of 15

rjay75
Collaborator
Collaborator
Accepted solution

No you can't modify the existing Inventor dialogs. But yes you can add custom items to the Context Menu. The Inventor API help has a sample program demonstrating adding a Button to the Context Menu.

Message 5 of 15

Anonymous
Not applicable
rjay75, I'm having trouble finding the sample you're referring to. Would you have any tips on how to find it? Thank you.
0 Likes
Message 6 of 15

bradeneuropeArthur
Mentor
Mentor
You need to install the ASK kit first in your programfiles folder / bin/ SDK

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 15

rjay75
Collaborator
Collaborator

Had to dig back to old versions of the API help. But from the 2013 help here is the example code. I've test this and the code still works in 2017.

 

Add a button to the context menu API Sample

' Copy the following into a Module.

Option Explicit

Public oClass1 As Class1

Sub AddToMenu()
    Set oClass1 = New Class1
    oClass1.Initialize
End Sub

'*************************************************************
' The declarations and functions below need to be copied into
' a class module whose name is "Class1".  The name 
' can be changed but you'll need to change the declaration in
' the calling function "AddToMenu" to use the new name.


Option Explicit
Private WithEvents oUserInputEvents As UserInputEvents

Public Sub Initialize()
    Set oUserInputEvents = ThisApplication.CommandManager.UserInputEvents
End Sub

Private Sub oUserInputEvents_OnContextMenu(ByVal SelectionDevice As SelectionDeviceEnum, ByVal AdditionalInfo As NameValueMap, ByVal CommandBar As CommandBar)

    On Error Resume Next
    
    ' Check if the context menu has the 'Home View' (formerly 'Isometric View') command
    Dim oCmdBarControl As CommandBarControl
    Set oCmdBarControl = CommandBar.Controls.Item("AppIsometricViewCmd")
    
    If Not oCmdBarControl Is Nothing Then
        
        Dim oCtrlDef As ControlDefinition
        Set oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppZoomAllCmd")
        
        ' Add the "Zoom All" command before the home view command
        Call CommandBar.Controls.AddButton(oCtrlDef, oCmdBarControl.index)
        
    End If
    
End Sub

 

I still use this code in software using C#.

 

Summarizing what it does.

 

Create a button definition. Add it to the ControlDefinitions of the Application.CommandManager object. Add a event handler on the button class as normal. Add an event handler to the CommandManager.UserInputs.OnContextMenu event. In that event handler determine if it's the appropriate context to show your command. IE... look at any selected objects etc... If so add your button to the list if it's not there. If not and it's present remove your button. The definition still exists.

 

 

Some C# code I use to achieve this. I create the command definition as normal, but use the event to conditionally add it to the context menu.

 

Snippet

void UserInputEvents_OnContextMenu(SelectionDeviceEnum SelectionDevice, NameValueMap AdditionalInfo, CommandBar CommandBar)
{
    if (appInventor.ActiveDocument == null)
        return;
    CommandBarControl cmdCtrl = null;
    foreach (CommandBarControl tCtrl in CommandBar.Controls)
    {
        if (tCtrl.InternalName.Equals("btnNewBtnName"))
        {
            cmdCtrl = tCtrl;
            break;
        }
    }
    bool hasItems = appInventor.ActiveDocument.SelectSet.Count > 0;
    if ((cmdCtrl == null) && hasItems)
    {
        cmdCtrl = CommandBar.Controls.AddButton(btnNewBtn);
    }
    else if ((cmdCtrl != null) && !hasItems)
    {
        cmdCtrl.Delete();
    }
}

 

 

 

 

 

 

 

Message 8 of 15

Anonymous
Not applicable

Thank you. Now I'm looking to find out which component instance was hovered over when the user did the right click which triggers this event handler. The AdditionalInfo NameValueMap is always null from what I'm seeing. 

 

The part in an assembly does get highlighted when I right click on it but my document.HighlightSets.Count = 0 

 

Is there another way to find out what the user intended context was when they did the right click?

 

 

0 Likes
Message 9 of 15

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Hope this piece of code will help you!

 

 Dim oselectionSet As SelectSet = m_inventorApplication.ActiveDocument.SelectSet
                            Dim oSelectedCompOcc As ComponentOccurrence = oselectionSet.Item(1)
                            
dim oDoc as document = oSelectedCompOcc.Definition.Document

MsgBox(oDoc.fullfilename)

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 10 of 15

Anonymous
Not applicable

Thanks. That's what I went with yes but it's not always what they right clicked on to open the menu. If you already had somethings selected and you then right click on another part in the assembly the selection set has the previously selected parts, not the one that was just right clicked on. This is why UI context is usually passed to this sort of event... to give specific context for the user interaction. 

0 Likes
Message 11 of 15

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Would the mouse click event bring something?

Or mousehover?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 12 of 15

Anonymous
Not applicable

Good question. I don't see those on CommandManager.UserInputEvents

 

I'll play around with OnPreSelect and OnStopPreselect. That looks like the same concept. 

 

Thank you for sharing that suggestion.

 

0 Likes
Message 13 of 15

rjay75
Collaborator
Collaborator

Hello, the event that would supply that information is the UserInputEvents.OnPreSelect event.

 

 

Message 14 of 15

bradeneuropeArthur
Mentor
Mentor

I will take a look at this soon ok?

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 15 of 15

Anonymous
Not applicable

Yep, that's working for me. I just capture the info and then clear it when the OnStopPreselect fires. If the context menu opens up before OnStopPreselect then I have what I need so that works good.

 

Thanks to all. 

0 Likes