Hello all,
I use Teamcenter 9 and NX 8.5.
My parts are named as
part1-A1.prt DB_PART_NO ="part1" and DB_PART_REV = "A1"
part1-A2.prt DB_PART_NO ="part1" and DB_PART_REV = "A2"
part1-A3.prt DB_PART_NO ="part1" and DB_PART_REV = "A3"
My drawings are named as
part1_dr01.prt DB_PART_NO ="part1" and DB_PART_REV = "dr01"
part1_dr02.prt DB_PART_NO ="part1" and DB_PART_REV = "dr02"
part1_dr03.prt DB_PART_NO ="part1" and DB_PART_REV = "dr03"
When in assembly, i want to open the selected part's drawing by a journal.
I will select the part1 with one of the revision A1,A2 or A3
Journal will handle the File-open , search for the part name and find the relevant revision of the drawing of the part
I tried to write many journals but couldn't achieve because my lack of experience.
re: open drawing in TC
I am not currently using a TC install, so I probably won't be able to provide any useful code, but I do have a question. In your description it sounds as if the drawing and model are in two different datasets, is this the case? I've worked on 2 different TC installs, but both of them kept the model (master) and drawing (specification) in the same dataset. If the model and drawing are in the same dataset, this probably has an easy solution. If they are in different datasets, it might be a bit harder.
RE: Journal to open selected part's drawing from assy/Teamcenter
He is something I threw together a while back to do something similar where I work. If you have components selected in the assembly navigator, it will open the drawings for those, otherwise it will open the drawing for the currently viewed part. You will need to modify the code slightly to work with your naming convention in Teamcenter.
'***************************************************************'
'* ¯\(°_o)/¯'
'* Created by Todd Mitchell'
'* Date: 07/31/2014'
'* Program Name: Super Drawing'
'* Description: Open Drawings From Selected Components'
'* Revisions: Initial'
'***************************************************************'
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 SelectedList As New List(Of String)
Dim bolSelected As Boolean = False
Dim objSelected As NXObject
Dim intType As Integer
Dim intSubType As Integer
Sub Main()
Try
AreComponentsSelected()
If bolSelected = False Then
OpenDrawings(workPart.GetStringAttribute("DB_PART_NO") & "/" & workPart.GetStringAttribute("DB_PART_REV"))
Else
For Each selectedcomponent As String in SelectedList
OpenDrawings(selectedcomponent)
Next
End If
SendKeys.SendWait("{F12}") 'Created F12 Hotkey in NX To Switch to Drafting Environment'
Catch ex As Exception
LogError(ex.message)
End Try
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
LogError(ex.message)
End Try
End Sub
Sub OpenDrawings(ByVal OpenMe As String)
Try
Dim strSplitString() As String = Split(OpenMe, "/")
Dim strPartNo As String = strSplitString(0)
Dim strRevNum As String = strSplitString(1)
Dim strOpenString As String = "@DB/" & strPartNo & "/" & strRevNum & "/specification/" & strPartNo & "-DWG01"
Try
theSession.Parts.SetNonmasterSeedPartData(strOpenString)
Dim prtBasePart As BasePart
Dim lsBasePart As PartLoadStatus
prtBasePart = theSession.Parts.OpenBaseDisplay(strOpenString, lsBasePart)
lsBasePart.Dispose()
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()
End Try
Catch ex As Exception
LogError(ex.message)
End Try
End Sub
Sub LogError(ErrorMessage As String)
Dim errPath As String = Path.GetDirectoryName(theSession.ExecutingJournal)
Dim errFile As String = Replace(Path.GetFileName(theSession.ExecutingJournal), ".vb", "")
Using ErrorWriter As New IO.StreamWriter(errPath & "\" & errFile & "_LogError.txt", True)
ErrorWriter.Write(vbCrLf + "Log Entry : ")
ErrorWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString())
ErrorWriter.WriteLine(ErrorMessage)
ErrorWriter.WriteLine("--------------------------------------------------------------")
ErrorWriter.Close
End Using
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module
Hi
Hi
I am very interested in this Journal but don't appear to be able to get it working, can anyone please help?
Our numbering system is:
M-5774-0101-01-A (Master model)
M-5774-0101-01-A-DRG (Specification file)
The "A" is the Revision
below is a recorded journal showing our part naming.
' NX 7.5.5.4
' Journal created by mw111368 on Fri Dec 05 11:13:49 2014 GMT Standard Time
'
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")
theSession.SetUndoMarkName(markId1, "Open Part File Dialog")
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Open Part File")
theSession.DeleteUndoMark(markId2, Nothing)
theSession.SetUndoMarkName(markId1, "Open Part File")
theSession.DeleteUndoMark(markId1, Nothing)
theSession.Parts.SetNonmasterSeedPartData("@DB/G-6045-1040-01/A/specification/G-6045-1040-01-A_DRG")
Dim basePart1 As BasePart
Dim partLoadStatus1 As PartLoadStatus
basePart1 = theSession.Parts.OpenBaseDisplay("@DB/G-6045-1040-01/A/specification/G-6045-1040-01-A_DRG", partLoadStatus1)
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
partLoadStatus1.Dispose()
End Sub
End Module
I have now managed to get
I have now managed to get this Journal working but have realized that our Specification files can have more then one different suffix on the end.
the journal is set to look for "-DRG", but we have also used "_DRG", "-DRG1". can I easily look for all of these variants and open the one that exists?
RE: I have now managed to get
you could define an array of all the string you want/search for and loop through it until you found what you are looking for
Dim arrStrTofind(1) as String
arrStrTofind(0)="_DRG"
arrStrTofind(1)="-DRG1"
For i = 0 to UBound(arrStrTofind)
'position = 0 if character not found
position = InStr("the name you're searching in",arrStrTofind(i))
if position <> 0 Then
Select Case i
Case 0
"open file 1"
Case 1
"open file 2"
"etc"
End Select
Next
Thanks
Regards
Hi
Hi
I am looking to add "-DRG", and "_DRG", but am not experienced enough to do, so would very much appreciated some help.
Regards
Maryn
'***************************************************************'
'* ¯\(°_o)/¯'
'* Created by Todd Mitchell'
'* Date: 07/31/2014'
'* Program Name: Super Drawing'
'* Description: Open Drawings From Selected Components'
'* Revisions: Initial'
'***************************************************************'
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 SelectedList As New List(Of String)
Dim bolSelected As Boolean = False
Dim objSelected As NXObject
Dim intType As Integer
Dim intSubType As Integer
Sub Main()
Try
AreComponentsSelected()
If bolSelected = False Then
OpenDrawings(workPart.GetStringAttribute("DB_PART_NO") & "/" & workPart.GetStringAttribute("DB_PART_REV"))
Else
For Each selectedcomponent As String in SelectedList
OpenDrawings(selectedcomponent)
Next
End If
SendKeys.SendWait("{F12}") 'Created F12 Hotkey in NX To Switch to Drafting Environment'
Catch ex As Exception
LogError(ex.message)
End Try
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
LogError(ex.message)
End Try
End Sub
Sub OpenDrawings(ByVal OpenMe As String)
Try
Dim strSplitString() As String = Split(OpenMe, "/")
Dim strPartNo As String = strSplitString(0)
Dim strRevNum As String = strSplitString(1)
Dim strOpenString As String = "@DB/" & strPartNo & "/" & strRevNum & "/specification/" & strPartNo & "-" & strRevNum & "_DRG1"
Try
theSession.Parts.SetNonmasterSeedPartData(strOpenString)
Dim prtBasePart As BasePart
Dim lsBasePart As PartLoadStatus
prtBasePart = theSession.Parts.OpenBaseDisplay(strOpenString, lsBasePart)
lsBasePart.Dispose()
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()
End Try
Catch ex As Exception
LogError(ex.message)
End Try
End Sub
Sub LogError(ErrorMessage As String)
Dim errPath As String = Path.GetDirectoryName(theSession.ExecutingJournal)
Dim errFile As String = Replace(Path.GetFileName(theSession.ExecutingJournal), ".vb", "")
Using ErrorWriter As New IO.StreamWriter(errPath & "\" & errFile & "_LogError.txt", True)
ErrorWriter.Write(vbCrLf + "Log Entry : ")
ErrorWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString())
ErrorWriter.WriteLine(ErrorMessage)
ErrorWriter.WriteLine("--------------------------------------------------------------")
ErrorWriter.Close
End Using
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module
can someone please help
can someone please help adding an array into this journal as detailed above.
Thanks
Martyn
re: Journal to open selected part's drawing from assy / Teamcent
The code below adds the ability to create a list of commonly used suffixes which it attempts to open until it succeeds.
'***************************************************************'
'* ¯\(°_o)/¯'
'* Created by Todd Mitchell'
'* Date: 07/31/2014'
'* Program Name: Super Drawing'
'* Description: Open Drawings From Selected Components'
'* Revisions: Initial'
'################################################################################################################
' Version History:
' Version | Date | Changed by | Description of change
' --------|------------|---------------|-------------------------------------------------------------------------
' 1.0 | 31/07/2014 | Todd Mitchell | Initial release
' 1.1 | 30/04/2015 | Ian Eldred | Added multiple spec file extension capability
' 1.2 | 30/04/2015 | Ian Eldred | Only switch to drawing mode if a drawing is found. Log errors in NX log file.
'################################################################################################################
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 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"))
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("-DRG")
ExtensionList.Add("-DRG1")
ExtensionList.Add("_DRG")
ExtensionList.Add("_DRG1")
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
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
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module
I am trying to adopt this
I am trying to adopt this code, however when the code can't find the specified filename, NX freezes up. Do you know what might be causing this? I assumed if there are no matches within the try...catch loop, the filename would be ignored and then the code would check the next item on the list?
Is this line of code critical?
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
re: open drawing
If you reply to a comment (be sure to use the "reply" link below the comment you are replying to), an email notification will be sent to the author of the comment (unless he has disabled the notifications). Replying to the comment is your best chance of getting the comment author's attention.
The GetUnloadOption function only affects the code if you compile it into a .dll or .exe file. If you playback the code as a journal, it has no effect.
Hi,
Hi,
I have am trying to adopt your code to open a list of part numbers (from an excel) and then export the notes in the drawing. I have the script for exporting the notes. However, could you help with the catch exception for if the filename is not found? I basically want to just ignore the row with that part number and move onto the next. I'm unfamiliar with the try...catch loops in VB. Thanks!
NX Crashes sometimes
I use this works great, but sometimes NX crashes after loading the drawing dataset. Need to task kill and restart when ever it does.
The log file says +++Licensing toolkit error -- code == -10011 [License Error, cannot return a license that was not checked out or the specified module is not currently checked out.]
Its not linked to any particular assembly or trying to switch from drafting to modelling process, cannot reproduce the error, its random.
BH
re: open drawing
What version of NX are you using?
If you are running NX 1899 or later, you can use the "open related drawing" command instead of this journal.
https://docs.plm.automation.siemens.com/tdoc/nx/1899/nx_help/#uid:index_...
Thanks, thats good to know
Thanks, thats good to know 1899 has it built in.
We are stuck on NX 10.0.3 for now. Because of pandemic we had to postpone upgrade plans.
Any suggestions what I can do to investigate what is triggering the error?
BH
re: open drawing
The pandemic delayed our upgrade as well. I tested the code with TC 10.1.5 and NX 10.0.3; the code works for me as long as a specification exists that follows the naming convention assumed in the journal. Unfortunately, some of my users like to rename the spec file and it failed to open those drawings (but NX did not crash).
Does it return any errors? Check the NX log file, if possible, for clues.