passing a value of a variable in VBA to iLogic

passing a value of a variable in VBA to iLogic

mostafamahmoudseddek94
Advocate Advocate
351 Views
2 Replies
Message 1 of 3

passing a value of a variable in VBA to iLogic

mostafamahmoudseddek94
Advocate
Advocate

Hi,

I have created a recursive function that count mass of assemblies/ sub assemblies based on the current view representations.

I created an ilogic rule to set a specific view representation with the correct parts.

I want to calculate the total weight of that view representation to use it later on in a particular drawings

the point is, I want to pass the value of the created global variable in VBA to equal the local variable of the ilogic rule. How can I do that?

Public Global_W As Double
Public Global_STout As String

Sub main()
Global_W = 0
Global_STout = ""

Dim oDOC As AssemblyDocument
Set oDOC = ThisApplication.ActiveDocument

Dim COD As AssemblyComponentDefinition
Set COD = oDOC.ComponentDefinition

Call WeightSubAswembly(oDOC)
MsgBox ("Total Weight: " & oParameter.Value)
End Sub
----------------------------------------------------------------

Sub WeightSubAswembly(AssemblyDoc As AssemblyDocument)
 'some code here
End Sub

I hope I made myself clear;

Regards;

0 Likes
352 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

I don't know what your order of operations is, or how/when your iLogic rule is triggered to run, but if you get the iLogic AddIn within your VBA, then use one of its RunRuleWithArguments type methods, you can create a NameValueMap object, add name/value sets to it, then include that to send to the rule when you run it.  Does that sound like an option you could use.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

If the data you need to send to iLogic is either already a String, or can be easily converted to a String, there is another technique we could try, to see if it will suit your needs.  You could try using the SendPrivateEvent method to send a String type value to Inventor's clipboard from the VBA macro.  Then use the companion method called PeekPrivateEvent to retrieve that String value from Inventor's clipboard.  I haven't used this extensively, but the process works just fine for me in some recent simple tests.

From the VBA macro, you can use something like this:

Dim oStringToSend As String
oStringToSend = "Some Information"
Call ThisApplication.CommandManager.PostPrivateEvent(kStringEvent, oStringToSend)

Then after that, when your iLogic rule runs, you can use some code like this to retrieve that data:

Dim oRetrievedString As String
ThisApplication.CommandManager.PeekPrivateEvent(PrivateEventTypeEnum.kStringEvent, oRetrievedString)
MsgBox("oRetrievedString = " & oRetrievedString, , "")

You can give that a try if you want.

Of course there are also all sorts of ways to write data to something like a Parameter, iProperty, Attribute, text file, etc. that may also work, but I'm guessing you don't want to dirty the document or use external files just to pass this bit of data.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes