OpenWithOptions for modelstate

OpenWithOptions for modelstate

tobias_wiesendanger
Advocate Advocate
1,020 Views
7 Replies
Message 1 of 8

OpenWithOptions for modelstate

tobias_wiesendanger
Advocate
Advocate

Did anyone ever use openwithoptions for modelstates. The idea is to open something in a defined modelstates. I dont want to change the modelstate after opening. It should open in the correct one directly.

 

I saw that there are options that can be provided but im not exactly sure how to use them. This is what I have so far:

Dim oRefDocs As DocumentsEnumerator
oRefDocs = ThisAssembly.Document.AllReferencedDocuments

Dim fileOpenOptions As NameValueMap
fileOpenOptions = ThisApplication.TransientObjects.CreateNameValueMap

fileOpenOptions.Add("DefaultModelStateInPart", "Quader")

For Each oSubDoc In oRefDocs
	ThisApplication.Documents.OpenWithOptions(oSubDoc.FullDocumentName,fileOpenOptions, True)

Next

This fails on line 10. I think the provided options value is wrong.

 

regards

 

Tobias

0 Likes
Accepted solutions (3)
1,021 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor

The options method will only work when adding a new occurrence see api sample 

 

This forum post changes allready placed documents. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 8

CattabianiI
Collaborator
Collaborator
Accepted solution

Hi @tobias_wiesendanger the option does exist and the name is just "ModelState" and not "DefaultModelStateInPart", check manual here.  

What @A.Acheson is pointing out correctly though is: what you want to do?
open a document? and then you're code is almost ok.
change the active model state in an occurrence? if so check this link Acheson provided: https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-code-to-change-between-model-...)

Message 4 of 8

tobias_wiesendanger
Advocate
Advocate

Hm ok. Im trying to work around a problem when using iLogivVb.Automation.RunRule(someDoc, "someRule")..

It seams that the doc where is rule then is run, doesnt work the same if I open it and then run the rule.

 

Something like this: 

ThisDoc.ActiveModelState = "Quader"

fails with an error.  ThisDoc.ActiveModelState: Cannot set the model state in a member document. (Document name: ModelStateFile.ipt).

0 Likes
Message 5 of 8

tobias_wiesendanger
Advocate
Advocate

Thanks @CattabianiI that works great. I can workaround my problem with that. Code looks something like this:

Dim refDocs As DocumentsEnumerator
refDocs = ThisAssembly.Document.AllReferencedDocuments

Dim fileOpenOptions As NameValueMap
fileOpenOptions = ThisApplication.TransientObjects.CreateNameValueMap
fileOpenOptions.Add("ModelState", "Quader")

Dim subDoc As Document
For Each subDoc In refDocs

	Dim doc As PartDocument
	doc = ThisApplication.Documents.OpenWithOptions(subDoc.FullDocumentName, fileOpenOptions, False)
	iLogicVb.Automation.RunRule(doc, "ModelState")
Next
0 Likes
Message 6 of 8

g.georgiades
Advocate
Advocate
Accepted solution

Hi, you can also wrap the model state using angle brackets exactly like shown to open in different states. You can also use this method to change the model state for an already open document.

 

ThisApplication.Documents.Open("C:\Workspace\testpart.ipt<[Primary]>", True)
ThisApplication.Documents.Open("C:\Workspace\testpart.ipt<Other ModelState>", True)

 

Message 7 of 8

tobias_wiesendanger
Advocate
Advocate

Thats even better. Thanks @g.georgiades 

0 Likes
Message 8 of 8

CattabianiI
Collaborator
Collaborator
Accepted solution

If you want to make the open of the primary model state culture indipendent go with this one:

ThisApplication.Documents.Open("C:\Workspace\testpart.ipt<" & ThisApplication.LanguageTools.CurrentPrimaryModelStateString & ">", True)