Can I call a sub routine using a string?

Can I call a sub routine using a string?

JBEDsol
Collaborator Collaborator
1,040 Views
5 Replies
Message 1 of 6

Can I call a sub routine using a string?

JBEDsol
Collaborator
Collaborator

I have a code that traverses an assembly,  However I want to use it as a seperate sub routine that I can use over and over with different codes.  

 

So I need to traverse an assy to change the color of subs, or collect data, etc.  I want a way to input the sub routine I wish to run so that I don't have to keep rewriting the traverse code for every time I want to go through an assy.

 

0 Likes
1,041 Views
5 Replies
Replies (5)
Message 2 of 6

J-Camper
Advisor
Advisor

My first 2 thoughts for this would be

 

1) Set up an external rule to do the traversing based on having the Main assembly as the ActiveDocument.  Then you could run the external rule from the assembly, either manually or calling the rule from another rule.

 

2) Save the sub as a custom snippet, that you can add to any rule you are making with a double click.

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

There actually is a process set up for that exact situation.  The following link touches on this subject, but doesn't really do a great job of fully explaining how it works.

Advanced iLogic Techniques Reference 

The AddVbRule and AddVbFile are both used in this way.  The AddVbRule is for when you want to reference another local rule in the same document, while the AddVbFile is for when you want to reference an external rule.  However, it's not that simple.  The other rule needs to be set up right for it to work.  The "Straight VB code" option needs to be turned on in the rule being referenced, and the code needs to be set-up accordingly.  Any subs, functions, constants, enums, etc. within the referenced rule must be set-up within either the "Class ThisRule" block of code or within a Module, as you would in regular vb.net (outside the iLogic environment).  Many of the convenient objects & references you're used to using within the iLogic add-in, are no longer accessible in that mode, so it can get a bit tricky for folks that don't have a vb.net programming background.  I have used this reference system before though, and it's definitely doable. 

 

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

@JBEDsol 

Here's another couple of posts with similar discussions I was involved in that you might find enlightening.

iLogic: Reusing functions 

Calling Functions from VBA or External rules in local iLogic Rule 

 

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 have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

_dscholtes_
Advocate
Advocate

You could write the code that does the traversing and from within call a specific procedure / function to do what you want. You could pass an argument to the travelling procedure to state which specific procedure you would like to execute, e.g. 

Call TravelOccurences(oAsmCompDef.Occurrences, "UpdateMass")
Call TravelOccurences(oAsmCompDef.Occurrences, "SetHomeViewAndSave")

 

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

@JBEDsol 

Building on the process that @J-Camper mentioned, which can be a bit simpler to set-up/use, here is another link to one of my contribution posts where I show how to send and receive data between iLogic rules.  This way you can send one or more variables/data to the other rule (similar to input variables for a Sub or Function) for it to process, then you can receive resulting variables/data back from it.  It includes two sample iLogic rules to test this functionality.

 

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes