Below is the code which is available in this site, I am interested in getting view latter, but when i am executing the below code i am getting below error
System.ArgumentNullException: value cannot be null
Parameter Name: s
at System.Text.UTF8Encoding.GetByteCount(string chars)
at NXOpen.UF.Util.ConertStructStringstoUTF8(object inStruct, Object outStruct, Dictionary` array_len_info)
at NXOpen.UF.UFDraw.AskViewLabelParms(tag view_label_tag, ViewLabelParms_ view_label_parms)
Can you please help me to get view label
code is here
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim ufSession As UFSession = ufSession.GetUFSession
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const undoMarkName As String = "view label size factor"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim validViewParms As Integer = -1
For Each temp As Drawings.DraftingView In workPart.DraftingViews
'lw.WriteLine(temp.Name)
'lw.WriteLine("view label shown: " & temp.Style.General.ViewLabel.ToString)
'lw.WriteLine("scale label shown: " & temp.Style.General.ScaleLabel.ToString)
'lw.WriteLine("")
'if neither the view label nor scale label is shown, skip to next view
If Not (temp.Style.General.ViewLabel Or temp.Style.General.ScaleLabel) Then
Continue For
End If
Dim myLabel As UFDraw.ViewLabelParms = New UFDraw.ViewLabelParms
Dim viewLabelTag As Tag
ufSession.Draw.AskViewLabel(temp.Tag, viewLabelTag)
validViewParms = ufSession.Draw.AskViewLabelParms(viewLabelTag, myLabel)
If validViewParms = UFConstants.UF_DRAW_invalid_parameter Then
MsgBox("parameters could not be loaded for " & temp.Name)
Continue For
Else
MsgBox("Name: " & temp.Name & vbCrLf & _
"parent type: " & myLabel.parent_label_type.ToString & vbCrLf & _
"type: " & myLabel.GetType.ToString & vbCrLf & _
"parm type: " & myLabel.view_label_parm_type.ToString & vbCrLf & _
"letter format: " & myLabel.letter_format.ToString & vbCrLf & _
"view letter: " & myLabel.view_letter)
End If
myLabel.letter_size_factor = 1.6
myLabel.letter_format = UFDraw.ViewLabelLetterFormat.ViewLabelDashedLetter
ufSession.Draw.SetViewLabelParms(viewLabelTag, myLabel)
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Thanks in Advance
re: view letter
What version of NX are you using?
I see a reference to UTF8 encoding in the error message, what journal file format is your preference set to? (menu -> preferences -> user interface -> tools -> journal -> journal file format) The menu location should cover most newer NX versions.
Thanks For your reply
Thanks For your reply
I am using 11.0.2.7 version of NX
Journal file format is Unicode,
Even I tried with Other options like ASCII, Unicode Big Endian and UTF-8 But getting same error,
can you please help me in solving above problem
Thanks
re: UTF error
You might need to take this one up with GTAC (or your local support); the code errors out in NX 11 and 12, but it works in NX 10 and 1911 (I don't have other versions of NX CR installed). The error occurs in an internal API function.
Thanks for reply,
Thanks for reply,
Is There Any Other Method / Any other Code to get View letter in NX 11
Thanks In Advance
re: view letter
If you just need the view letter, you can parse it out of the "evaluated text" returned by the journal, or you can pass the view label to an "EditViewLabelSettingsBuilder" and query the view letter (shown in the code below).
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module3
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
lw.Open()
Const undoMarkName As String = "view label letter"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim validViewParms As Integer = -1
For Each temp As Drawings.DraftingView In theSession.Parts.Work.DraftingViews
lw.WriteLine(temp.Name)
'lw.WriteLine("view label shown: " & temp.Style.General.ViewLabel.ToString)
'lw.WriteLine("scale label shown: " & temp.Style.General.ScaleLabel.ToString)
'lw.WriteLine("")
'if neither the view label nor scale label is shown, skip to next view
If Not (temp.Style.General.ViewLabel Or temp.Style.General.ScaleLabel) Then
Continue For
End If
Dim viewLabelTag As Tag
theUfSession.Draw.AskViewLabel(temp.Tag, viewLabelTag)
Dim viewLabelObj As Annotations.Note = Utilities.NXObjectManager.Get(viewLabelTag)
Dim noteText() As String = viewLabelObj.GetText
lw.WriteLine("raw view label text:")
For Each tempLine As String In noteText
lw.WriteLine(tempLine)
Next
lw.WriteLine("")
lw.WriteLine("evaluated label text:")
Dim aT As Annotations.AssociativeText = theSession.Parts.Work.Annotations.CreateAssociativeText
Dim cData As Annotations.ComponentData = theSession.Parts.Work.Annotations.CreateComponentData(viewLabelObj)
For Each tC As Annotations.TextComponent In cData.GetTextComponents
For Each aLine As String In tC.GetText
lw.WriteLine(aT.GetEvaluatedText(viewLabelObj, aLine))
Next
Next
lw.WriteLine("")
Dim viewlabels1(0) As NXOpen.DisplayableObject
viewlabels1(0) = viewLabelObj
Dim editViewLabelSettingsBuilder1 As NXOpen.Drawings.EditViewLabelSettingsBuilder
editViewLabelSettingsBuilder1 = theSession.Parts.Work.SettingsManager.CreateDrawingEditViewLabelSettingsBuilder(viewlabels1)
Dim editsettingsbuilders1(0) As NXOpen.Drafting.BaseEditSettingsBuilder
editsettingsbuilders1(0) = editViewLabelSettingsBuilder1
theSession.Parts.Work.SettingsManager.ProcessForMultipleObjectsSettings(editsettingsbuilders1)
lw.WriteLine("view letter: " & editViewLabelSettingsBuilder1.ViewCommonViewLabel.Letter)
lw.WriteLine("")
lw.WriteLine("")
editViewLabelSettingsBuilder1.Destroy()
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
View lwtter was my
View lwtter was my requirement, Thnak you so much
Thanks a lot
Thanks a lot