' NX 7.5.5.4
'
Option Strict Off
Imports System
Imports System.IO
Imports System.Collections
Imports System.Windows.Forms
Imports System.Windows.Forms.MessageBox
Imports NXOpen
Imports NXOpen.UF
Imports System.Diagnostics
Imports NXOpenUI
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 dwgs As Drawings.DrawingSheetCollection
dwgs = workPart.DrawingSheets
Dim sheet As Drawings.DrawingSheet
Dim currentFile As String
Dim fileAndRev As String
Dim strRevision As String
currentFile = workPart.GetStringAttribute("PARTNUMBER")
strRevision = workPart.GetStringAttribute("DB_PART_REV")
fileAndRev = currentFile & "/" & strRevision
'____________________________________________________________________________________
Dim theUISession As UI = UI.GetUI
Dim sheetName As String
Dim sheetNameString As String
Dim sheetNameInteger As Integer
Dim sheetNameIntegerMinusOne As Integer
Dim totalNumberOfSheets As Integer = 0
Dim lengthOfSheetName As Integer
' ----------------------------------------------
' Menu: File->Plot...
' ----------------------------------------------
Dim plotBuilder1 As PlotBuilder
plotBuilder1 = workPart.PlotManager.CreatePlotBuilder()
plotBuilder1.Copies = 1
plotBuilder1.Tolerance = 0.001
plotBuilder1.RasterImages = True
plotBuilder1.XDisplay = PlotBuilder.XdisplayOption.Right
plotBuilder1.XOffset = 0.15
plotBuilder1.CharacterSize = 0.06
plotBuilder1.Rotation = PlotBuilder.RotationOption.Degree90
plotBuilder1.JobName = fileAndRev
'______________________________________________
For Each sheet In workPart.DrawingSheets
totalNumberOfSheets += 1 'the final totalNumberOfSheets count = the total number of sheets (including the INFO sheet)
Next
totalNumberOfSheets = totalNumberOfSheets - 1 'the final totalNumberOfSheets count = the total number of sheets (NOT including the INFO sheet)
Dim sheets1() As NXObject
Dim filenames1() As String
For Each sheet In workPart.DrawingSheets
sheetName = sheet.Name
lengthOfSheetName = sheetName.Length
If sheetName <> "INFO" Then
If sheetName.Substring(0, 2) = "SH" Then 'test to see if 1st 2 characters = "SH" & bypass "INFO" sheet
If lengthOfSheetName = 3 Then
sheetNameString = sheetName.Substring(2, 1)
End If
If lengthOfSheetName = 4 Then
sheetNameString = sheetName.Substring(2, 2)
End If
If lengthOfSheetName > 3 Then
If sheetName.Substring(3, 1) = "_" Then
sheetNameString = sheetName.Substring(2, 1)
End If
End If
If lengthOfSheetName > 4 Then
If sheetName.Substring(4, 1) = "_" Then
sheetNameString = sheetName.Substring(2, 2)
End If
End If
End If
sheetNameInteger = CInt(sheetNameString)
sheetNameIntegerMinusOne = sheetNameInteger - 1
Dim drawingSheet1 As Drawings.DrawingSheet = CType(workPart.DrawingSheets.FindObject(sheetName), Drawings.DrawingSheet)
ReDim Preserve sheets1(totalNumberOfSheets)
sheets1(sheetNameIntegerMinusOne) = drawingSheet1
ReDim Preserve filenames1(totalNumberOfSheets)
filenames1(sheetNameIntegerMinusOne) = "T:\TEMP\DWG_" & currentFile & strRevision & sheetNameString & ".cgm"
End If
Next
'______________________________________________
plotBuilder1.SourceBuilder.SetSheets(sheets1)
plotBuilder1.PlotterText = "HPGL2_TO_DISK"
plotBuilder1.ProfileText = "compare_tiff_E-J_size"
plotBuilder1.ColorsWidthsBuilder.Colors = PlotColorsWidthsBuilder.Color.BlackOnWhite
plotBuilder1.ColorsWidthsBuilder.Widths = PlotColorsWidthsBuilder.Width.StandardWidths
plotBuilder1.PrinterGroupText = "Plot_Files"
plotBuilder1.SetFilenames(filenames1)
'_________________________________________________________________________
'plot builder code
Try
plotBuilder1.Commit()
Catch ex As NXException
'add code to inspect and handle error
'we'll just show a message box
msgbox(ex.errorcode & ": " & ex.message)
Finally
'any cleanup code you need to run whether there is an error or not
plotBuilder1.Destroy()
End Try
'_________________________________________________________________________
Dim nXObject1 As NXObject
nXObject1 = plotBuilder1.Commit()
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module