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:
'Program: qPlot
'Description: Quickly plot a bannered Checkplot with correctly scaled lineweights for NX9
'Creator: T. Mitchell
'Creation Date: 16DE14
'Version History: 16DE14 - Initial Program
' : 06JL15 - Changed from Registry stored plotter list to DSL Plotter File
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 EV As String = Environment.GetEnvironmentVariable("UGII_TEMPLATE_DIR")
Dim plotterfile As String = EV & "\available_plotters"
Dim myStringElements As Integer = 0
Dim strPlotter(0) As String
' Declarations of the blocks on a qPlot dialog
Dim blkPlotter As Snap.UI.Block.Enumeration
Dim blkPaper As Snap.UI.Block.Enumeration
' Constructor for the qPlot dialog object
Public Sub New()
Me.Title = "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 ThisPlotter As String
Using sr As StreamReader = File.OpenText(plotterfile)
ThisPlotter = sr.ReadLine()
While Not ThisPlotter Is Nothing
ReDim Preserve strPlotter(myStringElements)
strPlotter(myStringElements) = ThisPlotter
myStringElements += 1
ThisPlotter = sr.ReadLine()
End While
End Using
blkPlotter.Items = strPlotter
blkPaper = New Snap.UI.Block.Enumeration()
blkPaper.Label = "Please Select A Plot Scale"
blkPaper.Items = {"Full (1:1)", "Half (2:1)", "Other (11in Roll)"}
' 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()
myForm.Show()
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()
Try
PrepPlot()
Catch ex As Exception
InfoWindow.WriteLine(ex.Message)
End Try
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
End If
End Sub
Public Sub PrepPlot()
Dim strPlotter As String = blkPlotter.SelectedItem
Dim intSelectedSize As Integer = blkPaper.SelectedIndex
Dim module_id As Integer = 0
theUfSession.UF.AskApplicationModule(module_id)
' Get user name
Dim strUserName As String = ""
theUfSession.UF.TranslateVariable("USERNAME", strUserName)
' Get current date and time
Dim CurDateTime As NXOpen.UF.SystemInfo
theUfSession.UF.AskSystemInfo(CurDateTime)
' Get current Sheet
Dim tagSheet As Tag
theUfSession.Draw.AskCurrentDrawing(tagSheet)
' 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
Else
dblDistanceFromRight = 230
dblUserOriginX = 1
End If
' Compute user Y coordinate
If dblSheetLength > 1 Then
dblUserOriginY = 1
Else
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 strCHKPlot As String = "CHECK PLOT - DO NOT USE TO SOURCE OR MANUFACTURE"
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(intSelectedSize), 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)
theSession.UpdateManager.AddToDeleteList(Note1)
theSession.UpdateManager.AddToDeleteList(Note2)
theSession.UpdateManager.DoUpdate(DelMark)
End Sub
Public Sub UFPlotSheet(ByVal sheet As Tag, plotscale As Double, strSelPlotter As String)
' Set Plot Job Variables
Dim myJobOptions As UFPlot.JobOptions
theUfSession.Plot.AskDefaultJobOptions(myJobOptions)
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
theUfSession.Plot.AskDefaultBannerOptions(jobBannerOptions)
' Remove defaulted on banner text
jobBannerOptions.show_banner = False
' Find the default custom pen widths
Dim jobDefaultWidths As UFCgm.CustomWidths
theUfSession.Plot.AskSessionCustomWidths(jobDefaultWidths)
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
Next
jobDefaultWidths.custom = CustomWidths
' Actually set Pen widths!!!
theUfSession.Plot.SetSessionCustomWidths(jobDefaultWidths)
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, "", 1)
' Set widths back to default
Dim SetDefaultWidths As UFCgm.CustomWidths
theUfSession.Plot.AskDefaultCustomWidths(SetDefaultWidths)
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!!!
theUfSession.Plot.SetSessionCustomWidths(SetDefaultWidths)
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
UserNoteBuilder1.Origin.SetInferRelativeToGeometry(True)
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
Else
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
UserNoteBuilder1.Text.TextBlock.SetText(text1)
Dim BannerObject As Annotations.Note
BannerObject = UserNoteBuilder1.Commit()
UserNoteBuilder1.Destroy()
Return BannerObject
End Function
End Class