Add VbRule in ilogic - link to another part

Add VbRule in ilogic - link to another part

johnster100
Collaborator Collaborator
898 Views
3 Replies
Message 1 of 4

Add VbRule in ilogic - link to another part

johnster100
Collaborator
Collaborator

Hi,

is it possible to use the 'AddVbRule' function to link a rule from one part to another?

 

example: AddVbRule "PartA.ipt", "General Classes"

 

thanks alot,

John

0 Likes
Accepted solutions (1)
899 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

No.  The AddVbRule technique only works with other local rules, within the same document as the source.  The AddVbFile technique works with external iLogic rules as the source.  Not just any local or external iLogic rule will work with these techniques either.  The source rules have to have the "Straight VB Code" option turned on, and they have to be formatted correctly also.

Here is one of the links which mentions these:  https://help.autodesk.com/view/INVNTOR/2021/ENU/?guid=GUID-32B66838-22E4-4A0A-B5BB-862350C76B36

The source rule (the rule you are referencing) must have that option turned on and formatted completely, but the active rule, which is referencing the other rule, doesn't need to have that option turned on, and isn't nearly as sensitive with the formatting.

 

Here is a simple example I often refer to demonstrate this functionality:

  1. Create a new external iLogic rule named "GetFullFileName".
  2. In your Rule Editor, go to the Options tab, then check the option "Straight VB code".
  3. Copy and paste the following code into it, then click [Save], (not Save & Run), then [Close].

 

Class ThisRule
	Public Function GetFullFileName(ByRef oDoc As Inventor.Document) As String
		If oDoc IsNot Nothing Then
			GetFullFileName = oDoc.FullFileName
		End If
	End Function
End Class

 

4. Now at the top of a new rule (with no other code in it), copy and paste the following:

 

AddVbFile "GetFullFileName"

 

(You could specify the full path and file name with extension, if you wanted, but if your external rules are set up correctly, you don't really need to.)

Once you have pasted (or typed) this into your rule, it should immediately (automatically) be moved into the 'Header' area of the rule.  This is OK, and is expected.

5.  Now all we have to do is use this function in this new rule to prove it works, so copy and paste the following into your new rule down below (in the regular part of the rule):

 

MsgBox(GetFullFileName(ThisDoc.Document))

 

Now we're ready to test this new rule, so click [Save & Run].

It should have just shown you a message with the full path and file name of the document that was active when the new rule was ran.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 4

edward_narvaez_jr
Explorer
Explorer
Accepted solution

For anyone else that comes to this... 

If your class is inside a subfolder then that subfolder must be listed in "external rule directories" of "advanced ilogic configuration dialog". Otherwise it won't find it regardless of absolute or relative pathing. 

Message 4 of 4

WCrihfield
Mentor
Mentor

Yep.  I also had to learn that one the hard way.  I now have one main folder where all external iLogic stuff is located, then within that folder, I have a whole bunch of sub folders, each for a different 'category' or 'product type' of external iLogic rules (or related documentation.  I included that main folder, and each of the relevant sub folders containing external rule files.  They really need to fix that so that it can find our rules within sub folders of one main one that we list.  I do usually also include the file extension when using AddVbFile, but not any part of its path.  I do that because I use the .txt file extension, which is too common.  I may change them all at some point to the most specific one (.iLogicVb), but that may be a big project to do, and require some search/replace functionality throughout all my existing rules.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes