Quantcast
Channel: NX Journaling - Journaling / NXOpen API
Viewing all articles
Browse latest Browse all 787

NX Dwg stamp Adding sheet to one sheet Dwg

$
0
0

Hi,
When i try to run the below code (Stamped PDF for QC), If I have one sheet Dwg it is adding empty second sheet while creating the table, If it is multi sheet Dwg I am not getting any issues. Please let me know where is the problem, So that I could correct it.

Option Strict OffImports System
Imports NXOpen
Imports NXOpen.UFImports System.Windows.FormsImports NXOpen.AnnotationsImports NXOpen.UtilitiesImports System.Collections.GenericImports NXOpen.UF.UFDrawImports NXOpen.DrawingsImports System.Windows.Forms.MessageBoxImports System.IOImports System.Collections 
' NX Echeck Stamp' Journal created by Alto on 10-06-2015 
Module NXJournal
 
    Dim theSession As Session = Session.GetSession()Dim workPart As Part = theSession.Parts.WorkDim displayPart As Part = theSession.Parts.DisplayDim ufs As UFSession = UFSession.GetUFSession()Dim ui As UI = ui.GetUI()Dim fontIndex1 AsInteger 
 
    Sub Main()' Create the tabular noteDim taborgin As Point3d =New Point3d(9.72414748499, 2.55025773063, 0)Dim newcolumns AsInteger=3Dim newrows AsInteger=5Dim tabnote As NXOpen.Tag= CreateTabnoteWithSize(newrows, newcolumns, taborgin) 
        ' Get the column tagsDim columns(newcolumns -1)As NXOpen.TagDim rows(newrows)As NXOpen.TagDim i AsIntegerDim j AsIntegerDim height AsDouble=NothingDimwidthAsDouble=NothingFor i =0To newcolumns -1
            ufs.Tabnot.AskNthColumn(tabnote, i, columns(i))
            ufs.Tabnot.AskColumnWidth(columns(i), width)width=0.7
            ufs.Tabnot.SetColumnWidth(columns(i), width)Next 
        For j =0To newrows -1
            ufs.Tabnot.AskNthRow(tabnote, j, rows(j))
            ufs.Tabnot.AskRowHeight(rows(j), height)
            height =0.22
            ufs.Tabnot.SetRowHeight(rows(j), height)Next 
        Dim pt1 As Point =NothingDim cell1 As NXOpen.TagDim cellprefes As UFTabnot.CellPrefs=Nothing
        ufs.Tabnot.AskCellAtRowCol(rows(0), columns(0), cell1)Dim cell2 As NXOpen.Tag
        ufs.Tabnot.AskCellAtRowCol(rows(0), columns(2), cell2)
        ufs.Tabnot.MergeCells(cell1, cell2)Dim cell3 As NXOpen.Tag
        ufs.Tabnot.AskCellAtRowCol(rows(4), columns(0), cell3)Dim cell4 As NXOpen.Tag
        ufs.Tabnot.AskCellAtRowCol(rows(4), columns(2), cell4)
        ufs.Tabnot.MergeCells(cell3, cell4) 
        ufs.Tabnot.AskCellAtRowCol(rows(0), columns(0), cell1)
        ufs.Tabnot.SetCellText(cell1, "IN REVIEW PROCESS CHECK")
        ufs.Tabnot.AskCellAtRowCol(rows(1), columns(0), cell1)
        ufs.Tabnot.SetCellText(cell1, "E CHECK")
        ufs.Tabnot.AskCellAtRowCol(rows(1), columns(1), cell1)
        ufs.Tabnot.SetCellText(cell1, "NOG")
        ufs.Tabnot.AskCellAtRowCol(rows(1), columns(2), cell1)
        ufs.Tabnot.SetCellText(cell1, "CM")
        ufs.Tabnot.AskCellAtRowCol(rows(2), columns(0), cell1)
        ufs.Tabnot.SetCellText(cell1, "CHECK")
        ufs.Tabnot.AskCellAtRowCol(rows(2), columns(1), cell1)
        ufs.Tabnot.SetCellText(cell1, "CERT")
        ufs.Tabnot.AskCellAtRowCol(rows(2), columns(2), cell1)
        ufs.Tabnot.SetCellText(cell1, "ENG APVD")
        ufs.Tabnot.AskCellAtRowCol(rows(3), columns(0), cell1)
        ufs.Tabnot.SetCellText(cell1, "METHODS")
        ufs.Tabnot.AskCellAtRowCol(rows(3), columns(1), cell1)
        ufs.Tabnot.SetCellText(cell1, "FLAM")
        ufs.Tabnot.AskCellAtRowCol(rows(3), columns(2), cell1)
        ufs.Tabnot.SetCellText(cell1, "DESIGN ENG")
        ufs.Tabnot.AskCellAtRowCol(rows(4), columns(0), cell1)
        ufs.Tabnot.SetCellText(cell1, "(IN ACCORDANCE WITH ALL APPLICABLE PROCESSES AND PROCEDURES)")
        ufs.Tabnot.AskCellAtRowCol(rows(4), columns(0), cell4)
        ufs.Tabnot.AskCellPrefs(cell4, cellprefes)
        cellprefes.fit_methods(0)= UFTabnot.FitMethod.FitMethodWrap
        ufs.Tabnot.SetCellPrefs(cell4, cellprefes)
        ufs.Tabnot.AskCellAtRowCol(rows(0), columns(0), cell4)
        ufs.Tabnot.AskCellPrefs(cell4, cellprefes)
        cellprefes.fit_methods(0)= UFTabnot.FitMethod.FitMethodAutoSizeText
        ufs.Tabnot.SetCellPrefs(cell4, cellprefes)For i =0To newrows -1For j =0To newcolumns -1
                ufs.Tabnot.AskCellAtRowCol(rows(i), columns(j), cell1)
                ufs.Tabnot.AskCellPrefs(cell1, cellprefes)
                fontIndex1 = workPart.Fonts.AddFont("ideas_iso")
                cellprefes.format= UFTabnot.Format.FormatText
                cellprefes.text_font= fontIndex1
                cellprefes.text_height=0.05
                cellprefes.text_aspect_ratio=1.0'
                cellprefes.text_angle=0.0
                cellprefes.text_slant=0.0
                cellprefes.line_space_factor=1.0
                cellprefes.char_space_factor=1.0
                cellprefes.text_color=6
                cellprefes.horiz_just= UFTabnot.Just.JustLeft
                cellprefes.vert_just= UFTabnot.Just.JustTop
                ufs.Tabnot.SetCellPrefs(cell1, cellprefes) 
            NextNext 
        For i =0To newcolumns -1
            ufs.Tabnot.AskNthColumn(tabnote, i, columns(i))
            ufs.Tabnot.AskColumnWidth(columns(i), width)width=0.75
            ufs.Tabnot.SetColumnWidth(columns(i), width)Next 
        For j =0To newrows -1
            ufs.Tabnot.AskNthRow(tabnote, j, rows(j))
            ufs.Tabnot.AskRowHeight(rows(j), height)
            height =0.23238
            ufs.Tabnot.SetRowHeight(rows(j), height)Next
        ufs.Tabnot.AskRowHeight(rows(0), height)
        height =0.1
        ufs.Tabnot.SetRowHeight(rows(0), height)
        ufs.Tabnot.AskRowHeight(rows(4), height)
        height =0.2
        ufs.Tabnot.SetRowHeight(rows(4), height) 
        Dim letteringPrefs As LetteringPreferences =NothingDim userSymPrefs As UserSymbolPreferences =Nothing 
        Call Printpdf() 
        Dim notifyOnDelete1 AsBoolean
        notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete 
        theSession.UpdateManager.ClearErrorList() 
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete") 
        Dim objects1(0)As NXObject
        Dim displayableObject1 As DisplayableObject =CType(workPart.FindObject("ENTITY 165 9 1"), DisplayableObject) 
        objects1(0)= displayableObject1
        Dim nErrs1 AsInteger
        nErrs1 = theSession.UpdateManager.AddToDeleteList(objects1) 
        Dim notifyOnDelete2 AsBoolean
        notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete 
        Dim nErrs2 AsInteger
        nErrs2 = theSession.UpdateManager.DoUpdate(markId1)EndSub 
 
    Sub Printpdf() 
        Dim dwgs As Drawings.DrawingSheetCollection
        dwgs = workPart.DrawingSheetsDim sheet As Drawings.DrawingSheetDim i AsIntegerDim pdfFile AsString=NothingDim currentPath AsString=NothingDim currentFile AsString=NothingDim exportFile AsString=NothingDim partUnits AsInteger=NothingDim strOutputFolder AsString=NothingDim strRevision AsString=NothingDim rspFileExists
        Dim rspAdvancePrint =Nothing 
        Dim IsTcEng AsBoolean=FalseDim UFSes As UFSession = UFSession.GetUFSession()
        UFSes.UF.IsUgmanagerActive(IsTcEng) 
        partUnits = displayPart.PartUnits 
        'Read TCE attributesIf IsTcEng Then
            currentFile = workPart.GetStringAttribute("DB_PART_NO")
            strRevision = workPart.GetStringAttribute("DB_PART_REV")EndIf
        exportFile = currentFile
 
        strOutputFolder = OutputPath()'if we don't have a valid directory (ie the user pressed 'cancel') exit the journalIfNotDirectory.Exists(strOutputFolder)ThenExitSubEndIf
        strOutputFolder = strOutputFolder &"\" 
        Dim shts AsNew ArrayList()ForEach sheet In dwgs
            shts.Add(sheet.Name)Next
        shts.Sort() 
        i =0Dim sht AsStringForEach sht In shts
 
            ForEach sheet In dwgs
                If sheet.Name= sht Then
                    i = i +1 
                    If strRevision <> ""Then
                        pdfFile = strOutputFolder & exportFile &"_"& strRevision &".pdf"Else
                        pdfFile = strOutputFolder & exportFile &".pdf" 
                    EndIf 
                    If i =1ThenIfFile.Exists(pdfFile)Then
                            rspFileExists =MsgBox("The file: '"& pdfFile &"' Already exists; overwrite?", vbYesNo + vbQuestion)If rspFileExists = vbYes ThenTryFile.Delete(pdfFile)Catch ex As Exception
                                    MsgBox(ex.Message& vbCrLf &"Journal exiting", vbCritical + vbOKOnly, "Error")ExitSubEndTryElseExitSubEndIfEndIfEndIf 
                    'update any views that are out of date
                    theSession.Parts.Work.DraftingViews.UpdateViews(Drawings.DraftingViewCollection.ViewUpdateOption.OutOfDate, sheet) 
                    Try
                        ExportPDF(sheet, pdfFile, partUnits, rspAdvancePrint)Catch ex As Exception
                        MsgBox("Error occurred in PDF export"& vbCrLf & ex.Message& vbCrLf &"journal exiting", vbCritical + vbOKOnly, "Error")ExitSubEndTryExitForEndIfNext 
        Next 
        If i =0Then
            MessageBox.Show("This part has no drawing sheets to export", "PDF export failure", MessageBoxButtons.OK, MessageBoxIcon.Warning)Else
            MessageBox.Show("Exported: "& i &" sheet(s) to pdf file"& vbCrLf & pdfFile, "PDF export success", MessageBoxButtons.OK, MessageBoxIcon.Information)EndIf 
    EndSub 
    Function OutputPath() 
        Dim strLastPath AsString=Nothing 
        Try
            strLastPath =GetSetting("NX journal", "Export pdf", "ExportPath")Catch e As ArgumentException
        Catch e As Exception
            MsgBox(e.GetType.ToString)FinallyEndTry 
        Dim FolderBrowserDialog1 AsNew FolderBrowserDialog
 
        With FolderBrowserDialog1
            .RootFolder= Environment.SpecialFolder.DesktopIfDirectory.Exists(strLastPath)Then
                .SelectedPath= strLastPath
            Else
                .SelectedPath="H:\"EndIf
            .Description="Select the directory to export .pdf file"If .ShowDialog= DialogResult.OKThen
                OutputPath = .SelectedPathSaveSetting("NX journal", "Export pdf", "ExportPath", .SelectedPath)Else
                OutputPath =0EndIfEndWith 
    EndFunction 
    Sub ExportPDF(dwg As Drawings.DrawingSheet, outputFile AsString, units AsInteger, advancePrint AsInteger) 
        Dim printPDFBuilder1 As PrintPDFBuilder
 
        printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder()
        printPDFBuilder1.Scale=1.0
        printPDFBuilder1.Action= PrintPDFBuilder.ActionOption.Native
        printPDFBuilder1.Colors= PrintPDFBuilder.Color.BlackOnWhite
        printPDFBuilder1.Size= PrintPDFBuilder.SizeOption.ScaleFactorIf units =0Then
            printPDFBuilder1.Units= PrintPDFBuilder.UnitsOption.EnglishElse
            printPDFBuilder1.Units= PrintPDFBuilder.UnitsOption.MetricEndIf
        printPDFBuilder1.XDimension= dwg.Height
        printPDFBuilder1.YDimension= dwg.Length
        printPDFBuilder1.OutputText= PrintPDFBuilder.OutputTextOption.Polylines
        printPDFBuilder1.RasterImages=True
        printPDFBuilder1.ImageResolution= PrintPDFBuilder.ImageResolutionOption.Medium
        printPDFBuilder1.Append=True 
        Dim sheets1(0)As NXObject
        Dim drawingSheet1 As Drawings.DrawingSheet=CType(dwg, Drawings.DrawingSheet) 
        sheets1(0)= drawingSheet1
        printPDFBuilder1.SourceBuilder.SetSheets(sheets1) 
        printPDFBuilder1.Filename= outputFile
 
        Dim nXObject1 As NXObject
        nXObject1 = printPDFBuilder1.Commit() 
        printPDFBuilder1.Destroy() 
    EndSub 
    PublicFunction CreateTabnoteWithSize( _
       ByVal nRows AsInteger, ByVal nColumns AsInteger, ByVallocAs Point3d)As NXOpen.TagDim secPrefs As UFTabnot.SectionPrefs=Nothing
        ufs.Tabnot.AskDefaultSectionPrefs(secPrefs)Dim cellPrefs As UFTabnot.CellPrefs=NothingDim origin(2)AsDouble
        origin(0)=loc.X
        origin(1)=loc.Y
        origin(2)=loc.ZDim tabnote As NXOpen.Tag
        ufs.Tabnot.Create(secPrefs, origin, tabnote)Dim nmRows AsInteger=0
        ufs.Tabnot.AskNmRows(tabnote, nmRows)For ii AsInteger=0To nmRows -1Dim row As NXOpen.Tag
            ufs.Tabnot.AskNthRow(tabnote, 0, row)
            ufs.Tabnot.RemoveRow(row)
            ufs.Obj.DeleteObject(row)NextDim nmColumns AsInteger=0
        ufs.Tabnot.AskNmColumns(tabnote, nmColumns)For ii AsInteger=0To nmColumns -1Dim column As NXOpen.Tag
            ufs.Tabnot.AskNthColumn(tabnote, 0, column)
            ufs.Tabnot.RemoveColumn(column)
            ufs.Obj.DeleteObject(column)Next 
        Dim columns(nColumns -1)As NXOpen.TagFor ii AsInteger=0To nColumns -1If ii =0Then
                ufs.Tabnot.CreateColumn(20, columns(ii))Else
                ufs.Tabnot.CreateColumn(40, columns(ii))EndIf
            ufs.Tabnot.AddColumn(tabnote, columns(ii), UFConstants.UF_TABNOT_APPEND)Next 
        Dim rows(nRows -1)As NXOpen.TagFor ii AsInteger=0To nRows -1
            ufs.Tabnot.CreateRow(10, rows(ii))
            ufs.Tabnot.AddRow(tabnote, rows(ii), UFConstants.UF_TABNOT_APPEND)NextReturn tabnote
 
    EndFunction 
    PublicFunction GetUnloadOption(ByVal dummy AsString)AsIntegerReturn Session.LibraryUnloadOption.ImmediatelyEndFunction 
 
 
End Module

Viewing all articles
Browse latest Browse all 787

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>