MacroControlDefinition does not work in 2014

MacroControlDefinition does not work in 2014

Anonymous
Not applicable
1,577 Views
7 Replies
Message 1 of 8

MacroControlDefinition does not work in 2014

Anonymous
Not applicable

I wrote an addin for Inventor 2013.  It works properly.

Added the same adding for Inventor 2014 and it creates the buttons,

but does not launch the macros as it did in 2013.

 

Nothing happens when you click on the buttons.

 

*** What has changed? ***

 

As I have to install every Inventor seat in the company I want keep the customization as easy as possible.

I have about twelve critical macros that the users want to see at all times.

Since Autodesk took away toolbars after version 2011 I had to come up with something else.

I settled on using the Quick Access Toolbar as it is displayed at all times.

 

The code in my addin opens a file at a fixed location and automatically populates the Quick Access Toolbar with my macros for each environment.

 

[code]
Namespace LoadVbaMacros
<ProgIdAttribute("LoadVbaMacros.StandardAddInServer"), _
GuidAttribute("80678e4b-8fd4-4bd5-a920-2ca75174f845")> _
Public Class StandardAddInServer
  Implements Inventor.ApplicationAddInServer

 

  ' Inventor application object.
  Private m_inventorApplication As Inventor.Application

 

  #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 macrobuttons to the Quick Access Toolbar.
    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

        End if

      End if
    Next

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

End Sub

...
[/code]

0 Likes
1,578 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

 

--- File containing Macro Names ---

--------------------------------------------

 

' This file controls what macros appear in Inventors Quick Access toolbar.

' The format for active macro lines are <Environment> : <Macro Name>

' Empty Lines or Lines that begin with an aposterphy are ignored.
' Note that in ZeroDoc we suppress all but PG_2_PG

' Active Macro lines may be made inactive by using an adding a leading aposterphy
' Use this method instead of deleting a macro line. Never delete a macro.

 

'=== Start Macro Lines ===

' ZeroDoc : Dim_Power
' ZeroDoc : QuickDocs
' ZeroDoc : PrepareDwgs
' ZeroDoc : ExportDxf

ZeroDoc : PG_To_PG

' ZeroDoc : ABS_Assy
' ZeroDoc : Interfere
' ZeroDoc : DimPrecision
' ZeroDoc : CreatePDF
' ZeroDoc : Swap_SheetMetal_Material
' ZeroDoc : UpdateOldDrawing
' ZeroDoc : SimplifyPerfs

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
Assembly : QuickDocs
' Assembly : PrepareDwgs
' Assembly : ExportDxf
' Assembly : PG_To_PG
Assembly : ABS_Assy
Assembly : Interfere
' Assembly : DimPrecision
Assembly : CreatePDF
Assembly : Swap_SheetMetal_Material
' Assembly : UpdateOldDrawing
' Assembly : SimplifyPerfs

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

0 Likes
Message 3 of 8

Mark_Wigan
Collaborator
Collaborator

does this help:

http://usa.autodesk.com/adsk/servlet/ps/dl/item?siteID=123112&id=21623268&linkID=15639655

best regards,
- Mark

(Kudo or Tag if helpful - in case it also helps others)

PDSU 2020 Windows 10, 64bit.

0 Likes
Message 4 of 8

Anonymous
Not applicable

Nope, Still nothing when I click on a macro  button

 

I ran "3rdParty\%platform%\VBA\Vba71033.MSI" from the inventor product design premium 2014 thumb drive that was shipped to me.

 

Something flashed on the screen to quick to follow.

 

Do I need to copy the MSI to my desktop and run it elevated?

 

(Frustrating to load a new product and not have it work.  Especially at the prices we pay.)

 

 

0 Likes
Message 5 of 8

Anonymous
Not applicable

Okay I found the problem.  My addin is working fine.

 

The problem is that VBA is trying to run in 64 bit mode.  (Didn't know that was possible.)

 

Because they crash on load the macros do not run.  (No errors in Inventor)

 

1)  I get an error saying I need to add an attribute called PtrSafe to my Delcare statements.

Did that an things seem to move forward.

 

2) I access several different databases through my macros.

 

Connecting to Access via jet 4.0 throws an error.  Provider not found.

Weird thing is if I fire up 2011 I do not get this error.

 

Connecting to MAS 200 I get an error saying that the ODBC DSN contains an architecture mismatch between the   driver and the application.

 

What can I do to fix the issue?

0 Likes
Message 6 of 8

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

MS provided new VBA which has 64bits version. Inventor 2014 uses it. So now VBA is also running within Inventor process (64bits).

 

Have you tried in other VBA environment such as Excel, Word 2010? If it is reproducible, you would have to consult with MS how to connect Database in VBA. Appreciate if you could share the solution when you get any.

 

0 Likes
Message 7 of 8

Anonymous
Not applicable

So far I've narrowed things down to errors in the VBA code when running 32 bit cide in 64 bit inventor.

VBA 7 is 64 bit.  

 

My assumption is that the code errors out when the button is pressed in my addin and the macro trys to run.

 

I do not get any error messages though.  Notihing happens when you click the button.

 

I've removed the addin for now.  After I ammend my 32 bit code for 64 bit I will try again.

 

0 Likes
Message 8 of 8

ekinsb
Alumni
Alumni

As Xiaodong said, Microsoft has recently provided an update to VBA and it now supports 64-bit.  In previous version of Inventor 64-bit we created a workaround to this by launching a seperate 32-bit process that hosted VBA.  It would then communicate with the 64-bit Inventor.  Communicating between two processes is much slower than being in process and there are also some argument types that can't be passed between processes.  Besides this, the 32-bit workaround seemed to work reasonably well, but we did see occasional weird behavior.

 

With VBA running within Inventor all the issues go away.  However, now there are a few new issues that we've never had to deal with before.  Most people won't see these issues, but a few will.  The first issue is if you're using any Windows API calls.  The declarations will need to be modified to work for 64-bit.  There is documentation from Microsoft on how to do this that you can find by opening Inventor's VBA, going to the Help menu and clicking "Microsoft Visual Basic for Applications Help".  In the contents tree, expand "Visual Basic Conceptual Topics" and the first article is "64-Bit Visual Basic for Applications Overview", as shown below.

 

 

Another issue is that 32-bit components cannot run in a 64-bit process.  That's the problem here, the components you're using to access the database are 32-bit components.  They'll fail to load in 64-bit Inventor.  If you were running 32-bit Windows it would work ok.

 

There are two options that I'm aware of.  The first is to get 64-bit versions of the components.  The second is to write an exe to host your 32-bit component and somehow communicate between VBA and this external process.  The details of doing this will likely be unique to your specific use of the database and could possibly be fairly simple to quite complex.  A simple approach as far as technology use is to write to a file a description of what you need to query for or write to the database and then execute the exe and specify the file as a command line argument.  The exe can read the file, query or write to the database, write any information to a file, and terminate.  The VBA program can then read the file to get the results.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes