Can't access Part Document from Assembly if Part is not previously set to Master Model State

Can't access Part Document from Assembly if Part is not previously set to Master Model State

logan.andersonD3CSK
Contributor Contributor
317 Views
2 Replies
Message 1 of 3

Can't access Part Document from Assembly if Part is not previously set to Master Model State

logan.andersonD3CSK
Contributor
Contributor

I have an iLogic rule that will place multiple model states of a part file into an assembly, and everything works perfectly as long as the part document has the master model state active, but if any other model state is active, the rule throws an error.

 

To see majority of the code I am using, see the solution for this forum: https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/find-names-of-all-model-states-in-co...

 

In particular, the line of code that throws the error is:

Dim oPDoc As PartDocument = ThisApplication.Documents.ItemByName(filepath)
' filepath is a string with the filepath to the part document on my computer set earlier in the code

 

The error I get is:

loganandersonD3CSK_0-1651265862976.png

loganandersonD3CSK_1-1651266720474.png

 

Due to the error occurring at this point in the rule, I am unable to activate the master model state in the part document via the rule to circumvent this error.

 

  Is anyone else having a similar issue? (I'm trying to figure out if this is a bug in Inventor's programming that can get fixed in an update down the road.)

0 Likes
318 Views
2 Replies
Replies (2)
Message 2 of 3

Ralf_Krieg
Advisor
Advisor

Hello

 

Can you try this? It's untested, so please save before.

Dim oPDoc As PartDocument = ThisApplication.Documents.ItemByName(filepath)
If oPDoc.ComponentDefinition.IsModelStateMember Then
    oPDoc=oPDoc.ComponentDefinition.ModelStates.ActiveModelState.FactoryDocument 
End If
' filepath is a string with the filepath to the part document on my computer set earlier in the code

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 3

CattabianiI
Collaborator
Collaborator

From the ItemByName manual, the filepath parameter is: 

Input String that specifies the Document to return. If only the FullFileName is specified for part and assembly documents, the master document within the file is returned (if it exists in the collection).


In your case you specified a full file name which correspond to the master/primary model state which you'll not have opened.

I don't get from the linked post which is the complete rule, but you could loop through the Application.Documents and compare doc.FullFileName with filepath to get the file you want to work with.

@Ralf_Krieg 
The if in your snippet is after the error.



0 Likes