Windows Forms Called from Rules

Windows Forms Called from Rules

d_stapleton
Contributor Contributor
490 Views
7 Replies
Message 1 of 8

Windows Forms Called from Rules

d_stapleton
Contributor
Contributor

Thanks for the help in advance.

I'm new to Inventor and the Rules, & iLodgic. 

I have created a Windows Form in Visual Studio using VB as the Language.  When I run as an Addin the Form works as it should.  I have tried to run this through Inventor Rules so I can tie it to the part, with no luck.  This is the Form:

d_stapleton_0-1730736733579.png

This is what I have in My Rule:

d_stapleton_1-1730736886717.png

This is the start of the errors I get:

d_stapleton_2-1730737232582.png

Any help would greatly be appreciated!

 

Dan

0 Likes
491 Views
7 Replies
Replies (7)
Message 2 of 8

sergicasadogarcia
Contributor
Contributor

Hi @d_stapleton,

 

I share you the information about AddReference: LINK to documentation 

 

sergicasadogarcia_1-1730785247372.png

 

I think it only supports .dll files , that might be what you’re experiencing. Maybe you need to copy the dll file of the AddReference in C:\Program Files\Autodesk\Inventor [Version]\Bin\iLogicAdd.

 

I've struggled with iLogic many times as well. I believe an Add-In workflow is better for these tasks, as the Visual Studio IDE doesn’t have issues like the one you're facing.

 

Regards.

Sergi Casado.

Please mark a "Solution as solved" when the issue is solved ! And a Like if it helps you.
0 Likes
Message 3 of 8

d_stapleton
Contributor
Contributor

Sergi Casado,

 

I saw that information yesterday and tried it before I tried it with the .exe file.  I had the same issue as I did with the.exe file.  It's like I'm missing something or a lot of somethings to make either work.  I agree with you the Addin's are a lot easier to figure out.  The only reason I wanted to go this route is, I'm trying to figure out a way to program a part file, and have the program be saved, and stored with the part file so they are one.  This way if I copy a part, from one file to another file, the program stays with it.  Maybe I can't do this with Autodesk Inventor like I could with other software.

 

Thanks for your help.

Dan Stapleton

 

 

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

Hi @d_stapleton.  I am not experienced in add-in creation or external exe creation, but I have been pushing the limits of iLogic for years, and have fully created all code required for Windows Forms within some of my iLogic rules (typed in directly, from scratch) and showed them, and handled several of their events, all within a single iLogic rule before.  And sometimes I have referenced an external iLogic rule set to 'Straight VB Code' where the Form's code is contained in a Class, and called it from another, regular rule.  This is definitely possible, so don't give up hope.  But I am not familiar with your files/code, so I am not sure how to advise you about how to 'call' it from a rule.  I usually have to create new 'instance' of my custom Class, using the 'New' keyword, within my rule, then I can use that instance (stored to a local varable in my rule) to Show/Call the form to show.  Since you mentioned this being an add-in, I was a little surprised to see you trying to run an EXE in the rule, instead of trying to call a 'method' to run.  Is your code really designed as an external exe, instead of an add-in?

By the way, I can not download or use a ZIP file from a forum, due to corporate security policies, so attaching your files will not help me to help you, but it might help others.  If you do though, make sure they do not contain anything 'personal/proprietary/confidential'.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

d_stapleton
Contributor
Contributor

Wesley Crihfield,

 

Can you lead me to an example of how you programed a windows form with iLogic Rules.  Just something simple so I can see how it was created.

 

Thanks

Dan Stapleton

0 Likes
Message 6 of 8

WCrihfield
Mentor
Mentor

I have attached two of my 'standalone' (contain all required code) external rules that create a Windows Form, then show it, then react to its events.  The one named WinForm In Rule Example 1 is an older one that I created primarily for learning purposes / practice, and to show how to react to various events of popular controls in a Windows Form.  It does not really interact with any specific Inventor Document.  The other one is also not necessarily for a specific document either, but was a utility for the task of ensuring that specific properties were present, and set to a specific value, in all Inventor files of the specified type in a folder.  It is not necessarily the most efficient way to do things, and is certainly pretty difficult initially to do it this way, but gives us more control than what we have with simple iLogic forms, depending on our needs and the situation.

 

It would have likely been easier to use Visual Studio to design the form, then somehow transfer the required code over into an external iLogic rule, or create a DLL file, and put it into the proper location, so that we could reference it from an iLogic rule, one way or another.  But, even though I do have VS2022 Community installed, and the Inventor SDK stuff installed, I don't think VS is set-up properly or something like that.  I have to rely on our 'corporate' IT dept to do all installations and anything requiring administrative rights, since no one in our entire corporation is allowed to have admin rights on their own computers.  This is what has prevented me from being able to create my own add-ins and/or exe's.  I do not have a degree in software development, so I was not sure what all 'packages' or whatever needed to be downloaded and set-up in it when they installed it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 8

d_stapleton
Contributor
Contributor

Wesley Crihfield,

 

Sorry for the delay.  I have been trying the way you suggested by just putting the code into the Rule.  I have hit a snag, and I don't see anything wrong with the code.  It keeps giving me a Handles code error.  If you get time, please take a look at let me know it you see anything.

d_stapleton_0-1731083997920.png

Here's the error.

d_stapleton_1-1731084150505.png

Do you think it's a protect level?

 

Thanks in advance

Dan Stapleton

0 Likes
Message 8 of 8

WCrihfield
Mentor
Mentor

Hi @d_stapleton.  The 'protection level' phrase you see in the error messages are usually just referring to 'scope' issues.  What I mean is, the level at which the variable was 'declared' (using Dim or similar).  Blocks of code will only recognize a variable that was either declared within that same block of code, or within a 'parent' block of code level.  When it sees you using a variable within a block of code, and it does not recognize it, or can not determine where it was declared, it will give an error or warning like that.

 

Both your code, and the error message shown are just images, so I can not select the text of the code to copy it over into another code window for testing.  It is usually best if you use the 'Insert/Edit code sample' tool in the forum reply tools, to create a code window within your forum reply, then copy your source code, and paste it into that forum code window.  Or, copy the code into a Notepad text file, then save it to C:\Temp, then attach it to the forum reply, as an attachment.  That way we can copy the code into our own code window for quick testing.

 

You obviously did not show all of the code in your rule, because the 'End Class' line is not present.  But if that is all your code except for that one last line of code, then yes, I do see issues that will need to be fixed.

 

This Sub routine looks like it was designed to be an event handler, but where is the 'PictureBox1' object variable declared?...and where is the line of code specifying that this Sub routine is supposed to be 'handling' that event?

WCrihfield_0-1731086492055.png

Same questions about this Sub routine:

WCrihfield_1-1731086571783.png

Where is the 'tbThickness' object variable declared/defined, and did you use WithEvents in the line of code where it is declared/defined?

 

There are two different ways to define what Sub routine will be handling an event.

  • Using 'WithEvents' while declaring/defining the variable of the object that has events, then using the 'Handles' specifier at the end of the Sub routine's signature/definition line, is one of those ways.
  • Using 'AddHandler Object.Event, AddressOf Object_Event' is another way to do it.  The first part specifies the exact event, the second part specified which specific Sub routine will be handling that event.  And if done this way, we also have the option of using the 'RemoveHandler Object.Event, AddressOf Object_Event' phrase to disconnect/remove that event handler.  (Where 'Object' is your 'variable' that represents an object which has an event)

Then there is this line of code within your Sub routine:

WCrihfield_3-1731086988453.png

Where was the variable 'lblParamThickness' declared/defined?

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes