Showing results for 
Search instead for 
Did you mean: 

Scaling of leader text in drawing




I am adding a leader to points in Active View in Drawing through the journal.


But when I add it, the text is getting scaled automatically and it is taking View Scale.

e.g. View-scale is 1:2. I have kept leader font size 3.5 in code. But after placing it is half


So what is the change that I need to make so that it will take scale as 1: 1.?



Re: Scaling of leader text in drawing

Honored Contributor
Honored Contributor

I have a feeling that this is related to your other, recent thread:


If so, the text is scaling according to the view scale. If you do not want that to happen, do not add the text inside the view (by expanding the view and adding the text), add it to the drawing instead.

Re: Scaling of leader text in drawing




Yes, it is related to that topic only.


I tried by not to expanding view so in that case Point leader is not coming near to that point.

And if I will Expand the view then it will come near to that point.

I have used point coordinates as leader point.

Please find the attached code and correct me where I have to make a change.

Re: Scaling of leader text in drawing

Honored Contributor
Honored Contributor

An example journal showing one solution is below. When run, it will prompt you to select a point object (the selection filter only allows point objects), you can pick any point object that appears in a drafting view. The journal will then prompt you to select a location for the label; it will create a note with the point coordinates with a leader attached to the point object.


The journal was pieced together from a few different source journals; it wasn't extensively tested - if you use this technique, you will need to flesh it out to make it more robust.


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()

    Dim theUI As UI = UI.GetUI()
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ")


        Dim workPart As Part = theSession.Parts.Work

        Dim pointTag As NXOpen.Tag
        Dim myPoint As Point
        Dim cursor As Point3d

        Dim cursorView As Integer

        Dim dwgview As Drawings.DraftingView = Nothing
        Dim dwgViewTag As Tag = Tag.Null

        If select_a_point(pointTag, dwgViewTag) = Selection.Response.Cancel Then
        End If


        dwgview = Utilities.NXObjectManager.Get(dwgViewTag)

        theUfSession.Disp.SetHighlight(pointTag, 0)
        myPoint = Utilities.NXObjectManager.Get(pointTag)
        'lw.WriteLine(myPoint.Coordinates.X & "," & myPoint.Coordinates.Y & "," & myPoint.Coordinates.Z)


        Dim text1(2) As String

        Dim nullAnnotations_SimpleDraftingAid As Annotations.SimpleDraftingAid = Nothing

        Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder
        draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(nullAnnotations_SimpleDraftingAid)

        text1(0) = "X " + myPoint.Coordinates.X.ToString("F3")
        text1(1) = "Y " + myPoint.Coordinates.Y.ToString("F3")
        text1(2) = "Z " + myPoint.Coordinates.Z.ToString("F3")



        Dim leaderData1 As Annotations.LeaderData
        leaderData1 = workPart.Annotations.CreateLeaderData()


        Dim nullView As View = Nothing

        leaderData1.Leader.SetValue(myPoint, dwgview, myPoint.Coordinates)

        Dim point2 As Point3d = New Point3d(cursor.X, cursor.Y, 0.0)
        draftingNoteBuilder1.Origin.Origin.SetValue(Nothing, nullView, point2)

        Dim nXObject1 As NXObject
        nXObject1 = draftingNoteBuilder1.Commit()



    End Sub

    Function select_a_point(ByRef point As NXOpen.Tag, ByRef viewTag As NXOpen.Tag) As Selection.Response

        Dim message As String = "Point:"
        Dim title As String = "Select a Point"
        Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
        Dim response As Integer
        'Dim viewTag As NXOpen.Tag
        Dim cursor(2) As Double
        Dim sel_mask As UFUi.SelInitFnT = AddressOf mask_for_points


            theUfSession.Ui.SelectWithSingleDialog(message, title, scope, sel_mask,
                         Nothing, response, point, cursor, viewTag)
        End Try

        If response <> UFConstants.UF_UI_OBJECT_SELECTED And
           response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
            Return Selection.Response.Cancel
            Return Selection.Response.Ok
        End If

    End Function

    Function mask_for_points(ByVal select_ As IntPtr,
                             ByVal userdata As IntPtr) As Integer

        Dim num_triples As Integer = 1
        Dim mask_triples(0) As UFUi.Mask

        mask_triples(0).object_type = UFConstants.UF_point_type
        mask_triples(0).object_subtype = 0
        mask_triples(0).solid_type = 0

                           num_triples, mask_triples)
        Return UFConstants.UF_UI_SEL_SUCCESS

    End Function

    Function SelectScreenPos(ByRef pos As Point3d) As Selection.DialogResponse

        Dim view As NXOpen.View = Nothing
        Dim letteringPrefs As Annotations.LetteringPreferences = Nothing
        Dim userSymPrefs As Annotations.UserSymbolPreferences = Nothing

        Return theUI.SelectionManager.SelectScreenPosition("Select XYZ Label Position", view, pos)

    End Function

    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


