- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Shared Variable of a structure losing structure "Type"
Hello all,
I'm in the process of coding my first iLogic project. I'm having an issue with a shared variable
I have one rule reading data from a CSV file and puting them into a customer parameter Structure.
Public Structure CustomParam Public n As Integer Public Name() As String Public Values As ArrayList End Structure
Dim oCustomParams As ArrayList
oCustomParams = ReadParam(oPath)
SharedVariable("oCustomParams") = oCustomParams
Dim oCustomParam As CustomParam
oCustomParam = ReadParam(oPath_single)
SharedVariable("oCustomParam") = oCustomParam
The data is transfered to other rules correctly and I can access all the data. Both a single variable and an ArrayList of variables work. My issue is that I can't "call" the structure type anymore.
Sub MySub (oCustomParam As CustomParam) ... End Sub Sub MySub (oCustomParam) ... End Sub
The first case will return a "Specified cast is not valid."
Not specifying the argument type will solve the issue. However, I would like if possible to specify the argument as a "CustomParam".
Is there any way to achieve this? Maybe a Structure is not the proper way to handle this. I don't have much coding experience so I may be looking at this wrong.
Thank you in advance for your time and answers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
try it this way!
Public Sub main Dim s As String = "This" MsgBox( main2(s)) End Sub Public Function main2 (s As String) Dim aaa As String = s Return aaa End Function
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm not sure I understand your answer. I don't think I can call function outside the rule in which they are declared.
I'm trying to share a set of data between two (or more) rules which is why I created a shared variable.
The transfer work. I'm not losing any data. However, the data type "CustomParam" that I created is lost in the process.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey@j.haggenjos ,
I'm looking into implementing a similar data structure with external rules. Did you have any luck with resolving this particular challenge, and if so, care to share your findings?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey @KarlH_ ,
Sorry for the delay in my answer. I only see your post now.
I ended up accepting that Shared Variable are undefined object. You can put anything in it and read it in other rules. But I never managed to cast it to a specific type. As long as you are aware of it in your code, you can do pretty much any data transfer between two rules.
I have since then moved to an Inventor AddIn which gives me greater control over what is happening. However, this limitation of Shared Variable was not the reason to move to an AddIn.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @j.haggenjos. There is actually a workflow for doing what you want with iLogic rules, it's just not discussed very much here on the forums for some reason. You can actually build up your own sets of regularly used Public Subs, Functions, Enums, etc., as iLogic rules (as long as they are formatted correctly and have the right settings turned on). Then you can have access to the resources in those other rules by including a special type of reference to those other rule(s) at the top of your new rule.
Here is a link to one online help page that touches on the subject.
Advanced iLogic Techniques Reference
1) In order to prepare an 'external' rule to be used as a reference for resources like this, you first need to more thoroughly prepare/format the code within, similarly to how it might be laid out in regular vb.net, with everything contained within Classes &/or Modules. Then in the Option panel of the iLogic Rule Editor for that rule, turn on the 'Straight VB Code' setting.
2) Then in the new rule (where you want to use a resource from that first rule), either use the AddVBRule followed by the quoted name of the other rule, at the top of the rule, or use the AddVBFile, followed by the quoted path & name of the file to reference code from at the top of the rule.
It can be a bit difficult to get working properly if you're new to programming, because all the usual iLogic snippet type codes won't work like normal within that resource rule, due to how it has to be formatted.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS)
.
If you want and have time, I would appreciate your Vote(s) for My IDEAS
or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you @WCrihfield for the input.
At the time, my workflow was to have a main rule run and call different rules depending on the situations. Shared Variable was my way of having a common dataset.
You are right, I probably could have improved by structuring the code differently and referencing other rules as classes and use the underlying functions instead of simply calling the rules when I needed the code in them.
However, as the complexity of my tool grew, I decided to take the time and move it to an AddIn.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
That's OK too. But just so you know, within the iLogic system, there is also another set of tools for sharing data between rules (and even VBA macros). You may have noticed that some of the lines of code for running another rule include 'arguments' as a NameValueMap. You can use that to send data to the rule that that line is calling to run. Then in the rule that is being called to run, it would need to include a bit of special code at the beginning to retrieve the data being sent to it. The object use there is called "RuleArguments". You can use that to check for and retrieve any data you may be expecting when that rule starts. Here is a link to a contribution posts I created about this process of sending and receiving data between rules, if you are interested.
Wesley Crihfield
(Not an Autodesk Employee)