Help Creating a Button VB,NET Addin

Help Creating a Button VB,NET Addin

Anonymous
Not applicable
1,881 Views
5 Replies
Message 1 of 6

Help Creating a Button VB,NET Addin

Anonymous
Not applicable

Hi everyone,

 

I have a need to write an Inventor addin that loads some macrobuttons to the quick access toolbar.

 

I think I have it figured out as a test in VBA. No clue as to how to write it to be persistent as a VB.NET addin.

 

I downloaded the 2013 Wizards and templates and have started a Inventor Addin for VB.NET
I've located the Region "ApplicationAddInServer Members" but need a nudge to get started.

 

Any help here?

--- Test VBA Code Follows ---

 

Private Sub CommandButton1_Click()
  Dim myMacro As Inventor.MacroControlDefinition

  'Dim ZeroDocQAControls As Inventor.CommandControls
  Dim PrtQAControls As Inventor.CommandControls
  Dim AssyQAControls As Inventor.CommandControls
  Dim DwgQAControls As Inventor.CommandControls

  'Test macro to set in the quick launch toolbbar.
  Set myMacro = ThisApplication.CommandManager.ControlDefinitions.Item("macro:basLaunch.Dim_Power")
  

  ' What is the Item name for zero document loaded. (NO Part,Assembly, or Drawing Environment)

  'Set ZeroDocQAControls = ThisApplication.UserInterfaceManager.Ribbons.Item("Zero Document").QuickAccessControls
  Set PrtQAControls = ThisApplication.UserInterfaceManager.Ribbons.Item("Part").QuickAccessControls
  Set AssyQAControls = ThisApplication.UserInterfaceManager.Ribbons.Item("Assembly").QuickAccessControls
  Set DwgQAControls = ThisApplication.UserInterfaceManager.Ribbons.Item("Drawing").QuickAccessControls

 

  ' Add Test macro to Quick Access Toolbars.
  'Call ZeroDocQAControls.AddMacro(myMacro)
  Call PrtQAControls.AddMacro(myMacro)
  Call AssyQAControls.AddMacro(myMacro)
  Call DwgQAControls.AddMacro(myMacro)
End Sub

0 Likes
1,882 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

Okay,  I think I have it working in the Addin.

 

A couple of questions though.

 

1)  Since I am not creating any new tabs or for that matter any new Macrodefinitions

Do I need to utilize the FirstTime argument or can I skip it and run my code on every launch?

 

2) What is the Item name for the evironment that has no document loaded?

 

Currently I am trying to use "Zero Document" but that fails.

ZeroDocQAControls = m_inventorApplication.UserInterfaceManager.Ribbons.Item("Zero Document").QuickAccessControls

0 Likes
Message 3 of 6

Anonymous
Not applicable

Okay,  Found "ZeroDoc" was the environment name I was looking for.

 

Everything looks good on the QA toolbar as far as displaying my macros.

Except when I use the cusomize QA toolbar dropdown.

 

If I select some of my macros to be suppressed by unchecking them it doesn't stick.

Next time I load inventor all of them are back on the QA toolbar.

 

How does one keep the customized display status?

 

 

0 Likes
Message 4 of 6

Anonymous
Not applicable

Since no one has responded I guess there is no built in way keep the changes the user makes to the visible state

of an item added to the quick access toolbar.

 

Makes sense if they are being destroyed on Inventor shut down

 

I suppose I could use the deactivate event and save the visible/invisible state of my macros to disk

and restore them on activate.

 

Any other Ideas?

0 Likes
Message 5 of 6

MegaJerk
Collaborator
Collaborator

You should be able to query the Application.Documents.Count (something along those lines) to get the number of documents open (should be 0 if nothing is open), which could give you the logic conditions needed to load buttons. Then after that, if you load a document (On load event) you can have the button loadout change on the fly (maybe!). 

Perhaps you should talk more in detail about what it is you're trying to accomplish. Though I recently started to get into the whole custom toolbar game myself, it might make for a fun adventure and help out some other people if we start a dialog about this now. 😄 




If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes
Message 6 of 6

Anonymous
Not applicable

Since Inventor did away with toolbars, our engineers hate having to use multiple clicks to get at their custom macros.

As a workaround I am writing an addin that populate the quick access bar with macros in 2014.

 

The addin reads a text file that allows/ disallows which macro loads.

all works as expected.

 

The only piece of the puzzle I would like it persistence of the user controled visibliliy state.

Its not a show stopper.  we can live without it.  but it would be nice.

 

--- Sampe of Text file ---

'...

 ZeroDoc : PG_To_PG

'...

Part : Dim_Power
Part : QuickDocs
' Part : PrepareDwgs
' Part : ExportDxf
' Part : PG_To_PG
' Part : ABS_Assy
' Part : Interfere
' Part : DimPrecision
Part : CreatePDF
Part : Swap_SheetMetal_Material
' Part : UpdateOldDrawing
Part : SimplifyPerfs

'...

Assembly : Dim_Power

'...

------

#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

  Dim ZeroDocQAControls As Inventor.CommandControls = m_inventorApplication.UserInterfaceManager.Ribbons.Item("ZeroDoc").QuickAccessControls
  Dim PrtQAControls As Inventor.CommandControls = m_inventorApplication.UserInterfaceManager.Ribbons.Item("Part").QuickAccessControls
  Dim AssyQAControls As Inventor.CommandControls = m_inventorApplication.UserInterfaceManager.Ribbons.Item("Assembly").QuickAccessControls
  Dim DwgQAControls As Inventor.CommandControls = m_inventorApplication.UserInterfaceManager.Ribbons.Item("Drawing").QuickAccessControls

  ' Add Test macro to Quick Access Toolbars.
  Dim sMacros() As String = IO.File.ReadAllLines("C:\Dim_Power\Local DB\PSPMacroBar.txt")

  For Each sMacro As String In sMacros
    If Not sMacro.Contains(":") Then sMacro = ""
    If sMacro.Trim.StartsWith("'") Then sMacro = ""
    If sMacro <> "" Then
    Dim sSeg() As String = sMacro.Split(":"c)
    Dim sEnviron As String = sSeg(0).Trim.ToLower
    Dim sMacroName = sSeg(1).Trim
    sMacroName = "macro:basLaunch." & sMacroName

    Dim myMacro As Inventor.MacroControlDefinition = CType(m_inventorApplication.CommandManager.ControlDefinitions.Item(sMacroName), MacroControlDefinition)

   Select Case sEnviron
     Case "zerodoc"
       ZeroDocQAControls.AddMacro(myMacro)
    Case "part"
       PrtQAControls.AddMacro(myMacro) 
    Case "assembly"
      AssyQAControls.AddMacro(myMacro)
    Case "drawing"
      DwgQAControls.AddMacro(myMacro)
    End Select
  End If
Next

  ZeroDocQAControls = Nothing
  PrtQAControls = Nothing
  AssyQAControls = Nothing
  DwgQAControls = Nothing

 

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

 

---  Addin Activation ---
 

 

 

0 Likes