Extract Vb-file for 'Preferences -> View label'

Hi everybody,

I am new to this site. I already used a lot of the very usefull tips and tricks, so thanks for that!

I now have this problem that i can't extract the VB-code using the record function on NX8.5 to change the 'view label settings' in 'preferences'. This function doesn't have the green spot in front of it, meaning it's not supported for recording. I just want to make simple changes in the 'view label details and section'.

Could somebody advise me on how to do this?

Thanks a lot!

Steffen

Can you give an example of the type of change that you are looking to make?

I want to have some format preferences in there for details and sections as:

Prefix name, Size factor, view scale, scale adjustment etc.

Cheers!

The code below will change the letter format and size factor on existing view labels. In the net_ref API doc, search for "UF_DRAW_ask_view_label_parms" and also follow the link on the resulting page for "UF_DRAW_view_label_parms_p_t" to get more information on the function and available options.

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

Hi,

That's a quick job! I am a real novice at VB-programming; where can I find the 'net_ref API doc'?

Besides that, it isn't neccesary for excisting labels to change. This journal will be part of a program that wil be used at the start-up of a drawing. I think this would make the code easier?

Thanks so far! Impressive skills.

Steffen

It was some code that I already had on hand; you'll need to tweak it to get what you need. If you pass in a null tag (instead of an existing view tag) to the SetViewLabelParms function, it will set the global preferences (it will affect new views created rather than existing views).

There is a forum post here that describes how to get to the .NET API reference document in the NX help.

Hi , I want to have some preferences for all view label. I got for scale factor for view label & view scale. But I am not getting , how to change the factor for View label prefix e.g Section, Detail etc. Could you please give some example.

Thanks

You want to apply a scale factor to the prefix text ("SECTION", "DETAIL", etc)?

In NX, the height factor is only applied to the view letter. However, if you edit the prefix text, you can add your own scale factor to the prefix. For example, the default prefix text for a detail view is "DETAIL"; if you specify a prefix text of "<C1.25>DETAIL<C>", the prefix text height will be 1.25x the normal text height. If you add such text control characters into the prefix text, you will need to parse the prefix text if you later want to query the scale factor used.

Could you please give me eg in journal script. It will be helpful for me

The journal code below will change all the section view labels; the view prefix text will be changed to "SECTION" with text control characters to change the size of the text. The code only operates on section views, a similar strategy can be used for other view types.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module2

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 = "section view prefix size factor"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

'scale factor for the section view prefix text
Const factor As Double = 1.5

For Each temp As Drawings.DraftingView In workPart.DraftingViews

If Not TypeOf (temp) Is Drawings.SectionView Then
Continue For
End If

Dim views1(0) As View

views1(0) = temp
Dim editViewSettingsBuilder1 As Drawings.EditViewSettingsBuilder
editViewSettingsBuilder1 = workPart.SettingsManager.CreateDrawingEditViewSettingsBuilder(views1)

Dim editsettingsbuilders1(0) As Drafting.BaseEditSettingsBuilder
editsettingsbuilders1(0) = editViewSettingsBuilder1
workPart.SettingsManager.ProcessForMutipleObjectsSettings(editsettingsbuilders1)

editViewSettingsBuilder1.ViewSectionLabel.LabelPrefix = "SECTION"

Dim nXObject1 As NXObject
nXObject1 = editViewSettingsBuilder1.Commit()

editViewSettingsBuilder1.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