Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inventor addin (calling dialog)

1 REPLY 1
Reply
Message 1 of 2
navbor
801 Views, 1 Reply

Inventor addin (calling dialog)

I have written the following code for my inventor addin. Everything works fine (or so it seems), but I am stuck with a problem that I cannot make sense of.

 

So far my code creates a new ribbon panel and button on the tools tab for parts, assemblies, zerodoc & drawings.

 

I have created a dialog that I want to open from this button. However since I have created a wrapper to make my dialog modeless, I am not sure how to pass the "inventor.application" variable to my new dialog so that I can process futher.

 

Any tips / ideas will be most welcome.

 

The code is quite long, but the area where I think I need to make changes is "PrivateSub m_buttonDef_OnExecute(ByVal Context As Inventor.NameValueM...."

 

 

Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Namespace VMUtils
  <ProgIdAttribute("VMUtils.StandardAddInServer"), _
  GuidAttribute("4b0c909e-4a1f-435a-a37f-63ab230e1dc6"), _
  ComVisible(True)> _
  Public Class StandardAddInServer
    Implements Inventor.ApplicationAddInServer
    ' Inventor application object.
    Shared m_inventorApplication As Inventor.Application


    '#################################################################################################
    '# BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN #
    '# --------------------------------------------------------------------------------------------- #
    '# Class wide variable declerations                                                              #
    '#                                                                                               #
    '#################################################################################################

    Private m_clientID As String
    Private WithEvents m_iprop_buttonDef As ButtonDefinition = Nothing
    Private WithEvents m_uiEvents As UserInterfaceEvents = Nothing

    '#################################################################################################
    '# END # END # END # END # END # END # END # END # END # END # END # END # END # END # END # END #
    '# --------------------------------------------------------------------------------------------- #
    '# Class wide variable declerations                                                              #
    '#                                                                                               #
    '#################################################################################################

#Region "ApplicationAddInServer Members"

    Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, _
                        ByVal firstTime As Boolean) _
                      Implements Inventor.ApplicationAddInServer.Activate
      ' 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.
      ' Initialize AddIn members.
      m_inventorApplication = addInSiteObject.Application
      '#################################################################################################
      '# BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN #
      '# --------------------------------------------------------------------------------------------- #
      '# My code                                                                                       #
      '#                                                                                               #
      '#################################################################################################
      m_clientID = AddInGuID(GetType(StandardAddInServer))
      If firstTime Then
        CreateUserInterface()
      End If
      m_uiEvents = m_inventorApplication.UserInterfaceManager.UserInterfaceEvents
      '#################################################################################################
      '# END # END # END # END # END # END # END # END # END # END # END # END # END # END # END # END #
      '# --------------------------------------------------------------------------------------------- #
      '# My code                                                                                       #
      '#                                                                                               #
      '#################################################################################################

      ' TODO:  Add ApplicationAddInServer.Activate implementation.
      ' e.g. event initialization, command creation etc.
    End Sub

    Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate
      ' 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.
      ' TODO:  Add ApplicationAddInServer.Deactivate implementation
      ' Release objects.
      Marshal.ReleaseComObject(m_inventorApplication)
      m_inventorApplication = Nothing
      System.GC.WaitForPendingFinalizers()
      System.GC.Collect()
    End Sub

    Public ReadOnly Property Automation() As Object Implements _
      Inventor.ApplicationAddInServer.Automation
      ' This property is provided to allow the AddIn to expose an API 
      ' of its own to other programs. Typically, this  would be done by
      ' implementing the AddIn's API interface in a class and returning 
      ' that class object through this property.
      Get
        Return Nothing
      End Get
    End Property

    Public Sub ExecuteCommand(ByVal commandID As Integer) Implements _
      Inventor.ApplicationAddInServer.ExecuteCommand
      ' Note:this method is now obsolete, you should use the 
      ' ControlDefinition functionality for implementing commands.
    End Sub

#Region "Property definitions"
    '#################################################################################################
    '# BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN #
    '# --------------------------------------------------------------------------------------------- #
    '# My property definitions                                                                       #
    '#                                                                                               #
    '#################################################################################################
    'This property use reflection to get the value for the GuIDAttribute of the attached class
    Public Shared ReadOnly Property AddInGuID(ByVal t As Type) As String
      Get
        Dim guid As String = ""
        Try
          Dim customAttributes() As Object = t.GetCustomAttributes(GetType(GuidAttribute), False)
          Dim guidAttribute As GuidAttribute = CType(customAttributes(0), GuidAttribute)
          guid = "{" + guidAttribute.Value.ToString() + "}"
        Finally
          AddInGuID = guid
        End Try
      End Get
    End Property

    '#################################################################################################
    '# END # END # END # END # END # END # END # END # END # END # END # END # END # END # END # END #
    '# --------------------------------------------------------------------------------------------- #
    '# My property definitions                                                                       #
    '#                                                                                               #
    '#################################################################################################
#End Region

#Region "Custom methods"

    '#################################################################################################
    '# BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN #
    '# --------------------------------------------------------------------------------------------- #
    '# Custom Methods                                                                                #
    '#                                                                                               #
    '#################################################################################################
    Public Sub CreateUserInterface()
      'Get a reference to the UserinterfaceManager Object

      '---------------------------------------------

      Dim UIManager As Inventor.UserInterfaceManager = m_inventorApplication.UserInterfaceManager
      Dim controlDefs As ControlDefinitions = m_inventorApplication.CommandManager.ControlDefinitions
      Dim small_I_Prop_Icon As stdole.IPictureDisp = PictureConverter.ImageToPictureDisp _
                                                     (My.Resources.IPIcon16X16)
      Dim lrg_I_Prop_Icon As stdole.IPictureDisp = PictureConverter.ImageToPictureDisp _
                                                   (My.Resources.IPIcon32X32)
      Dim toolPanelDispname As String = "Viz-Mec tools"
      Dim parttoolPanelInternalName As String = "partVMTools"
      Dim assytoolPanelInternalName As String = "assyVMTools"
      Dim drawtoolPanelInternalName As String = "drawVMTools"
      Dim zerotoolPanelInternalName As String = "zeroVMTools"

      Dim partDocRibbon As Inventor.Ribbon = UIManager.Ribbons.Item("Part")
      Dim drawingDocRibbon As Inventor.Ribbon = UIManager.Ribbons.Item("Drawing")
      Dim assyDocRibbon As Inventor.Ribbon = UIManager.Ribbons.Item("Assembly")
      Dim zeroDocRibbon As Inventor.Ribbon = UIManager.Ribbons.Item("ZeroDoc")
      Dim partDocToolsTab As Inventor.RibbonTab = partDocRibbon.RibbonTabs.Item("id_TabTools")
      Dim assyDocToolsTab As Inventor.RibbonTab = assyDocRibbon.RibbonTabs.Item("id_TabTools")
      Dim drawDocToolsTab As Inventor.RibbonTab = drawingDocRibbon.RibbonTabs.Item("id_TabTools")
      Dim zeroDocToolsTab As Inventor.RibbonTab = zeroDocRibbon.RibbonTabs.Item("id_TabTools")

      Dim partdocToolPanel As Inventor.RibbonPanel
      Dim assydocToolPanel As Inventor.RibbonPanel
      Dim drawdocToolPanel As Inventor.RibbonPanel
      Dim zerodocToolPanel As Inventor.RibbonPanel

      partdocToolPanel = partDocToolsTab.RibbonPanels.Add(toolPanelDispname, _
                                                          parttoolPanelInternalName, m_clientID)
      assydocToolPanel = assyDocToolsTab.RibbonPanels.Add(toolPanelDispname, _
                                                          assytoolPanelInternalName, m_clientID)
      drawdocToolPanel = drawDocToolsTab.RibbonPanels.Add(toolPanelDispname, _
                                                          drawtoolPanelInternalName, m_clientID)
      zerodocToolPanel = zeroDocToolsTab.RibbonPanels.Add(toolPanelDispname, _
                                                          zerotoolPanelInternalName, m_clientID)

      m_iprop_buttonDef = controlDefs.AddButtonDefinition("Iprops", "vmUtilsIProps", _
                                                          CommandTypesEnum.kNonShapeEditCmdType, _
                                                          m_clientID, _
                                                          , _
                                                          , _
                                                          small_I_Prop_Icon, _
                                                          lrg_I_Prop_Icon)

      partdocToolPanel.CommandControls.AddButton(m_iprop_buttonDef, True)
      assydocToolPanel.CommandControls.AddButton(m_iprop_buttonDef, True)
      drawdocToolPanel.CommandControls.AddButton(m_iprop_buttonDef, True)
      zerodocToolPanel.CommandControls.AddButton(m_iprop_buttonDef, True)
    End Sub


    '#################################################################################################
    '# END # END # END # END # END # END # END # END # END # END # END # END # END # END # END # END #
    '# --------------------------------------------------------------------------------------------- #
    '# Custom Methods                                                                                #
    '#                                                                                               #
    '#################################################################################################
#End Region

#End Region

    Private Sub m_buttonDef_OnExecute(ByVal Context As Inventor.NameValueMap) _
      Handles m_iprop_buttonDef.OnExecute
      Dim Ipropfrm As frmiProps = New frmiProps

      Ipropfrm.Show(New WindowWrapper(m_inventorApplication.MainFrameHWND))
    End Sub

  End Class

    <System.ComponentModel.DesignerCategory("")> Friend Class PictureConverter
        Inherits System.Windows.Forms.AxHost

        Private Sub New()
            MyBase.New(String.Empty)
        End Sub

    Public Shared Function ImageToPictureDisp(ByVal image As System.Drawing.Image) As  _
      stdole.IPictureDisp
      Return CType(GetIPictureDispFromPicture(image), stdole.IPictureDisp)
    End Function
  End Class

#Region "hWnd Wrapper Class"
  ' This class is used to wrap a Win32 hWnd as a .Net IWind32Window class.
  ' This is used for parenting a dialog to the Inventor window.
  '
  ' For example:
  '
  ' myForm.Show(New WindowWrapper(m_inventorApplication.MainFrameHWND))
  '
  Public Class WindowWrapper

    Implements System.Windows.Forms.IWin32Window

    Public Sub New(ByVal handle As IntPtr)
      _hwnd = handle
    End Sub


    Public ReadOnly Property Handle As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle
      Get
        Return _hwnd
      End Get
    End Property

    Private _hwnd As IntPtr
  End Class
#End Region
End Namespace

 

Regards
Rob
-------------------------------------------
Windows 7 Pro (X64)
Intel(R) core (TM) i5-4690 CPU @ 3.50GHz
32.0 GB RAM
Nvidia Quadro K2000
Autodesk Inventor 2015 Professional Ultimate Design Suite
1 REPLY 1
Message 2 of 2
saseendrankombath
in reply to: navbor

Dim Ipropfrm As frmiProps = New frmiProps
Dim owner As New Windows.Forms.NativeWindow
                owner.AssignHandle(m_inventorApplication.MainFrameHWND)
                Ipropfrm.Show(owner)

 This will open the form under inventor

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report