'Sample NX Open .NET Visual Basic program : make cgm and tif of all drawing sheets 'Note: 'GTAC provides programming examples for illustration only, and assumes that you are familiar 'with the programming language being demonstrated and the tools used to create and debug procedures. 'GTAC support professionals can help explain the functionality of a particular procedure, but we will 'not modify these examples to provide added functionality or construct procedures to meet your specific needs. ' ------------------------------------------------------------------------- ' 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. ' ' Once we are sure that the CGM has been created, we make the .tif ' ------------------------------------------------------------------------- Option Strict Off Imports System Imports NXOpen Imports NXOpen.Utilities Imports NXOpen.UF Imports NXOpen.Drawings Imports System.Text Module make_cgm_and_tif_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 partName As String = workPart.Leaf.ToString Dim sheetName As String Dim cgmFileName As String Dim tifFileName 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 + "\" + partName + "_" + mySheet.Name + ".cgm" ufs.Ui.SetPrompt("Waiting for CGM file: " & cgmFileName) plot.SaveCgm(mySheet.Tag, jobOptions, JobName, bannerOptions, cgmFileName) ' does the file exist? Dim status As Integer = -1 Do ufs.Cfi.AskFileExist(cgmFileName, status) Loop Until status = 0 ' the CGM is there, so do the conversion tifFileName = tmp_dir + "\" + partName + "_" + mySheet.Name + ".tif" ufs.Ui.SetPrompt("Creating TIFF File..." & tifFileName) ' this is easy but will always use 72 dpi resolution: ' plot.ConvertFile(cgmFileName, UFPlot.Format.TiffFormat, tifFileName) ' So to use a different resolution do this instead: Dim baseDir As String = Nothing ufs.UF.TranslateVariable("UGII_BASE_DIR", baseDir) Dim exPath As String = String.Concat(baseDir, "\NXPLOT\cgm2tiff.exe") Dim proc As New Diagnostics.Process proc.StartInfo.FileName = exPath proc.StartInfo.Arguments = " " & cgmFileName & " " & tifFileName & " -resolution=600 -mono" proc.StartInfo.WindowStyle = Diagnostics.ProcessWindowStyle.Hidden proc.Start() Do ufs.Cfi.AskFileExist(tifFileName, status) Loop Until status = 0 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