Yes, there is a solution for this, but it can be a little complicated to set up.
I usually just use that same strategy that @blandb mentioned, but there is another option made just for this situation too.
I will attempt to describe the steps needed to set this up:
- Place your code for that function in an external rule
- While your still in the rule editor dialog, and that rule is open, go to the Options tab (at the top of the dialog), and check the checkbox next to the option "Straight VB code".
- You will need to change "Private Function" to "Public Function", at the start of your code
- Now on the line just above your Public Function, type "Class ThisRule" (without the quotes)
- Then on the next line after the last line of your function block, type "End Class" (without the quotes)
- Now save that rule, but copy the name of that Function to the clipboard or temporary new Text document, because we will need it when we call it from another rule.
- Now in order to have that function available within another rule:
- At the top of the other rule (or in the Header of that rule, because that's where this line of code will go once you get done typing it), type "AddVbFile" (without the quotes), followed by a single space, then the full path and file name of that external rule you defined the function in (including the file extension). The path and file name should all be within quotes, as you would with any string.
Here is the simplest example I can think of:
Copy and paste this code into an empty external iLogic rule
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
Then check the checkbox next to that setting within the Options tab, called "Straight VB code".
Then Save the rule (without running it).
Now get the full file name and file extension of that rule you just created, and have it ready to insert into the top of the next rule.
Now create a new empty rule (local or external, it doesn't matter), and paste the following code into it:
AddVbFile "S:\Engineering\SHARED\External iLogic\REF FUNCTIONS\GetFullFileName.txt"
MsgBox(GetFullFileName(ThisDoc.Document))
And replace the file path and name string with the one for that last rule you created.
(The active document must be saved before it will retrieve a FullFileName from it, otherwise it will just return a blank string.)
Now run this last rule.
It should have just shown you a message that showed the full file name of the active document.
Notice that you didn't have to specify the referenced function in any special way. It just functions exactly the same as if it were defined within the same rule.
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

(Not an Autodesk Employee)