Relation between model state and view

Relation between model state and view

dhanshri_gavas
Contributor Contributor
162 Views
3 Replies
Message 1 of 4

Relation between model state and view

dhanshri_gavas
Contributor
Contributor

Hi,
  Is there a direct connection between the model state and the view of the document in Inventor? If I want to get a view according to the model state, how can I do that using code? Suppose the Assembly has two model states and, respectively, two views also. Suppose I select the model state 2 and view 1; then what will be visible in the model?

Thanks in advance for your help.

0 Likes
163 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @dhanshri_gavas.  I assume you are talking about regular model screen views of model documents, and not views placed within a drawing type document.  Well, I don't think there is a 'direct' connection between a ModelState and a View, but there is a direct connection between a view and a document, then the document 'can' have sort of a direct association with a ModelState.  Below are a couple links that will help clarify some of that.

Document 

Document.ModelStateName 

Document.Views 

Views 

View 

View.Document 

ModelState.Document 

ModelState.FactoryDocument 

The View object does not have a View.ModelState or View.ModelStateName property directly, just a direct way to access the Document of the View.  Then the Document may, or may not be associated with any ModelState.  Not all Documents have ModelStates.  Documents associated with iParts or iAssemblies are an example of a Document which will not have any ModelStates, because a Document can not have both types of systems in it at the same time.  Most other documents will only have the one original ModelState, and because of that, there will only be one Document for that model file.  When a model file has multiple ModelStates defined in it, then it becomes possible for there to be multiple Documents in that one file.  There can potentially be one Document per ModelState, bot that is not guaranteed.  If you simply create a new ModelState, that by itself does not also create a new Document for that new ModelState.  A new Document gets automatically generated for a ModelState when we place an instance / occurrence of that model into an assembly, set to that ModelState, because a separate 'definition' is needed for that occurrence to reference.  Once there is a Document object for a ModelState, then it may be possible to get that Document from that ModelState through its ModelState.Document property, and if so, you may then be able to use its Views.Add method to create a new view of that Document that is associated with that other ModelState version of a model file.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

WCrihfield
Mentor
Mentor

Since I had not tried this sort of thing before myself, and thought it was an interesting idea, I decided to conduct some local testing.

I wanted to see if it was possible to show multiple model views of the same model file, where each view was looking at a different ModelState version of it.  Well, I got mixed results, which caused me to learn something new about ModelStates that I had not realized before.

 

When I did not have any other assembly files or drawing files open that referenced the model file I was going to be viewing, then I 'invisibly' opened that model file by code using its FullFileName (not FullDocumentName), then accessed its ModelStates, none of its ModelStates had a value for their ModelState.Document property.  This was odd to me, because I knew that every ModelState variation that model file was being referenced by at least one or two assembly files, therefore I thought that there should have been a Document for each of them.  So, to investigate further into this, I opened an assembly in which there were component occurrences referencing each of that model file's ModelStates, then ran this same rule again, and found that each of those same ModelState objects now had a Document as the value of their ModelState.Document property, and I was able to open a separate view of each ModelState version of that model file.  But then to test further, I closed that assembly again, and tried that rule once again, and just as before, when iterating those ModelStates, none had a value for their ModelState.Document property again, so not able to open a view for each of them.

 

In another variation of this testing, where those ModelState documents were not available through that property, I tried a different strategy to access each ModelState version of the one model file, which included the use of the Application.Documents.Open method.  When using that, we can specify the FullDocumentName, which is the FullFileName plus the ModelState name.  To get that value, I used the Application.FileManager.GetFullDocumentName method, where I supplied the FullFileName and the ModelState name as I was iterating through the ModelStates.  That had different results, depending on if I specified True (Visibly open it), or False (invisibly open it).  One version of that testing resulted in 3 visible views where each view had the same ModelState active (the last one).  And another version of that testing resulted in one view, where the 'last' ModelState was 'active'.  It seems that in both cases, the act of 'opening' each ModelState Document had the effect of changing which ModelState was 'active' in the already visible views.  I tried this 3 different ways with the same two types of results.

Complicated thing to try to do. 😅

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 4

hollypapp65
Advocate
Advocate

View Rep and ModelState are independent.

View Rep always use ActiveModelState.

 

Same with PosRep.

 

I setup different ViewRep in assembly to hide parts in drawing views.

Also used PosRep for simple exploded view instead of using ipn.

0 Likes