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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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