Dockable Window

Dockable Window

Anonymous
Not applicable
1,318 Views
4 Replies
Message 1 of 5

Dockable Window

Anonymous
Not applicable

Hello Everyone,

 

How can I get the volume of solid when using the "onselect" event and put it to a text box on the user Dockable Window.

 

I did try but when I select It did not change the text of the textbox on the Dockable.

 

Please help me in this case

 

Many thanks.

0 Likes
Accepted solutions (1)
1,319 Views
4 Replies
Replies (4)
Message 2 of 5

HideoYamada
Advisor
Advisor

Hi,

 

What language are you using? (VBA, C#, VB.net or etc...)

 

If you just only want to know the volume at Dockable Window,

(you don't want to write the code if it's possible,)

you can download and customize my app Tiny Quick Property for it.

Capture.png

 

=====

Freeradical

 Hideo Yamada

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 3 of 5

Anonymous
Not applicable

Hello Yamada

 

I would like to write the code for my situation. I am using vb.net.

 

Many thanks.

0 Likes
Message 4 of 5

HideoYamada
Advisor
Advisor
Accepted solution

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

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 5 of 5

Anonymous
Not applicable

Many thank Mr.!

0 Likes