AddVbFile within AddVbFile

AddVbFile within AddVbFile

Anonymous
Not applicable
1,619 Views
7 Replies
Message 1 of 8

AddVbFile within AddVbFile

Anonymous
Not applicable

Hi,

 

I'm trying to create a file full of constants.

I'm also trying to access these constants within external .vb files loaded into external rules through `AddVbFile`. But I can't seem to use/nest `AddVbFile` from within the .vb files.

Is this possible? What would the syntax be?

 

Thanks

 

https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/CloudHelp/cloudhelp/2014...

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/add-vbrule-in-ilogic-link-to-another...

0 Likes
1,620 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor

Hi @Anonymous.  Yes, it is possible, just a bit tricky, due to how the strict vb.net code formatting involved in the external rule that you will be referencing.  Here is an extremely simple example you can try out.

Create a new external iLogic rule named "ConstantsRef" (file name is important, but can be different), in your normal location for your other external rules, then copy the following code to a new, empty 'External' iLogic rule (not a local/internal rule):

Class ThisRule
	Const MyConst1 As String = "MyConst1Value"
	Const MyConst2 As String = "MyConst2Value"
	Const MyConst3 As String = "MyConst3Value"
	Const MyConst4 As String = "MyConst4Value"
End Class

Then, on the Options tab, within the iLogic rule editor dialog, check the checkbox next to the "Straight VB Code" setting, because that is required.  Then click the [Save] button (not the [Save & Run] button), then close the iLogic rule editor with the [Close] button.

Now create a new external iLogic rule, and copy the following code into it.

AddVbFile "ConstantsRef"
MsgBox("MyConst1 = " & MyConst1,,"")

That first line will automatically go up into the 'Header' of the rule, leaving the second line down in your regular code window.  Then click Save first, then click the Save & Run button.  You should see the value of that Constant that was created within the other external iLogic rule file. (Just make sure the name of the other rule is the same.)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 8

Anonymous
Not applicable
But can the file that references the constants also be inserted into an external rule via `AddVbFile`, instead of being an external rule itself?
0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

Hi @Anonymous.  I honestly do not know if that is possible or not.  I do know that you can use more than one AddVbFile line within your iLogic rule's 'header', because I have done that before, and it worked OK.  I also know that you can create your own external DLL file with Visual Studio, and add a reference to that in your iLogic rules, but I have never done that myself yet, due to certain work related restrictions.  My attempts to use a third level down rule and use AddVbFile to reference another external rule that is itself also using AddVbFile to reference another external rule, have been 'buggy', always throwing errors.  The bottom level rule will recognize stuff in the file it is immediately referencing, but that bottom level rule will think that the file it is referencing is missing the references it needs for the information it is using from the file it is referencing, because it does not seem to recognize the referenced file's references, so to speak.  However, am not a seasoned 'software developer', just a seasoned Inventor iLogic & VBA coder, and seasoned CNC Programmer, so it is possible that I am missing something in the realm of vb.net that might make that scenario work.  This would be a good question for the folks at Autodesk directly, since they designed that capability, and would know its limitations.

Advanced iLogic Techniques Reference 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 8

Anonymous
Not applicable
Yeah, that's what I was thinking as well. I've been looking into creating DLL files all this morning.
It's a clever idea to try to nest rules to get around the limitation, so it's too bad it doesn't work.
Anyway, thanks for the response
0 Likes
Message 6 of 8

WCrihfield
Mentor
Mentor

Just an added note...or two.  You are probably familiar with running other rules from within existing rules, and maybe even familiar with passing a NameValueMap from one rule to another as the 'arguments' when running the other rule that way, but did you know that you can put a vast variety of stuff as the Value half of a 'pair' within a NameValueMap?  For instance, you can even pass a Document object directly to another rule that way, not just the name of the document.  And you can send a 'List(Of String)' Type object, with all its values included, as the value of a pair in a NameValueMap.  Most folks just assume you can only pass simple String or Numerical values that way, but knowing its greater potential can really open up some possibilities that you may not have considered before, and can really be pretty powerful.  Plus the rule on the receiving end can be set-up to send stuff back to the rule that sent stuff to it as well, or can send stuff on to another rule in a series.  On the receiving rule's side, you can simply check within 'RuleArguments' to see if anything has been passed to it.  If so, you can use those resources.  If not, use alternative resources.  Simple in concept, but certainly widens the field of view when planning a project.  Just thought I would throw that one out there.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 8

Anonymous
Not applicable
Yeah thanks for the tip. In fact I do that a bit already (before I knew about `ThisDoc.Document` I would pass the document in for whichever rules needed it).
What I'm trying to accomplish with this, though, is to consolidate a bunch of repetitive sub and function definitions, and to do that effectively I need to have more than a single layer of 'externalized' code, not just my constants, I've discovered since posting this.
0 Likes
Message 8 of 8

DonStauffer99
Advocate
Advocate

It's a long-standing bug. You can get around it by 1. Stuffing all your classes into a single external rule; or 2. Creating a DLL.

0 Likes