Is there a way to pass a variable from VBA to an iLogic Rule?

Is there a way to pass a variable from VBA to an iLogic Rule?

Anonymous
Not applicable
6,584 Views
29 Replies
Message 1 of 30

Is there a way to pass a variable from VBA to an iLogic Rule?

Anonymous
Not applicable

We are using Inventor 2011.

 

I have found a rouind about way to display document thumbnails in VBA in 64 bit windows 7 inventor.

 

The only piece of the puzzle I am missing is for a way to push a document object or a document file name into an iLogic Rule from VBA.

 

Any Ideas on how one can do that?

 

 

 

Below is a 64 bit thumbnail solution for VBA sans the input.

 

Essentially I am launching an iLogic Rule from VBA that pushes an inventor document object into a VB.NET dll.

The dll converts the iPictureDisp into a VB.NET image object, reduces the size then converts it into a byte array.

The byte array is passed back to VBA through the same iLogic Rule.

Once the byte array is received it is converted back into an iPictureDisp object.

 

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

' --- VBA Project Form Code ---

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

Option Explicit

 

Private Sub Command1_Click()

 

End Sub

 

 

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

' --- VBA Project Module Code ---

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

Option Explicit

 

Public Sub SetPic(ByRef bBuffer() As Byte)
  Set UserForm1.Pic.Picture = PictureFromRes(bBuffer)
End Sub

 

Public Sub RuniLogic(ByVal DLL_Name As String)
  Dim iLogicAuto As Object
  Dim oDoc As Document
 
  Set oDoc = ThisApplication.ActiveDocument
  If oDoc Is Nothing Then
    MsgBox "Missing Inventor Document"
    Exit Sub
  End If
 
  Set iLogicAuto = GetiLogicAddin(ThisApplication)
  If (iLogicAuto Is Nothing) Then Exit Sub

  iLogicAuto.RunExternalRule oDoc, DLL_Name
End Sub

Function GetiLogicAddin(oApplication As Inventor.Application) As Object
  Dim addIns As ApplicationAddIns
  Set addIns = oApplication.ApplicationAddIns

  Dim addIn As ApplicationAddIn
  Dim customAddIn As ApplicationAddIn
  For Each addIn In addIns
    If (addIn.ClassIdString = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}") Then
      Set customAddIn = addIn
    Exit For
    End If
  Next

  If (customAddIn Is Nothing) Then Exit Function

  customAddIn.Activate
  Set GetiLogicAddin = customAddIn.Automation
End Function

 

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

' --- iLogic External Rule "SaveThumb"  ---

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

 ' Add reference to ThumbNailFix.Dll
AddReference "ThumbNailFix" 

Sub Main()
 Dim oFix As New ThumbNailFix.Fixer
 oFix.Doc = ThisApplication.ActiveDocument
    oFix.SaveThumb
 
 ' Call VBA Sub Routine
 InventorVb.RunMacro("ApplicationProject", "basSandBox", "SetPic", oFix.bBuffer)
End Sub

 

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

' --- VB.NET Compiled ThumbNailFixer Dll Library ---

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

Imports Inventor
Imports System.Drawing
Imports Microsoft.VisualBasic.Compatibility.VB6
Imports System.IO

Public Class Fixer
  Public Property Doc As Inventor.Document = Nothing
  Public Property bBuffer As Byte() = Nothing

  Public Sub SaveThumb()
    Dim imgMemoryStream As MemoryStream = New MemoryStream()
    Dim img As Image = IPictureDispToImage(Doc.Thumbnail)
    Dim imgOut As Image = CType(img.GetThumbnailImage(100, 100, Nothing, New IntPtr), Bitmap)

    imgOut.Save(imgMemoryStream, System.Drawing.Imaging.ImageFormat.Bmp)
    bBuffer = imgMemoryStream.GetBuffer()
  End Sub
End Class

 

0 Likes
6,585 Views
29 Replies
Replies (29)
Message 21 of 30

Anonymous
Not applicable

 

Uninstalled Inventor Developer 2012.

Uninstalled Inventor Developer 2011.

 

VS (Visual Studio) Still displayed and launched the Inventor Addin template.

 

Noticed that 2012 uninstall removed SDK\DeveloperTools Folder and Files 2011 did not.uninstall.

Manually removed SDK\DeveloperTools 2011 Folder and Files.

 

VS Still displayed and launched the Inventor Addin template.

 

Manually removed all Inventor Folders containing VBInventorAddinTemplates.zip Folders

 

VS Still displayed and but errored out when trying to launch the Inventor Addin template.

Ran 2012 Developer Wizards.  Repair.  No change

Ran 2012 Developer Wizards.  Uninstall.  No change

Ran 2012 Developer Wizards.  ReInstalled  No change

 

