Message 1 of 3

Not applicable
07-22-2021
07:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.