Showing results for 
Search instead for 
Do you mean 

SNAP Blockstyler Error

I have been getting the following error: 

Unhandled exception encountered in call back automation code.

 This seems to occur if I exit out of the dialog, re-enter the dialog, and then click either OK or apply. If I switch to the modeling application and back to the drafting application, the file will run with no errors.

The NX log shows:

&MACRO OK 0 0 ! OK Callback  
*** EXCEPTION: Error code  3520041 in line 78 of D:\workdir\Reference\NX903_4\src\part\no\ind\jax_property_container.cxx at Thu May 28 10:23:43 2015 Eastern Daylight Time
+++ Property "BlockID" does not exist for block name ""

Any thought to what I did wrong?


The code:

Option Infer On
Imports Snap, Snap.Create
Imports NXOpen, NXOpen.UF
Imports System

Public Class qPlot : Inherits Snap.UI.BlockForm
    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
    Dim displayPart As Part = theSession.Parts.Display
    Dim strPlotter As String()

    ' Declarations of the blocks on a qPlot dialog
    Dim blkPlotter As Snap.UI.Block.Enumeration
    Dim blkPaper As Snap.UI.Block.Enumeration
    Dim blkRefresh As Snap.UI.Block.Button

    ' Constructor for the qPlot dialog object
    Public Sub New()

        Me.Title = "Nexteer qPlot"  ' Text to be shown in title bar of dialog
        Me.Cue = "Please select Plotter and Size"   ' Text to be shown in cue line

        ' Create an Enumeration blocks (Plotter and Paper)
        blkPlotter = New Snap.UI.Block.Enumeration()
        blkPlotter.Label = "Please select a Plotter"
        Dim strPlotterList As String = ""

            strPlotterList = GetSetting("NX journal", "qPlot", "PlotterList")
        Catch ex As Exception

        End Try

        If strPlotterList.Length < 1 Then
            strPlotter = Split(strPlotterList, "::")
            blkPlotter.Items = strPlotter
        End If

        blkPaper = New Snap.UI.Block.Enumeration()
        blkPaper.Label = "Please Select A Plot Scale"
        blkPaper.Items = {"Full (1:1)", "Half (2:1)", "Other (11in Roll)"}

        ' Create a Button block
        blkRefresh = New Snap.UI.Block.Button()
        blkRefresh.Label = "Refresh Plotter List"

        ' Add all the blocks to the BlockForm
        Me.AddBlocks(blkPlotter, blkPaper, blkRefresh)

    End Sub

    Public Shared Sub Main()

        ' Create and display a qPlot dialog
        Dim myForm = New qPlot()

    End Sub

    Public Overrides Sub OnShow()
        ' Code for when dialog is displayed
    End Sub

    Public Overrides Sub OnOK()
        ' Code for when user clicks OK
    End Sub

    Public Overrides Sub OnApply()
    End Sub

    Public Overrides Sub OnCancel()
        ' Code for when user clicks Cancel
    End Sub

    Public Overrides Sub OnUpdate(changedBlock As Snap.UI.Block.General)

        If changedBlock = blkPlotter Then

        ElseIf changedBlock = blkPaper Then

        ElseIf changedBlock = blkRefresh Then
        End If

    End Sub

    Public Sub GetPlotterList()
        Dim intPrinters As Integer = 0
        theUfSession.Plot.AskPrinterNames(intPrinters, strPlotter)
        Dim strNewPlotterList As String = strPlotter(0)
        For i = 1 To strPlotter.Length - 1
            strNewPlotterList = strNewPlotterList & "::" & strPlotter(i)
        SaveSetting("NX journal", "qPlot", "PlotterList", strNewPlotterList)
        blkPlotter.Items = strPlotter
    End Sub

    Public Sub PrepPlot()
        Dim strPlotter As String = blkPlotter.SelectedItem
        Dim intSelectedSize As Integer = blkPaper.SelectedIndex

        ' Get user name
        Dim strUserName As String = ""
        theUfSession.UF.TranslateVariable("USERNAME", strUserName)

        ' Get current date and time
        Dim CurDateTime As NXOpen.UF.SystemInfo

        ' Get current Sheet
        Dim tagSheet As Tag

        ' Get sheet dimensions
        Dim dwgSheet As Drawings.DrawingSheet = displayPart.DrawingSheets().CurrentDrawingSheet

        Dim dblSheetHeight As Double = dwgSheet.Height
        Dim dblSheetLength As Double = dwgSheet.Length

        Dim dblDistanceFromRight As Double
        Dim dblUserOriginX As Double
        Dim dblUserOriginY As Double

        ' Compute X Coordinates
        If dblSheetLength > 1189 Then
            dblDistanceFromRight = 330
            dblUserOriginX = 101
            dblDistanceFromRight = 230
            dblUserOriginX = 1
        End If

        ' Compute user Y coordinate
        If dblSheetLength > 1 Then
            dblUserOriginY = 1
            dblUserOriginY = 0
        End If

        ' Calculate user note location
        Dim dblCheckPlotXOrigin As Double = (dblSheetLength - dblDistanceFromRight)

        ' Calculate user coordinates
        Dim userX As Double = (dblSheetLength - dblUserOriginX)
        Dim userY As Double = (dblSheetHeight - dblUserOriginY)

        ' Add the check plot notes
        Dim strUser As String = CurDateTime.date_buf & " " & strUserName.ToUpper
        Dim checkPlotNote As Annotations.Note = PlotBanner(dblCheckPlotXOrigin, 12.5, strCHKPlot, 7, 90)
        Dim userPlotNote As Annotations.Note = PlotBanner(userX, userY, strUser, 3.5, 0)
        Dim dbl11inScale As Double = 270 / dblSheetHeight
        Dim dblPlotScale() As Double = {1, 0.5, dbl11inScale}

        ' Plot the Sheet
        UFPlotSheet(tagSheet, dblPlotScale(blkPaper.SelectedIndex), strPlotter)

        ' Delete check plot note
        Dim DelMark As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete Notes")

        Dim Note1 As NXObject = CType(checkPlotNote, NXObject)
        Dim Note2 As NXObject = CType(userPlotNote, NXObject)

    End Sub

    Public Sub UFPlotSheet(ByVal sheet As Tag, plotscale As Double, strSelPlotter As String)

        ' Set Plot Job Variables
        Dim myJobOptions As UFPlot.JobOptions
        myJobOptions.colors = UFPlot.Colors.BlackOnWhite
        myJobOptions.use_drawing_sheet_widths = False
        myJobOptions.widths = UFPlot.Widths.Custom3Widths

        Dim jobName As String
        theUfSession.Plot.AskDefaultJobName(sheet, jobName)

        Dim jobUnits As UFPlot.Units = UFPlot.Units.Millimeters

        Dim jobOrigin() As Double = {0, 0, 0}

        Dim jobBannerOptions As UFPlot.BannerOptions

        ' Remove defaulted on banner text
        jobBannerOptions.show_banner = False

        ' Find the default custom pen widths
        Dim jobDefaultWidths As UFCgm.CustomWidths
        jobDefaultWidths.use = UFCgm.WidthUse.WidthByWidth
        jobDefaultWidths.units = UFConstants.UF_PART_METRIC

        ' Variable to hold new custom pen widths
        Dim CustomWidths() As UFCgm.WidthCustom = jobDefaultWidths.custom
        Dim intNumberOfWidths As Integer = CustomWidths.Length

        For i = 0 To intNumberOfWidths - 1
            CustomWidths(i).Width = CustomWidths(i).Width * plotscale

        jobDefaultWidths.custom = CustomWidths
        ' Actually set Pen widths!!!

        Dim jobExtents As UFPlot.Extents

        ' Add layout to Plot
        theUfSession.Plot.AddJobToPlotLayout(sheet, myJobOptions, jobName, jobUnits, jobOrigin, UFPlot.Rotation.Rotation0, plotscale, jobExtents)

        ' Plot
        theUfSession.Plot.PrintPlotLayout(jobName, jobBannerOptions, strSelPlotter, "<System Profile>", 1)

        ' Set widths back to default
        Dim SetDefaultWidths As UFCgm.CustomWidths
        SetDefaultWidths.use = UFCgm.WidthUse.WidthByWidth
        SetDefaultWidths.units = UFConstants.UF_PART_METRIC
        Dim DefaultWidths() As UFCgm.WidthCustom = SetDefaultWidths.custom
        SetDefaultWidths.custom = DefaultWidths
        ' Actually set pen widths!!!

    End Sub

    Public Function PlotBanner(ByVal userX As Double, _
                    ByVal userY As Double, _
                    ByVal BannerText As String, _
                    ByVal fontheight As Double, _
                    ByVal bannerangle As Double) As Annotations.Note

        Dim nullAnnotations_SimpleDraftingAid As Annotations.SimpleDraftingAid = Nothing

        Dim UserNoteBuilder1 As Annotations.DraftingNoteBuilder
        UserNoteBuilder1 = displayPart.Annotations.CreateDraftingNoteBuilder(nullAnnotations_SimpleDraftingAid)
        UserNoteBuilder1.Origin.Plane.PlaneMethod = Annotations.PlaneBuilder.PlaneMethodType.XyPlane
        If fontheight = 7 Then
            UserNoteBuilder1.Origin.Anchor = Annotations.OriginBuilder.AlignmentPosition.BottomLeft
            Dim fontIndex2 As Integer
            fontIndex2 = displayPart.Fonts.AddFont("lubalins")
            UserNoteBuilder1.Style.LetteringStyle.GeneralTextFont = fontIndex2
            UserNoteBuilder1.Origin.Anchor = Annotations.OriginBuilder.AlignmentPosition.TopRight
        End If

        Dim nullView As View = Nothing
        Dim notepoint As Point3d = New Point3d(userX, userY, 0.0)
        UserNoteBuilder1.Origin.Origin.SetValue(Nothing, nullView, notepoint)
        UserNoteBuilder1.Style.LetteringStyle.Angle = bannerangle
        UserNoteBuilder1.Style.LetteringStyle.GeneralTextSize = fontheight
        Dim text1(0) As String
        text1(0) = BannerText

        Dim BannerObject As Annotations.Note
        BannerObject = UserNoteBuilder1.Commit()

        Return BannerObject
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function

End Class