Thought I hosed the entire thing until I remembered I could restore previous versions of the VS ProjectTemplates and projectTemplatesCache folders.

 

I am back to the 2011 template being offered propertly in Visual Studio.

 

Not sure where to go from here.

0 Likes
Message 22 of 30

MjDeck
Autodesk
Autodesk

I'm not sure what going wrong.  There are two installation steps required.  We should probably be able to combine the two into one, but maybe there's a good reason why two are required.

Try the following.  These folder names should be the right ones for Windows 7.

Close down all Visual Studio sessions.

Uninstall the following software, if installed:

Autodesk Inventor 2011 Developer Tools
Autodesk Inventor 2012 Developer Tools
Autodesk Inventor Wizards

 

Install  DeveloperTools.msi from
C:\Users\Public\Documents\Autodesk\Inventor 2012\SDK

(install for Everyone)


Install  InventorWizards.msi  from
C:\Users\Public\Documents\Autodesk\Inventor 2012\SDK\DeveloperTools\Tools\Wizards


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 23 of 30

Anonymous
Not applicable

Folowed your instructions to the letter.  Except Developer 2011 was already uninstalled.

 

Loaded VS 2010 and started new projects.  The 2011 template is still there under the VisualBasic / Inventor Folder.

(The #Region "COM Registration" is still in Public Class StandardAddInServer)

 

Ah!  Located another Inventor Template under the Visual Basic Folder Directly.  It appears to be the 2012 version.

- See attached image. -

.

If this situation sticks then hopefully I can work with 2012.

I'll rewrite my project in 2012 and get back to you.

 

BTW for future reference it would be a good idea for Inventor templates to display their version number in VS in the template description.

 

0 Likes
Message 24 of 30

Anonymous
Not applicable

Made sure my new 2012 template addin. References the 2011  Interop

--- Addin Process ---

Built the Dll,

Copied the new ThumbFix64Bit.Dll to I:\Program Files\Autodesk\Inventor 2011\Bin.

Copied the new .Addin manifest to I:\Program Data\Autodesk\Inventor 2011\Addin

Loaded Inventor.  Opened from the main menu Tools | Addins.  Selected ThumbFix64Bit.

Checked Load/Unload. Pressed OK. The dalog closes.

Re-opened from Tools | Addins.  ThumbFix64Bit Load/Unload is unchecked.

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

(I assume that if Load/Unload is unchecked then the addin is not loaded.)

 

In any cased ran the VBA code to fire the event and nothing happened.  Again I assume the Addin is not loaded.

 

 

Edited the .Addin Manifest file and changed the inventor version from 16.0 to 15.0.  SupportGreaterThan 15.. to 14..

Same story.  It doesn't appear to be loading.

 

 

0 Likes
Message 25 of 30

MjDeck
Autodesk
Autodesk

Usually when an addin tries to load but can't, it is due to an error in the initialization or activation code within the addin.  It should be fixable.  Do you have a version of Visual Studio other than Visual Basic Express?  It is hard to debug in Visual Basic Express.
 Can you zip up your entire addin project and upload it here?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 26 of 30

Anonymous
Not applicable

I am using Windows7 and VS 2010 Standard edition not express.

 

Attached is the project and the VBA code used to fire the Addin Inventor Event.

 

 

0 Likes
Message 27 of 30

MjDeck
Autodesk
Autodesk

Here's a modified version of your StandardAddInServer.vb source file.  I made a few changes to the declarations and the top function, and the addin will load.  I didn't test the VBA.

The changes reflect the fact that you can't use the m_inventorApplication object in the declarations.  It will not be valid until Sub Activate is called.
 With VS 2010 Standard Editon, you can make a Debug build, and use it to debug your addin running on Inventor.  Set some breakpoints in your code.  Then use Project -> Properties -> Debug -> Start External Program.  Browse to the 2011 Inventor.exe


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 28 of 30

Anonymous
Not applicable

Doh!  Makes sense.

Yep that did it.  It loads and  fires application event as I wanted.

 

Takes a Clipboard filename as input and Returns a String bearing the bytearry via the clipboard.

 

Now I just need to spend some time tweaking my conversions.

 

I will get back on Monday with the results, but I am fairly confident it will work.

 

Thank you for your kind patience. 

 

 

 

0 Likes
Message 29 of 30

Anonymous
Not applicable

The Add-in / VBA code is a success.  Again Thank you for all the time.

I am going to post the attached solution n a new thread so this long winded one can be

archived if you like.

 

The thread title will be:  Fix for Inventor Thumbnails running on 64 bit PCs. 

0 Likes
Message 30 of 30

MjDeck
Autodesk
Autodesk

Glad to hear that it works.  That's a good idea: using the OnApplicationOptionChange and the DisplayOptions.  It doesn't modify any documents, and it should be quick.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes