O.K., here is sample code which uses dockable window to display volumes of selected items.
Imports Inventor
Imports System.Runtime.InteropServices
Namespace DockableWindowTest
<ProgIdAttribute("DockableWindowTest.StandardAddInServer"),
GuidAttribute("11289342-607b-4a8e-811d-4f59ed9ffab6")>
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
Private MyDockableWindow As DockableWindow
Private ContentTextBox As Windows.Forms.TextBox
Private WithEvents AppEvents As ApplicationEvents
Private WithEvents DocEvents As DocumentEvents
#Region "ApplicationAddInServer Members"
Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
' Initialize AddIn members.
g_inventorApplication = addInSiteObject.Application
' Add DockableWindow
ContentTextBox = New Windows.Forms.TextBox With {
.ReadOnly = True,
.Multiline = True
}
MyDockableWindow = g_inventorApplication.UserInterfaceManager.DockableWindows.Add("{b2747496-55f9-4092-bf42-91b25b9e8c07}", "DockableWindowTest", "Dockable Window Test")
MyDockableWindow.AddChild(ContentTextBox.Handle.ToInt64())
MyDockableWindow.Visible = True
' Add Application Event
AppEvents = g_inventorApplication.ApplicationEvents
End Sub
' This method is called by Inventor when the AddIn is unloaded. The AddIn will be
' unloaded either manually by the user or when the Inventor session is terminated.
Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate
AppEvents = Nothing
' Release objects.
Try
MyDockableWindow?.Delete()
Catch
End Try
Try
ContentTextBox?.Dispose()
Catch
End Try
MyDockableWindow = Nothing
ContentTextBox = Nothing
g_inventorApplication = Nothing
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
End Sub
Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation
Get
Return Nothing
End Get
End Property
Public Sub ExecuteCommand(ByVal commandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand
End Sub
#End Region
Private Sub AddText(str As String)
ContentTextBox.AppendText(str + System.Environment.NewLine)
End Sub
Private Sub AppEvents_OnActivateDocument(DocumentObject As _Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles AppEvents.OnActivateDocument
If BeforeOrAfter = EventTimingEnum.kAfter Then
AddText($"OnActivateDocument : {DocumentObject.DisplayName}")
DocEvents = DocumentObject.DocumentEvents
End If
End Sub
Private Sub AppEvents_OnDeactivateDocument(DocumentObject As _Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles AppEvents.OnDeactivateDocument
If BeforeOrAfter = EventTimingEnum.kBefore Then
AddText($"OnDeactivateDocument : {DocumentObject.DisplayName}")
DocEvents = Nothing
End If
End Sub
Private Sub DocEvents_OnChangeSelectSet(BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles DocEvents.OnChangeSelectSet
If BeforeOrAfter <> EventTimingEnum.kAfter Then Return
Dim selectSet = g_inventorApplication.ActiveEditDocument.SelectSet
If selectSet.Count = 0 Then Return
For Each obj In selectSet
Dim occ = TryCast(obj, ComponentOccurrence)
If occ Is Nothing Then Continue For
Dim doc = occ.ReferencedDocumentDescriptor.ReferencedDocument
Dim volume As Double = -1
Dim partNumber As String = String.Empty
If TypeOf doc Is PartDocument Then
Dim partDoc As PartDocument = doc
partNumber = partDoc.PropertySets("Design Tracking Properties")("Part Number").Value
volume = partDoc.PropertySets("Design Tracking Properties")("Volume").Value
End If
If TypeOf doc Is AssemblyDocument Then
Dim assyDoc As AssemblyDocument = doc
partNumber = assyDoc.PropertySets("Design Tracking Properties")("Part Number").Value
volume = assyDoc.PropertySets("Design Tracking Properties")("Volume").Value
End If
Dim volumeStr As String = String.Empty
If volume = 0 Then volumeStr = "N/A"
If volume > 0 Then volumeStr = volume.ToString()
If Not String.IsNullOrEmpty(volumeStr) Then
AddText($"{partNumber} : {volumeStr}")
End If
Next
End Sub
End Class
End Namespace
Public Module Globals
' Inventor application object.
Public g_inventorApplication As Inventor.Application
End Module
=====
Freeradical
Hideo Yamada