Re: Scaling of leader text in drawing




I tested this journal before but it is time-consuming for a user if there are like 100 or more points in one view.


So that is why I am creating a journal so it will automatic select visible point and create a leader with point name.


I have one query 

text1(0) = "X " + myPoint.Coordinates.X.ToString("F3")

whats is "F3" in this case ?
I have seen "N4" also ...

"X= " & pnt2(0).ToString("N4")

Re: Scaling of leader text in drawing

Honored Contributor
Honored Contributor

The "F3" in this case formats the coordinate value to have 3 decimal places.


The journal code wasn't intended as a total solution for you, but rather is a demonstration of how to create the leader and note without expanding the view; thus avoiding the scaling issues. You can replace the user interaction step with your own code to provide the point objects.

Re: Scaling of leader text in drawing


Hi Cowski,



Thanks for the suggestion.

I need one more help.

1.  I tried to add multipoint selection method in your code but I am not getting how to make it work.

Can you please help me.


2. When we get the coordinates in drawing that is with reference to work part. 

But I want to get it as with reference to the drawing.

How can I get it?

Re: Scaling of leader text in drawing

Honored Contributor
Honored Contributor
  1. Do you want the user to interactively select the points? I thought you wanted to find and process them automatically?
  2. I assumed that the point objects were in a drafting view on the sheet and you wanted the model space coordinates - is this not the case? Are your point objects in a drafting view or do they live on the drawing sheet itself? If they are in a drafting view and you want to know where they appear in the drawing sheet coordinate system, you can use the .MapModelToDrawing method to convert model space coordinates to drawing sheet coordinates.

Re: Scaling of leader text in drawing




I tried .MapModelToDrawing  and I am able to get view co-ordinate wrt to Drawing.

But I want the Point co-ordinates wrt to drawing.


Below is the code for that and it is only for View....

Please provide suggestion for points..




Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Drawings

Module NXJournal

    Dim s As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession

Sub Main()

    Dim workPart As Part = s.Parts.Work
    Dim lw As ListingWindow = s.ListingWindow()

    Dim curdrw As DrawingSheet = workPart.DrawingSheets.CurrentDrawingSheet()
    Dim member_view As DraftingView
    Dim ref_pt As Point3d

    For Each member_view In curdrw.GetDraftingViews()
        ref_pt = askDraftingViewDrawingRefPt(member_view)

        lw.WriteLine(" " + ref_pt.X.ToString + ", " + _
            ref_pt.Y.ToString + ", " + _

End Sub

    Function askDraftingViewDrawingRefPt(ByVal dv As DraftingView) As Point3d
        Dim vo As Point3d = dv.Origin
        Dim vm As Matrix3x3 = dv.Matrix
        Dim vw As Double() = {0, 0, 0, vm.Xx, vm.Xy, vm.Xz, vm.Yx, vm.Yy, _
            vm.Yz, vm.Zx, vm.Zy, vm.Zz}
        Dim abs As Double() = {0, 0, 0, 1, 0, 0, 0, 1, 0}
        Dim mx(11) As Double
        Dim resp As Integer
        Dim c() As Double = {-vo.X, -vo.Y, -vo.Z}
        Dim ref_pt(1) As Double

        ufs.Trns.CreateCsysMappingMatrix(vw, abs, mx, resp)
        ufs.Trns.MapPosition(c, mx)
        ufs.View.MapModelToDrawing(dv.Tag, c, ref_pt)

        Dim out_pt As Point3d = New Point3d(ref_pt(0), ref_pt(1), 0)
        Return out_pt

    End Function
End Module




Re: Scaling of leader text in drawing

Honored Contributor
Honored Contributor

"I tried .MapModelToDrawing  and I am able to get view co-ordinate wrt to Drawing.

But I want the Point co-ordinates wrt to drawing."


You have everything that you need right here:

Dim c() As Double = {-vo.X, -vo.Y, -vo.Z}
Dim ref_pt(1) As Double

ufs.View.MapModelToDrawing(dv.Tag, c, ref_pt)

Your "c" variable is an array that holds the point coordinates that you are interested in (w.r.t. absolute model space). Instead of passing in the view origin coordinates, pass in the coordinates of the point.