Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Possible to have a form for selecting a model state when adding a component to an assembly?

11 REPLIES 11
Reply
Message 1 of 12
claudio.ibarra
650 Views, 11 Replies

Possible to have a form for selecting a model state when adding a component to an assembly?

Two use-cases for what I'm looking for:

 

1) You have an IPT for a flange, with model states for various configurations (a dozen or more sizes, blind/slip-on, smooth/o-ring), etc.. One file with many model states. Is it possible to set it up such that when you place that model into an assembly, a custom form appears where you select various parameters to choose which model state you actually want to use in the assembly, instead of choosing from one alphabetical list? 

 

2) You have a component that consists of two flanges connected by a length of pipe. When you place that into an assembly, have a form appear so you can choose the flange sizes (let's keep it simple and say they're the same size and we handle reducers another way), the length between them, and maybe even switch the pipe between them between various shapes (straight length, 1 input for length; angle bend, 1 input for angle, 2 inputs for length; etc). 

 

Are these use-cases possible to achieve with model states and iLogic? 

 

Normally I would try to achieve #1 with something similar to "place ilogic component", but the model states are meant to be somewhat standardized. #2 makes me think "iAssemblies", but I don't know how much flexibility there is with the "pipe between them" and a form. The whole point is to make selection easier with a form so no one has to manually remember some file-naming scheme.

 

Note: Currently using Inventor 2023, latest updates.

Labels (3)
11 REPLIES 11
Message 2 of 12

You can create your own dialog, but before you open the document, you can obtain available model states only as array of strings. If you can build model state name from form control values, you can open or insert the part to the assembly. See the sample part with code sample.

 

Message 3 of 12

I have Inventor 2023, so I can only open this Inventor 2024 part as a derived reference, and it doesn't come with anything besides basic geometry.

Message 4 of 12
WCrihfield
in reply to: Michael.Navara

Hi @Michael.Navara.  I saw the rule within the attached part, where you are utilizing a Windows Form.  Not a bad idea.  Something I have seen, but have not really explored that much yet myself, is the FactoryTableDialog object that we can create through the Inventor application.  That may also be something worth looking into also in this case.  It says that it is for iPart / iAssembly type use, but since the ModelStateTable is laid out pretty much identically, and uses some of the same controls & terms, I am curious to test if it might work with a ModelStates document also.  Just throwing that idea out there.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 12

Message 6 of 12
Michael.Navara
in reply to: WCrihfield

I'm not sure if FactoryTableDialog (or something similar) can work for this purpose because there are few differencies.

iPrats has a table with specified and ordered key columns. This columns and its content can be transformed to selection.

Each row in iPrat table can be identified by key column values. This doesn't work for ModelStates. In my approach I can obtain only list of ModelState names.

Message 7 of 12
WCrihfield
in reply to: Michael.Navara

Hi @Michael.Navara.  In your previous response you mentioned "In my approach I can obtain only list of ModelState names."  Just in case you would prefer to get the actual ModelStates collection object, instead of a String array of their names, below is single line of iLogic code that can be used to retrieve that directly from a Document object.

Dim oMSs As ModelStates = ModelStateUtils.GetModelStates(oDoc)

I don't know if that would be more preferable than the:

Dim modelStates As String() = inventor.FileManager.GetModelStates(fileName)

line or not in this situation though.  Once you have the ModelStates collection object, you could access its ModelStateTable though, I guess.  The ModelStateUtils Class is defined under the Autodesk.iLogic.Runtime Namespace, which is already being referenced in our iLogic rules for us, but they do not include most of these types of tools in their online help documentation, so you can only explore them in the rule editor screen.

As far as a possible alternative to the:

Dim lastModelState As String = inventor.FileManager.GetLastActiveModelState(fileName)

line of code, which could be used with a Document object, instead of a file name String, maybe the Document.ModelStateName property could return the same result, not sure.  There are several other methods under the ModelStateUtils Class, and several other ModelState related Classes under the Autodesk.iLogic.Runtime Namespace, but not sure if any of them would be helpful here.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 12

I am able to open the file, and I can see the 6 model states, but the rule gives me an error when run. 

 

Error on line 16 in rule: SelectModelState, in document: IC_12327593_2022.ipt

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

