' -------------------------------------------------------------------------
' This example loops through all the sheets in the part.
' For each sheet, we open the sheet, update all views in it, and then
' create a CGM of that sheet.
' -------------------------------------------------------------------------
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Utilities
Imports NXOpen.UF
Imports NXOpen.Drawings
Imports System.Text
Module make_cgm_of_all_drawing_sheets
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim plot As UFPlot = ufs.Plot
Dim lw As ListingWindow = s.ListingWindow
Sub Echo(ByVal output As String)
s.ListingWindow.Open()
s.ListingWindow.WriteLine(output)
s.LogFile.WriteLine(output)
End Sub
Sub Main()
'
' ----------------------------------------------- make sure we have a part
Dim this_part As NXOpen.Tag
Try
this_part = s.Parts.Work.Tag
Catch ex As Exception
If this_part = NXOpen.Tag.Null Then
MsgBox("You need an open part to run this program.", MsgBoxStyle.OkOnly)
Exit Sub ' no part, so exit program gracefully
End If
End Try
' -------------------------------------------------------------------------
Dim workPart As Part = s.Parts.Work
Dim workView As View = s.Parts.Work.Views.WorkView
Dim drawingSheets As DrawingSheet()
drawingSheets = workPart.DrawingSheets.ToArray
Dim mySheet As DrawingSheet
Dim JobName As String = Nothing
Dim tmp_dir As String = Nothing
Dim outputDir As String = "H:\My Documents\Carls Documents"
If Not IO.Directory.Exists(outputDir) Then
MsgBox("Specified output directory does not exist: " & outputDir, MsgBoxStyle.OkOnly, "Error")
Return
End If
Dim partName As String = workPart.Leaf.ToString
Dim sheetName As String
Dim cgmFileName As String
Dim jobOptions As UFPlot.JobOptions
Dim bannerOptions As UFPlot.BannerOptions = Nothing
plot.AskDefaultJobOptions(jobOptions)
plot.AskDefaultBannerOptions(bannerOptions)
ufs.UF.TranslateVariable("UGII_TMP_DIR", tmp_dir)
For Each mySheet In drawingSheets '----------- Iterate through the sheets
mySheet.Open()
' ------------------------------------------------------------ Update Views
s.Parts.Work.DraftingViews.UpdateViews( _
DraftingViewCollection.ViewUpdateOption.All, mySheet)
' ---------------------------------------------------------------- Plotting
sheetName = "Printing Sheet: " + mySheet.Name
'cgmFileName = tmp_dir + "\" + mySheet.Name + ".cgm"
cgmFileName = IO.Path.Combine(outputDir, mySheet.Name & ".cgm")
' msgbox("cgmFileName: " & cgmFileName)
ufs.Ui.SetPrompt("Waiting for CGM file: " & cgmFileName)
plot.SaveCgm(mySheet.Tag, jobOptions, JobName, bannerOptions, cgmFileName)
Next '------------------------------------------ End of the FOR-NEXT loop
ufs.Ui.SetPrompt("Finished")
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module