This is the Journal I use to pull up drawings from the Models in the Navigator. I think I got it from this site. I had to add buttload of extra extensions since we don't seem to follow any specific naming convention for our drawings.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpen.UI
Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim workPart = theSession.Parts.Work
Dim theUFS As NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession()
Dim theUI As UI = ui.GetUI
Dim curSession As NXOpen.Session = NXOpen.Session.GetSession()
'Dim lw As ListingWindow = theSession.ListingWindow
Dim lg As LogFile = theSession.LogFile
Dim SelectedList As New List(Of String)
Dim bolSelected As Boolean = False
Dim objSelected As NXObject
Dim intType As Integer
Dim intSubType As Integer
Dim ExtensionList As New List(Of String)
Dim blnFoundSpec As Boolean = False
Sub Main()
'lw.Open()
lg.WriteLine("~~ Journal: Open_Specification.vb ~~")
lg.WriteLine(" timestamp: " & Now)
BuildExtensionList()
Try
lg.WriteLine(" Find out if components are selected.")
AreComponentsSelected()
If bolSelected = False Then
lg.WriteLine(" No components are selected.")
lg.WriteLine(" Open drawing for current work part.")
OpenDrawings(workPart.GetStringAttribute("DB_PART_NO") & "/" & workPart.GetStringAttribute("DB_PART_REV"))
OpenDrawings2(workPart.GetStringAttribute("DB_PART_NO") & "/" & workPart.GetStringAttribute("DB_PART_REV"))
Else
For Each selectedcomponent As String in SelectedList
lg.WriteLine(" Components are selected.")
lg.WriteLine(" Open drawing for selected parts.")
OpenDrawings(selectedcomponent)
OpenDrawings2(selectedcomponent)
Next
End If
If blnFoundSpec Then
curSession.ApplicationSwitchImmediate("UG_APP_DRAFTING")
Else
MessageBox.Show("(NO DWG found)", "", MessageBoxButtons.OK, MessageBoxIcon.Stop)
End If
Catch ex As Exception
lg.WriteLine(" Error in Sub Main: " & ex.Message)
End Try
'lw.Close()
lg.WriteLine("~~ Journal: Open_Specification.vb completed ~~")
lg.WriteLine(" timestamp: " & Now)
End Sub
Sub AreComponentsSelected()
Try
Dim intNumSelected As Integer = theUI.SelectionManager.GetNumSelectedObjects()
If intNumSelected = 0 Then
bolSelected = False
Exit Sub
End If
For i As Integer = 0 To intNumSelected-1
objSelected = theUI.SelectionManager.GetSelectedObject(i)
theUFS.Obj.AskTypeAndSubtype(objSelected.Tag, intType, intSubType)
If intType = UFConstants.UF_component_type Then
Dim theComp As Component = DirectCast(objSelected, Component)
SelectedList.Add(theComp.DisplayName)
bolSelected = True
End If
Next
Catch ex As Exception
lg.WriteLine(" Error in Sub AreComponentsSelected: " & ex.Message)
End Try
End Sub
Sub BuildExtensionList()
'Add new extensions to this list.
'This list should be sorted by most commonly used extension as opening will be attempted in this order.
ExtensionList.Add("-1")
ExtensionList.Add("-Dwg")
ExtensionList.Add("-dwg")
ExtensionList.Add("-DWG")
ExtensionList.Add("_Dwg")
ExtensionList.Add("_dwg")
ExtensionList.Add("_DWG")
End Sub
Sub OpenDrawings(ByVal OpenMe As String)
Dim strExtension As String
Dim strSplitString() As String = Split(OpenMe, "/")
Dim strPartNo As String = strSplitString(0)
Dim strRevNum As String = strSplitString(1)
Dim strOpenString As String = ""
For Each strExtension In ExtensionList
Try
'MessageBox.Show("@DB/" & strPartNo & "/" & strRevNum & "/specification/" & strPartNo & "-" & strRevNum & strExtension)
strOpenString = "@DB/" & strPartNo & "/" & strRevNum & "/specification/" & strPartNo & "-" & strRevNum & strExtension
Try
theSession.Parts.SetNonmasterSeedPartData(strOpenString)
Dim prtBasePart As BasePart
Dim lsBasePart As PartLoadStatus
prtBasePart = theSession.Parts.OpenBaseDisplay(strOpenString, lsBasePart)
lsBasePart.Dispose()
blnFoundSpec = True
Exit For
Catch exc As Exception
Dim prtPart As Part = CType(theSession.Parts.FindObject(strOpenString), Part)
Dim lsPart As PartLoadStatus
Dim status1 As PartCollection.SdpsStatus
status1 = theSession.Parts.SetDisplay(prtPart, False, True, lsPart)
lsPart.Dispose()
blnFoundSpec = True
Exit For
End Try
Catch ex As Exception
lg.WriteLine(" Error in Sub OpenDrawings:")
lg.WriteLine(" " & ex.Message & ": " & strOpenString)
End Try
Next
End Sub
Sub OpenDrawings2(ByVal OpenMe As String)
Dim strExtension As String
Dim strSplitString() As String = Split(OpenMe, "/")
Dim strPartNo As String = strSplitString(0)
Dim strRevNum As String = strSplitString(1)
Dim strOpenString As String = ""
For Each strExtension In ExtensionList
Try
'MessageBox.Show("@DB/" & strPartNo & "/" & strRevNum & "/specification/" & strPartNo & strExtension)
strOpenString = "@DB/" & strPartNo & "/" & strRevNum & "/specification/" & strPartNo & strExtension
Try
theSession.Parts.SetNonmasterSeedPartData(strOpenString)
Dim prtBasePart As BasePart
Dim lsBasePart As PartLoadStatus
prtBasePart = theSession.Parts.OpenBaseDisplay(strOpenString, lsBasePart)
lsBasePart.Dispose()
blnFoundSpec = True
Exit For
Catch exc As Exception
Dim prtPart As Part = CType(theSession.Parts.FindObject(strOpenString), Part)
Dim lsPart As PartLoadStatus
Dim status1 As PartCollection.SdpsStatus
status1 = theSession.Parts.SetDisplay(prtPart, False, True, lsPart)
lsPart.Dispose()
blnFoundSpec = True
Exit For
End Try
Catch ex As Exception
lg.WriteLine(" Error in Sub OpenDrawings:")
lg.WriteLine(" " & ex.Message & ": " & strOpenString)
End Try
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module