That attached part is a helpful example, though --- imagine you had a part like that. Is it possible to make an iLogic form that lives with the part, that shows maybe a view of the part and some drop-down boxes and checkboxes to help define the part (that can vary, but for the IC_12327593 part, let's say a checkbox for holes and a drop-down list for length).

 

When adding the part to an assembly, the user picks from the form to choose which model state they want to add to the assembly. Is that possible?

Message 9 of 12
WCrihfield
in reply to: claudio.ibarra

About the error...did you change that full file name being specified in the code to the downloaded part document's new path and name?  If not, you will need to do that before it will work.

 

When editing an iLogic Form, and you have the main, top line item (for the overall form, not something within the form) selected, you will see a property called "Show on Place Component", with a Boolean type value available at the very bottom of the form's properties, under the Behavior sub group.  If you turn that on, that will cause this form to show when inserting this document into an assembly as a component.  However, iLogic Forms to not generally mix well with trying to control multiple ModelStates.  Each ModelState represents a different Document within the one file on disk, and when you launch a global iLogic Form, it will generally remain focused on the document that was active on your screen when the form was first opened, and will not switch its focus to another document while it remains open.  When it is an internal form, its focus will remain on the document that it is saved within.  However, I am not sure how it would be able to change what ModelState the component should represent, because it will already be focused on whatever ModelState that was currently active in that model.  Folks have been trying to change ModelStates using a Multi-Value text type UserParameter to populate a drop-down list in their iLogic forms without much success, because you are only changing the value of that parameter within the currently active ModelState, not the other ModelStates.  It may be possible through the use of additional iLogic rules that are reacting to the value changes in the form though. 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 12
Michael.Navara
in reply to: WCrihfield

I prefer FileManager.GetModelStates(fileName) method because I assume (and not well describe) I don't want to open the file before the user selects the appropriate ModelState. This method allows you to get all ModelStates before the document is opened. Planed steps are as follows:
- Select inventor file
- Read modelStates
- Select one of them or cancel the operation
- When ModelState was selected, open the document
- Place the document to the assembly. (This is the original question.)

If you want to use ModelStateUtils, you need to open document first.


Message 11 of 12

For those steps, would they be running as a separate rule, summoned from the assembly where the selected file will eventually be placed? I've never used FileManager.GetModelStates, but maybe this is a way to accomplish what I'm after.

 

You are correct in assuming that we don't want to open the file before the user selects the appropriate ModelState. Is there any workflow possible where there can be a form with objects like checkboxes/dropdown lists to help the user choose a model state and then place that model state into an assembly? 

 

In the steps below, when the ModelState is selected opened, does the specific ModelState have to be opened discretely and then placed into the assembly (and then manually closed), or can it be placed directly into the assembly?

 


@Michael.Navara wrote:
I prefer FileManager.GetModelStates(fileName) method because I assume (and not well describe) I don't want to open the file before the user selects the appropriate ModelState. This method allows you to get all ModelStates before the document is opened. Planed steps are as follows:
- Select inventor file
- Read modelStates
- Select one of them or cancel the operation
- When ModelState was selected, open the document
- Place the document to the assembly. (This is the original question.)

If you want to use ModelStateUtils, you need to open document first.



 

Message 12 of 12
WCrihfield
in reply to: claudio.ibarra

One of the main steps in the process you are asking for is that you will need to monitor the AssemblyEvents.OnNewOccurrence Event, and catch only the specific events of when you are about to add a component that has multiple ModelStates to that specific assembly document.  I have an example iLogic rule that can create the general event handler, have it focus on one specific assembly document only, then report the details of the event, each time it is triggered, to the iLogic Log window.  You may be able to customize this to respond during the 'kBefore' timing period to review the ComponentDefinition that the new component will be referencing, then launch a custom Windows Form, like @Michael.Navara is suggesting, that might allow you to make some selections, then retrieve the correct ComponentDefinition, to replace the original with, then let that go through.  However, one major detail that worries me about this possibility is that the online documentation for this event says that the HandlingCodeEnum variable is ignored.  If that is the case, I am not sure it would allow the event handler to 'take over' control.  The iLogic rule code is attached as a text file, just in case you still want to look into that angle.  To use it effectively, make sure the correct assembly is visibly open on your screen when you run this rule.  The event handler should go away once that specific assembly document is closed then.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report