Using Inventor 2018 Ultimate debugging with visual studio 2015 community
I am trying to learn how to use interactive selections with the API (VB.net). So I started building an add in following the admapi example for user interactive selection as a tutorial. However I cannot seem to get the onselect event to fire. The admapi example is written in VBA so my code is a little different and evidently I am missing something as I am able to select edges as expected but the onselect event never fires as the admapi example suggests it should. The form is called from the StandardAddInServer...
' Sample handler for the button. Private Sub m_sampleButton_OnExecute(Context As NameValueMap) Handles m_sampleButton.OnExecute MsgBox("Button was clicked.") Dim oForm As New Form2 oForm.Show() End Sub
Below is the code for the form...
Imports Inventor Public Class Form2 Private WithEvents oInteraction As InteractionEvents Private WithEvents oSelect As SelectEvents Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load oInteraction = g_inventorApplication.CommandManager.CreateInteractionEvents oSelect = oInteraction.SelectEvents oInteraction.StatusBarText = "Select an edge" oSelect.AddSelectionFilter(SelectionFilterEnum.kPartEdgeFilter) oSelect.SingleSelectEnabled = True oInteraction.Start() End Sub Private Sub oSelect_Onselect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) Handles oSelect.OnSelect Dim i As Long Dim dlength As Double For i = 1 To JustSelectedEntities.Item(i) Dim oEdge As Edge = JustSelectedEntities.Item(i) Dim dMin As Double Dim dMax As Double oEdge.Evaluator.GetParamExtents(dMin, dMax) Dim dSingleLength As Double oEdge.Evaluator.GetLengthAtParam(dMin, dMax, dSingleLength) dlength = dlength + dSingleLength TextBox1.Text = Format(dlength, "0.0000 cm") TextBox2.Text = JustSelectedEntities.Count Next MsgBox("IT WORKED!!!",, "") End Sub End Class
Why does the oSelect_Onselect sub not fire when the edges are selected? What am I missing?
Solved! Go to Solution.
Solved by bradeneuropeArthur. Go to Solution.
try this:
Private Sub oSelect_Onselect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As Inventor.View) Handles oSelect.OnSelect MsgBox(JustSelectedEntities.Count) Dim i As Long Dim dlength As Double For i = 1 To JustSelectedEntities.Count Dim oEdge As Edge = JustSelectedEntities.Item(i) Dim dMin As Double Dim dMax As Double oEdge.Evaluator.GetParamExtents(dMin, dMax) Dim dSingleLength As Double oEdge.Evaluator.GetLengthAtParam(dMin, dMax, dSingleLength) dlength = dlength + dSingleLength TextBox1.Text = Format(dlength, "0,0000 cm") TextBox2.Text = JustSelectedEntities.Count Next MsgBox("IT WORKED!!!",, "") End Sub
The only thing is not working is the textbox1.text = format.....
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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: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 !
I see that may be an issue but I am not even getting into that sub routine to read that line. Sub oSelect_Onselect is not being read.
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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: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 !
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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: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 !
There may be another issue here. I just commented out a line of code that displays a message box but the message box is still popping up when I start the add in...
Private Sub m_sampleButton_OnExecute(Context As NameValueMap) Handles m_sampleButton.OnExecute 'MsgBox("Button was clicked.") Dim oForm As New Form2 oForm.Show()
Something else I notice now is the break points are not being hit. Its as if it is not connected to the edits I am making. I tried a clean and rebuild but same issues. Selection filter is not working either now though it was earlier today. Do I need to unload the add in or something?
because you are creating a new form:
Public Sub New()
oInteraction = g_inventorApplication.CommandManager.CreateInteractionEvents
oSelect = oInteraction.SelectEvents
oInteraction.StatusBarText = "Select an edge"
oSelect.AddSelectionFilter(SelectionFilterEnum.kPartEdgeFilter)
oSelect.SingleSelectEnabled = True
oInteraction.Start()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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: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 !
and use this reference to inventor library instead of yours:
C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Autodesk.Inventor.Interop\v4.0_22.0.0.0__@@@@@@@\Autodesk.Inventor.Interop.dll
set copy local to false
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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: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 !
Still not working. Something is disconnected somewhere how can it be that a line of code is commented out yet is still being read?
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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: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 !
This is an add in.
Inventor professional 2018 64-bit edition build: 227, Release 2018.2.3 - Date: Tue 01/16/2018.
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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: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 !
Hi,
Where is the "g_inventorApplication" declared and how is it passed to the form2?
oInteraction = g_inventorApplication.CommandManager.CreateInteractionEvents
This is your code.
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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: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 !
Started working on this again this morning and noticed my addin button was missing from the tools tab when debugging. I went to the add ins manager and noticed the add in was unloaded so I tried to load it and it would not load. Stopped the debugger and started again, the button now appears and the add in shows as loaded. Miraculously everything seems to be working correctly now... Breakpoints are being hit, and the on select event is now firing. I did not change anything in the code from last Friday. Evidently my machine just needed restarted?
In any case the g_inventorApplication is defined in the standard add in server namespace...
Imports Inventor Imports System.Runtime.InteropServices Imports Microsoft.Win32 Namespace ADDIN_TEST <ProgIdAttribute("ADDIN_TEST.StandardAddInServer"), _ GuidAttribute("2cf6734b-fa00-4dfa-b0e7-fbc893cc76e4")> _ Public Class StandardAddInServer Implements Inventor.ApplicationAddInServer Private WithEvents m_uiEvents As UserInterfaceEvents Private WithEvents m_sampleButton As ButtonDefinition #Region "ApplicationAddInServer Members" ' This method is called by Inventor when it loads the AddIn. The AddInSiteObject provides access ' to the Inventor Application object. The FirstTime flag indicates if the AddIn is loaded for ' the first time. However, with the introduction of the ribbon this argument is always true. Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate ' Initialize AddIn members. g_inventorApplication = addInSiteObject.Application ' Connect to the user-interface events to handle a ribbon reset. m_uiEvents = g_inventorApplication.UserInterfaceManager.UserInterfaceEvents ' TODO: Add button definitions. ' Sample to illustrate creating a button definition. Dim largeIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.BMAP1) Dim smallIcon As stdole.IPictureDisp = PictureDispConverter.ToIPictureDisp(My.Resources.BMAP1) Dim controlDefs As Inventor.ControlDefinitions = g_inventorApplication.CommandManager.ControlDefinitions m_sampleButton = controlDefs.AddButtonDefinition("EdgeSelect", "Internal Name", CommandTypesEnum.kShapeEditCmdType, AddInClientID) ' Add to the user interface, if it's the first time. If firstTime Then AddToUserInterface() End If End Sub
The form is called from the add in button execute event found in the same namespace...
' Sample handler for the button. Private Sub m_sampleButton_OnExecute(Context As NameValueMap) Handles m_sampleButton.OnExecute 'MsgBox("Button was clicked.") Dim oForm As New Form2 oForm.Show() End Sub
I guess this is solved now, but would like to know what happened and what changing the references copy local to False does?
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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: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 !