rafl
Mechanical
- May 30, 2011
- 41
I’m working on the journal that will plot current drawing using plot profiles.
My code works only after entering PLOT menu, otherwise it gives an error.
Can someone help me fix this.
My code works only after entering PLOT menu, otherwise it gives an error.
Can someone help me fix this.
Code:
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Drawings
Public Class Program
' class members
Private Shared theSession As Session
Private Shared theUI As UI = UI.GetUI
Private Shared theUfSession As UFSession
Private Shared lw As ListingWindow
' class methods
Public Shared Function Main(ByVal args As String()) As Integer
theSession = Session.GetSession()
theUI = UI.GetUI()
theUfSession = UFSession.GetUFSession()
lw = theSession.ListingWindow
'TODO: Add your application code here
lw.Open()
' check for existing target work part
Dim disp_part As Part = theSession.Parts.Display
If disp_part Is Nothing Then
lw.WriteLine("No displayed part...exit.")
Return 1
End If
Dim sheetCollection As DrawingSheetCollection = disp_part.DrawingSheets
Dim sheetArray As DrawingSheet() = sheetCollection.ToArray()
Dim currentSheet As DrawingSheet = sheetCollection.CurrentDrawingSheet
If currentSheet Is Nothing Then
lw.WriteLine("No current drawing sheet found...exit." & vbLf)
Return 1
End If
Dim noteText As String() = New String(2) {}
Dim sheetNumber As Integer = 0
For ii As Integer = 0 To sheetArray.Length - 1
If currentSheet.Name = sheetArray(ii).Name Then
sheetNumber = ii + 1
Exit For
End If
Next
Dim jobOpts As UFPlot.JobOptions = Nothing
Dim bannerOpts As UFPlot.BannerOptions = Nothing
Dim s As UFSession = UFSession.GetUFSession()
Dim plot As UFPlot = s.Plot
Dim ploter As String = "HP DJ 500 Ploter"
Dim Profile As String = Nothing
Dim ShSize As String
ShSize = currentSheet.Length & "x" & currentSheet.Height
' lw.WriteLine(ShSize.ToString)
If ShSize = "210x297" Then
Profile = "A4"
ElseIf ShSize = "420x297" Then
Profile = "A3"
ElseIf ShSize = "594x420" Then
Profile = "A2"
ElseIf ShSize = "841x594" Then
Profile = "A1"
ElseIf ShSize = "841x1189" Then
Profile = "A0"
End If
plot.AskDefaultJobOptions(jobOpts)
plot.AskDefaultBannerOptions(bannerOpts)
Dim sheet As Tag
s.Draw.AskCurrentDrawing(sheet)
Dim JobName As String
plot.AskDefaultJobName(sheet, JobName)
plot.Print(sheet, jobOpts, JobName, bannerOpts, ploter, Profile, 1)
End Function
Public Shared Function GetUnloadOption(ByVal arg As String) As Integer
'Unloads the image immediately after execution within NX
Return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately)
End Function
End Class