I am trying to Pass a string argument from VBA to iLogic.
I have the code to add the argument to VBA side.
What is the method to read the argument from the iLogic side?
Seems I do not see any documentation on the topic.
Solved! Go to Solution.
Solved by Gruff. Go to Solution.
What exactly would be the purpose of doing this? Could you simply not accomplish it all using either all VBA or all iLogic?
In a word, no.
I need to display tabular data to the user from VBA.
The VBA listbox can display columns, but is limited to 9 or 10. I need more columns.
I could automate Excel, but that is way too top heavy. Swatting a fly with a sledge hammer.
I the past I wrote an ActiveX dll in VB6 that allowed Rows and Columns to be displayed and scrolled.
That is no longer an option under 2014 Inventor VBA 7 64 bit.
Hence I am looking at an external iLogic rule that calls a VB.NET dll.
This works so far, but I need to pass the data string from VBA to the iLogic rule.
Okay,
I found out how to access a VB.NET form and all its controls when compiled as an addin for inventor from VBA.
This will work and I do not have to have an extra iLogic rule as the go between.
If you want to see how I did it let me know and I will post the code here.
If you have a fully VBA solution then I am all ears as of course i would rather not distribute the addin if I do not need to.
Hi Gruff,
Well you can post the code, I don't think it will hurt ...
My advice would be to stay away from VBA and iLogic as much as possible, .Net add-ins are actually the prefered, most powerful and flexible way to customize Inventor at the moment.
Regrads,
Philippe.
I won't go into detail unless someone asks.
After loading the Autodesk 2013 template into VB.NET add a form and a new class let's call it 'Core'.
In the StandardAddinServer.vb Change the Automation property so it returns an instance of Core.
In the Core class we create a method that launches the form.
This allows us to push data into the form from VBA and / or return data from the addin to VBA.
(The form can of course be as complex as we like.)
For example.
[code]
Imports System.Windows.Forms
Public Class Core
Public Function LaunchGrid(GridData As String) As String
Dim Frm As New frmMain
Frm.GridData = GridData
If Frm.ShowDialog() = DialogResult.OK Then
Return Frm.ReturnFileName
Else
Return ""
End If
End Function
End Class
[/code]
Compile and move the addin and dll files where needed.
From VBA we load the addin and call the method.
[code]
Public Function Run_GridPadAddin(ByVal sGridData As String) As String
Dim addIns As ApplicationAddIns
Dim Addin As ApplicationAddIn
Dim FileName As String
Set addIns = ThisApplication.ApplicationAddIns
On Error Resume Next
' Get GridPadAddin by ClientID (Guid)
Set Addin = addIns.ItemById("{91501A27-D2D3-4914-A145-A2159CCA10AD}")
If Err.Number = 0 Then
Addin.Activate
'Run method LaunchGrid with grid data source return filename if any
FileName = Addin.Automation.LaunchGrid(sGridData)
Else
Err.Clear
MsgBox "Inventor Add-In 'GridPadAddin.dll' not found"
FileName = ""
End If
Set Addin = Nothing
Set addIns = Nothing
Run_GridPadAddin = FileName
End Function
[/code]
It sounds like you have a solution but curious, could you have passed the string to a text parameter? Then use that parameter in your ilogic rule.
Dan
That was the original question. I did not get an answer. I know how to set it up on the VBA side.
What I did not know was how to read the variable on the iLogic side.
It is moot though now that I have a better solution. (No iLogic middle man.)
To get back to the original question, I don't think it is possible, I don't see how you could pass an external parameter to an iLogic rule except with some clunky worarounds like storing the data in a temp file or something like this ...
For people who want to check a full example of using Automation to exchange data between an addin and VBA or an exe, we have couple of blog posts that deal with the topic:
Concerning your previous comments:
A) My apps are in house solutions. Changes for new features or changes come across my desk daily and they expect a quick turn around.
I suppose you provide an updated VBA project to your users then, or they use a project stored on a network location. I don't see how updating an addin dll would be a different and more paiful process.
B) Debugging is a snap in VBA. Addin debugging is downright painful.
You can write .Net code in an external app just to test if it works, you won't have to restart Inventor each time this way.
C) Creating ribbon components for the addin purely through code is convoluted, time consuming, and difficult.
At least to me, and I've been writing VB.NET code for years. Autodesk really needs to provide a lot more examples of creating ribbon interfaces for addins as well as overviews.
We produced an XML parser that helps creating Ribbon items without the need to write code:
http://modthemachine.typepad.com/my_weblog/2012/02/xml-ribbon-builder-design-pattern.html
Thank you for all the links. I look forward to reading them all, especially the last.
Regarding passing variables into and out of an iLogic.
I do not want to belabor the point as I am not a fan iLogic and have a better workaround,
however the iLogic addin "RunExternalRuleWithArguments()" method appears to take a NameValueMap argument.
I just cannot figure out how to unpack it in the iLogic Rule.
Incidentally I find if odd that it also requires an inventor document when it is meant to run an external rule.
[code]
'---VBA Code ---
Public Function RunExternaliLogic(ByVal RequiredDoc As Inventor.Document, ByVal RuleName As String, ByVal sInput As String)
Dim iLogicAuto As Object
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Function
Dim args As NameValueMap
Set args = ThisApplication.TransientObjects.CreateNameValueMap
Call args.Add("InputValue", sInput)
Call args.Add("returnValue", sOutput)
Call iLogicAuto.RunExternalRuleWithArguments(RequiredDoc, RuleName, args)
End Function
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
[/code]
Philippe,
Again thank you for the XML ribbon link.
I am having a lot of difficulties understanding the sample project.
It makes a lot of assumptions as to the users knowledge about the internals of the inventor ribbon.
It is in no way easier to understand than raw code to add a button to the ribbon.
if anything it is more complex.
First thing I ran into is that the code tries to call a file that doesn't exist. "Ribbon_By_Xml_Example.Ribbons.xml"
Should I start a new thread on this topic?
Respectfully Tom,
Yes please start a new thread as it's unrelated to the original post, or you can log comments at the bottom of the Ribbon post.
Thank you,
Philippe.