Cancel
Showing results for 
Search instead for 
Did you mean: 

Open drawing, from model

Pioneer
Pioneer

hello all,

 

i have seen one post related to this topic, but when i use the journal provide by @DaveK its not doing any action on my part, can anybody suggest something ?

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 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()
        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"))
			Else
				For Each selectedcomponent As String in SelectedList
                    lg.WriteLine("  Components are selected.")
                    lg.WriteLine("  Open drawing for selected parts.")
                    OpenDrawings(selectedcomponent)
				Next
            End If
            If blnFoundSpec Then
                lg.WriteLine("  Switch to drawing mode using F12 hotkey.")
                'SendKeys.SendWait("{F12}") 'Created F12 Hotkey in NX To Switch to Drafting Environment'
                'Switches to Application Drafting
	            lg.WriteLine("  Begin Switch to Draftin Application.")
                theSession.ApplicationSwitchImmediate("UG_APP_DRAFTING")

                workPart.Drafting.EnterDraftingApplication()
	            lg.WriteLine("  End Switch to Draftin Application.")

            Else
                lg.WriteLine("  No drawing found.")
            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.GetSelectedTaggedObject(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("--DWG")
        ExtensionList.Add("--DWG1")
        ExtensionList.Add("--DWG2")
        ExtensionList.Add("--DWG3")
    End Sub
 
    Sub OpenDrawings(ByVal OpenMe As String)
			
		lg.WriteLine(OpenMe)
        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 = ""
		lg.WriteLine("Inside open Drawing")
		
        For Each strExtension In ExtensionList
            Try
                strOpenString = "@DB/" & strPartNo & "/" & strRevNum & "/specification/" & strPartNo & "-" & strRevNum & strExtension
				lg.WriteLine(strOpenString) 'IRFAN here
                Try
                    theSession.Parts.SetNonmasterSeedPartData(strOpenString)
                    Dim prtBasePart As BasePart
                    Dim lsBasePart As PartLoadStatus = Nothing
                    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

 

thanks,

 

NX 11, TC11

6 REPLIES 6

Re: Open drawing, from model

Legend
Legend

@FORZINDI 

 

Are you opening the drawing from TC?

 

In the post, It looks for drawing with certain extension(Refer BuildExtensionList()). Share us a snap of your dataset

of the part where the drawing reside.

伊尔凡

Re: Open drawing, from model

Pioneer
Pioneer

hello @Irfan23 

 

DATASET.JPG

here you go.

 

thanks.

Re: Open drawing, from model

Honored Contributor
Honored Contributor

The journal from me, is looking for drawing files that end in --dwg1, it looks like yours end in .dwg1, which could be the difference.

 

Have you tried changeing --dwg1, --dwg2, --dwg3, and --dwg4 to .dwg1, etc?

-Dave
NX 11 | Teamcenter 11 | Windows 10

Re: Open drawing, from model

Pioneer
Pioneer
Yes @DaveK I have tried, but with no success.

Thanks

Re: Open drawing, from model

Legend
Legend

@FORZINDI 

 

It chaged somecode based on your snapshot. Now the journal says where it is failing the process. Try to run this journal. Let us know the results. 

 

Refer to @DaveK  post again. 

 

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 lg As ListingWindow = theSession.ListingWindow  
 
	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()
        lg.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"))
			Else
				For Each selectedcomponent As String in SelectedList
                    lg.WriteLine("  Components are selected.")
                    lg.WriteLine("  Open drawing for selected parts.")
                    OpenDrawings(selectedcomponent)
				Next
            End If
            If blnFoundSpec Then
                lg.WriteLine("  Switch to drawing mode using F12 hotkey.")
                SendKeys.SendWait("{F12}") 'Created F12 Hotkey in NX To Switch to Drafting Environment'
            Else
                lg.WriteLine("  No drawing found.")
            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(".dwg")
        ExtensionList.Add(".dwg1")
        ExtensionList.Add("-dwg2")
        ExtensionList.Add("-dwg3")
    End Sub
 
    Sub OpenDrawings(ByVal OpenMe As String)
			
		lg.WriteLine(OpenMe)
        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 = ""
		lg.WriteLine("Inside open Drawing")
		
        For Each strExtension In ExtensionList
            Try
                strOpenString = "@DB/" & strPartNo & "/" & strRevNum & "/specification/" & strPartNo & "-" & strRevNum & strExtension
				lg.WriteLine(strOpenString) 'IRFAN here
                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
伊尔凡
Highlighted

Re: Open drawing, from model

Pioneer
Pioneer

yes @Irfan23 i got it.

 

i just changed "-" to "."  in the below code and it worked nicely, thanks for your help.

 

 strOpenString = "@DB/" & strPartNo & "/" & strRevNum & "/specification/" & strPartNo & "-" & strRevNum & strExtension