Replacing PartsList Reference with ModelState?

Replacing PartsList Reference with ModelState?

c_hoppen
Advocate Advocate
887 Views
7 Replies
Message 1 of 8

Replacing PartsList Reference with ModelState?

c_hoppen
Advocate
Advocate

Hello,

I need to replace a PartsList reference with a specific ModelState. Ih could use FileDescriptor.ReplaceReference but this only allows me to give a new file name. So I tried this:

 

 

 

	Dim partslist As PartsList = doc.SelectSet.Item(1)
	Dim refDoc As AssemblyDocument = partslist.ReferencedDocumentDescriptor.ReferencedDocument
	Dim mss As ModelStates = refDoc.ComponentDefinition.ModelStates
	Dim ms As ModelState = mss.Item("xxx")
	ms.Activate ' throws an exception
	

 

 

(Assumes  that xxx exists. The active ModelState is primary).

Any chance to do this?

Best

Christoph

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

WCrihfield
Mentor
Mentor

Hi @c_hoppen.  When you created / placed the PartsList initially, did you choose a drawing view to associate it with, or did you choose a file from the file browser directly?  If you choose a view, you could try changing the ModelState that the source view is referencing, and see if that also effects the PartsList that is based on that view.  But I am not sure if that connection is maintained after the creation of the PartsList, because there does not seem to be any exposed method or property of the PartsList for getting or setting a DrawingView directly.  If that does not work, then you may just need to delete then create a new PartsList to replace it.  In a quick test of a new drawing with a single sheet, and single view in it of an assembly with multiple ModelStates, and a PartsList based on that view...if I manually change which ModelState that view is set to, it shows a small interactive dialog letting me know about the change, and asking me if would like to update all PartsLists in this document to use one or the other ModelState instead.  That could be seen as a connection between the view and the PartsList, but that one view in that situation was the only reference to the model document, so it's difficult to judge.  Not sure how we could avoid, or react to that question if attempting to change the ModelState of the view by code though.  It may simply not be shown, and use a default response, or it may throw an error, because we need to answer the question that there is no way to do by code.  Not sure.

WCrihfield_0-1698764156947.png

Edit:  Here is the link to the blue link shown at the bottom of that dialog image above, just for reference:

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-7070AD70-276B-42C7-A163-46B38B9C2465 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 8

c_hoppen
Advocate
Advocate

Hi,

as you told, changing a views' model state will affect a linked parts list.

Unfortunuatelly, my customer linked the parts lists to files instead to a view.

choppen_0-1698764754671.png

After selecting a file you can select the Model State:

choppen_2-1698765209246.png

My idea was to get the associated document (ReferencedDocument) and set the desired model state to active - which fails.

Probably he has to delete the tables and create them again.

Best

Christoph

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

That would be my guess too.  The PartsList.ReferencedDocumentDescriptor  property returns a DocumentDescriptor object, then that DocumentDescriptor object has a property named ReferencedModelState, but that is a ReadOnly property with a value being a variation of the ModelStateTypeEnum, so no luck there.  It would be nice if they were able to make that property (or another similar one) Read/Write, with a String type value (name of the ModelState).

Edit:  The DocumentDescriptor's FullDocumentName property would have been another opportunity to change which ModelState it is pointing to, but nope, that had to be ReadOnly also.  The FullDocumentName would normally contain the name of the ModelState after its FullFileName portion, within "<" & ">" brackets.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

Frederick_Law
Mentor
Mentor

The link is maintained.

I save as drawing and change ModelState in view to make drawings for each ModelState.

I also use this command:

ReplaceRef-01.jpg

Work with or without ModelState.

Maybe look for referenced documents in Drawing Doc.

Don't know if it can be found in Sheet and View.

0 Likes
Message 6 of 8

c_hoppen
Advocate
Advocate

@Frederick_Law  schrieb:

The link is maintained.

I save as drawing and change ModelState in view to make drawings for each ModelState.

I also use this command:

ReplaceRef-01.jpg

Work with or without ModelState.

Maybe look for referenced documents in Drawing Doc.

Don't know if it can be found in Sheet and View.


I can replace references by filename, but not filename + Model State. That's what I asked.

0 Likes
Message 7 of 8

Frederick_Law
Mentor
Mentor

Yes, you can.

Select the file with ModelState and Click Option:

Model State-03.jpg

 

But I think that's may not the problem you have.

0 Likes
Message 8 of 8

c_hoppen
Advocate
Advocate
Yes - you can select filename and model state, but only by UI! I want do it by API.
I know FileDescriptor.ReplaceReference, but this method only takes the FullFileName.
0 Likes