Open selected parts from assembly (the opened document must show the correct model state)

Open selected parts from assembly (the opened document must show the correct model state)

Anonymous
Not applicable
418 Views
2 Replies
Message 1 of 3

Open selected parts from assembly (the opened document must show the correct model state)

Anonymous
Not applicable

Hi all,

 

I am using a code posted on this forum in 2018 by lmc.engineering (see code below). This code opens the selected part inside an assembly. The code works fine if the part does not have different model states. For example, part 3 has 3 model states: Master, B and C. If I select part 3 on model state B or C, it will always open the document on model state Master. Is there a way to make the code recognize the model state? I do appreciate any help, thanks =).

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oPart As ComponentOccurrence
Dim sRuleName As String = "My rule Name"
Line1 :
'''Pick part occurrence
oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select Part")
	If oPart Is Nothing Then
		Exit Sub
	Else
		Dim oFileName As String = oPart.Definition.Document.FullFileName
		Dim oDoc As PartDocument = ThisApplication.Documents.Open(oFileName)
		auto = iLogicVb.Automation
			Try
			auto.RunRule(oDoc, sRuleName)
			Catch
				MessageBox.Show("Cannot find a rule with the name " & sRuleName & "." & vbLf & "Please try again.", "Open and run")
			End Try
		'''Close the document with SAVE (as False), without SAVE (As True)
		oDoc.Close(False)
	
		Question = MessageBox.Show("Repeat Command?", "Open and run", MessageBoxButtons.OKCancel)
		If Question = vbOK Then
			''Repeat command
			GoTo Line1
		Else
			Exit Sub
		End If
	End If

 

0 Likes
Accepted solutions (1)
419 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

The easiest way is create new view of the selected document

Dim occ As ComponentOccurrence = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Pick occurrence")
Dim occDoc As Document = occ.Definition.Document

If (occDoc.Views.Count > 0) Then
	occDoc.Views(1).Activate
Else
	occDoc.Views.Add
End If
Message 3 of 3

Anonymous
Not applicable

It works like a charm =D. Thank you so much.

0 Likes