Guest Post by M Veldkamp

Forms are great if you know how to use them. For me, I never really bothered with Forms until quite recently. I’d like to give you some neat tricks I picked up while writing an iLogic Rule.

Maybe you can recognise this situation. I wrote a couple of nice iLogic rules for personal use. Simple tools at first: opening a document and changing a parameter, exporting a drawing to PDF.

Some coworkers started using them as well and in a few months the small simple tools got extra features and more people were interested.

I even have a rule with different ‘flavours’ for different co-workers.

One of these rules I like to call the Bulk Drawing Tool. The BDT runs on assemblies can place a watermark and print and/or export all underlying drawings.

It’s a complicated rule that has a lot of options and a lot of settings.

Lets say the rule can export in either DWG, PDF and DXF. You want to choose per format if you want to save or not.

So what I did at first when I had just 2 or 3 questions to ask, was make Message boxes with a question and that would be fine.

First message box:

Do you want to do DXF? yes/no

Second message box:

Do you want to do DWG export? Yes/no

Third… and fourth

Soon I added more options and the amount of message boxes keep increasing.

This is getting out of hand. Let’s just make a form!

Well… it turns out that to use a form and to ask ‘questions’ to the user you need to store the ‘yes or no’ somewhere.

You can store them in the Parameters so that’s fine but that brings up problem:

You end up adding information to a part that isn’t relevant to the part + Vault users will have to edit their part to use the rule. If they can’t or don’t want to check out a model to use the tool… they won’t.

So the problem is really that you want to store that ‘data’ of the form and the form itself but not in the model itself.

What you can do, apparently, is to go around the problem and use a ipt dedicated to forms.

Here’s the concept

You make a empty part.ipt and add parameters. I named mine like this:

ILOGIC_VariableName

example: ILOGIC_PRINT (it’s a boolean)

I then make a form and drag all the parameters I need into the form and make it look nice.

Here’s an example of how that looks:

An example of a form with just parameters.

So what I do then is save the part. Check it into the vault (so that everyone can access it and has the same file location on C:/)

CODE:

First we deactivate the Vault add-in so we can cheat.

Dim vaultaddin As ApplicationAddInvaultaddin = ThisApplication.ApplicationAddIns.ItemById("{48B682BC-42E6-4953-84C5-3D253B52E77B}") vaultaddin.Deactivate

Next: I don’t want Inventor breathing down my neck asking for permission to edit the file

ThisApplication.SilentOperation = False

Next up is we open the file where all the forms and such are stored:

Dim oModel As PartDocument aFilePath = "C:\CompanyName\Vault\SomeFolder\Form.ipt" oModel = ThisApplication.Documents.Open(aFilePath, False)

Next step is to declare our parameters we want to get . Add some comments to help future you

Dim ILOGIC_PRINT As Boolean 'true = print, false = ignore print Dim ILOGIC_EXPORT As Boolean 'true = export, false = ignore export Dim ILOGIC_PROD_AMOUNT As Integer 'Production amount. Can only be whole numbers Dim ILOGIC_LIBRARY As Boolean 'true = also process LIBRARIES folder, false = ignore LIBRARIES folder Dim ILOGIC_SORT As Boolean 'true = sort by A-Z, False = sort by BOM (per assembly) Dim ILOGIC_PRINT_PREF As String 'Can contain: "A4" or "A3" or "ORIGINALS" Dim ILOGIC_WATERMARK As Boolean 'true = place watermark Dim ILOGIC_PROD_NO As String 'reserved for PROD#. Can be numbers and letters.

Now we can open the form and get the ACTUAL information we want.Some explaination first.

To open the form we need to cheat a bit. We’re first making a rule IN THAT FORM.IPT and that rule can spawn a form. Currently there is no way to spawn a form in another part except for this work arround. If you need further info. Just ask.

IMPORTANT NOTE: The form must be set to Modal so the ONLY the form is active and inventor can’t do stuff in the background. (if you don’t the rule will just get the parameters immediately and ignore the input from the form)

Finally run the rule that opens the form and get the parameters:

auto = iLogicVb.Automationauto.RunRule(oModel, "Show Form1") 'in the model there is a rule called "Show Form" that changes some parameters ILOGIC_PRINT = oModel.ComponentDefinition.Parameters("ILOGIC_PRINT").Value ILOGIC_EXPORT = oModel.ComponentDefinition.Parameters("ILOGIC_EXPORT").Value ILOGIC_PROD_AMOUNT = oModel.ComponentDefinition.Parameters("ILOGIC_PROD_AMOUNT").Value ILOGIC_LIBRARY = oModel.ComponentDefinition.Parameters("ILOGIC_LIBRARY").Value ILOGIC_SORT = oModel.ComponentDefinition.Parameters("ILOGIC_SORT").Value ILOGIC_PRINT_PREF = oModel.ComponentDefinition.Parameters("ILOGIC_PRINT_PREF").Value ILOGIC_WATERMARK = oModel.ComponentDefinition.Parameters("ILOGIC_WATERMARK").Value ILOGIC_PROD_NO = oModel.ComponentDefinition.Parameters("ILOGIC_PROD_NO").Value

The variables that we set now contain the choices that you made in the form.

So in conclusion then: we can (ab)use an ipt to store Forms that we can call in each rule and each document without needing to add parameters for said rule in said document.