AddReference inside iLogic code marked as straight VB

AddReference inside iLogic code marked as straight VB

AlexFielder
Advisor Advisor
775 Views
9 Replies
Message 1 of 10

AddReference inside iLogic code marked as straight VB

AlexFielder
Advisor
Advisor

Hi all,

 

I have an issue using the "Addreference" function inside an iLogic rule marked as "StraightVB"

 

Should I be able to use this function with this setting marked true?

0 Likes
Accepted solutions (1)
776 Views
9 Replies
Replies (9)
Message 2 of 10

AlexFielder
Advisor
Advisor

This is an error message I receive:

 

2022-05-06 12_11_44-Rule Compile Errors in 3.VistaSystemPlacement.00.PlaceObjects, in Second Simple .png

And the header for the rule in question looks like this:

 

'AddReference "System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
AddReference "System.IO.Compression.FileSystem"
'AddVbFile "classes\ExtensionsGeneralExtensions"
 
Option Explicit On
Imports Inventor
Imports Microsoft.VisualBasic.FileIO
Imports System
Imports System.IO
Imports System.IO.Compression
Imports System.XML
Imports System.Xml.Serialization
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.Globalization
Imports System.Runtime.CompilerServices

Anybody know why this is happening?

0 Likes
Message 3 of 10

AlexFielder
Advisor
Advisor
Accepted solution

Okay, so I goofed.

 

These were the pair of addreference lines I needed in both the class file and the iLogic Rule only:

 

AddReference "System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
AddReference "System.IO.Compression.FileSystem"

 

 

And then everything behaves and we have access to the correct objects. 

 

<Goes off to contemplate life choices>

0 Likes
Message 4 of 10

fatih_ulus
Explorer
Explorer

@AlexFielder can you provide more details?

I have somethings similar, i made a straight vb code rule, and try to add it as a reference.

Imports Inventor
Imports System.IO
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports System.Text.RegularExpressions
addreference "C:\Workingfolder\JSONService.ilogicvb"

but it gives me an error:
Error on Line 6 : Declaration expected.

 

And I have no idea how to fix it besides adding the code directly into this one, but that goes besides the point of keeping things structured.

 

Thank you!

0 Likes
Message 5 of 10

WCrihfield
Mentor
Mentor

It has been my experience so far that, in the external rule marked as 'Straight VB Code', it will allow all the 'Imports' statements I want to use in its 'Header', but does not allow any 'AddReference' type lines in its 'Header'.  So, I too am curious about this general topic.

 

To work around this limitation, I have always added the required 'AddReference' lines into the 'Header' of the 'regular' rule is referencing that special external rule.  I know the 'regular' rule must have the 'AddVbFile' (followed by the external rule's file name) line in its header, to reference that special external rule.  But I have also been including any required 'AddReference' lines to it, when they were not allowed in the special external rule, to eliminate the errors where it does not recognize the Types that the 'reference' defines.  That system has always been working OK for me, but it never felt like the 'proper / correct' way to do it.

 

It would be nice if the online help page which touches on this basic functionality (Advanced iLogic Techniques Reference) went into more detail (or offered more helpful links) about how these types of 'header' lines needed to be dealt with in those 'Straight VB Code' external rules?  If we really need to include all that 'Version / Culture / PublicKeyToken' related stuff in our headers, then where are we supposed to get all that required information from?  Also if so, why do our regular rules not require that much detail in their 'AddReference' header lines.  I have never had to specify all that before in any regular rule.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 10

AlexFielder
Advisor
Advisor

The AddReference line needs to appear before the Imports statement in order for Inventor to compile the code correctly.

0 Likes
Message 7 of 10

fatih_ulus
Explorer
Explorer

Hmm, can you show me an external rule in which you have done that and it works? Because whatever I try, I can not seem to get it to work.

0 Likes
Message 8 of 10

AlexFielder
Advisor
Advisor

Please take a look at this search of my Github repository:

Code search results

 

AlexFielder_0-1731671328938.png

(screenshot in case it isn't clear what I mean)

 

If you have any further questions please ask 🙂

0 Likes
Message 9 of 10

nick_panzarino
Enthusiast
Enthusiast

I've encountered the same issue with "AddReference" and "Straight VB" rules. Putting the "AddReference" lines only in the "regular" rule does seem to work but it has its limitations. For example, a main benefit of "Straight VB" rules is to re-use functions/code between multiple rules. Requiring those references to be added to every header in addition to the "AddVbFile" breaks the encapsulation of the StraightVB rule and runs the risk of developers forgetting to add the correct references and being unable to diagnose the issue. It would be nice if those references could be added directly to StraightVB rules without breaking things.

Message 10 of 10

JMGunner
Enthusiast
Enthusiast

Better too Add

 

AddVbFile "ilogicUtilsNTI.iLogicVb"

 

the and mapp the folder in  ilogic settings

JMGunner_1-1746798929336.png

 

 

JMGunner_0-1746798926235.png

 

 

0 Likes