Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get Point Name in a note with x.y.z coodinates

Status
Not open for further replies.

ChadSeel

Aerospace
Dec 20, 2019
1
thread561-350228

Is there a way to Add the Point name to the Journal with the x,y,z coordinates in a note?
 
Replies continue below

Recommended for you

If you have a reference to the point object, you can use its .Name property to access the name of the point. The code posted by FrankSwinks does not directly access the point objects, therefore does not have access to the point names. Adding point names to this journal would not be a trivial task.

www.nxjournaling.com
 
I suck with VB Coding. So I cant do much more than offer you this journal and hope it helps.

We have something called Sealer Beads. They have attributes in their bodies. This Journal when ran in Drafting, allows the user to select the beads edge in a drafting view and then you select a placement for the note. It will add a note reading a certain attribute.

Perhaps if you can figure out how to adapt it to select points instead of edges, and change what attributes it puts in the note? Are these Weld Spots where the coordinates are listed in an attribute?

I thought I had one that did points and even made labels rather than notes, but I cant seem to find it. I will look some more. Just hoping this will help get you somewhere.

Journal attached

Ken
My brain is like a sponge. A sopping wet sponge. When I use it, I seem to lose more than I soak in.
 
Hello,

Try below code, it might be helpful to you.


Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Annotations.DraftingNoteBuilder
Imports NXOpen.Drawings
Imports NXOpen.Annotations.PlaneBuilder
Imports NXOpen.Annotations.Annotation
Imports NXOpen.Utilities
Imports NXOpen.UF.UFUi
Imports System.Threading
Imports System.Reflection
Imports NXOpen.Features


Module Point_Leader_Drawing


Sub Main()
   
        Dim theSession As Session
        Dim workPart As Part
        Dim theUfSession As UFSession
        Dim displayPart As Part
        Dim theUI As UI
        Dim dwgsheet As Drawings.DrawingSheet

        Dim PointName As String
        theSession = Session.GetSession()
        workPart = theSession.Parts.Work
        displayPart = theSession.Parts.Display
        theUfSession = UFSession.GetUFSession
        theUI = UI.GetUI
        dwgsheet = workPart.DrawingSheets.CurrentDrawingSheet

        Dim View As Drawings.DraftingView
        Dim DispObjs() As DisplayableObject

        Dim tempPoint As Point
        Dim num3 As Double
        Dim numArray As Double()
        Dim numArray2 As Double()
        Dim strViewName As String = Nothing
        Dim null As Tag = NXOpen.Tag.Null
        Dim tag2 As Tag = NXOpen.Tag.Null

        On Error Resume Next

        For Each oView As Drawings.DraftingView In dwgsheet.SheetDraftingViews
           
                oView.ActivateForSketching()
                If oView.IsActiveForSketching = True Then

                    Dim numSelectedObjects As Integer = theUI.SelectionManager.GetNumSelectedObjects
                    DispObjs = oView.AskVisibleObjects()
                    For Each tempobj As DisplayableObject In DispObjs
                        If TypeOf tempobj Is Point Then
                            tempPoint = tempobj

                            Dim coordinates As Point3d = tempPoint.Coordinates
                            numArray = New Double() {coordinates.X, coordinates.Y, coordinates.Z}
                            numArray2 = New Double(2 - 1) {}
                            ' Dim strArray As String() = New String() {coordinates.X.ToString, coordinates.Y.ToString, coordinates.Z.ToString}
                            strViewName = oView.Name
                            theUfSession.View.AskTagOfViewName(strViewName, [null])
                            theUfSession.Draw.AskViewScale([null], tag2, num3)
                            theUfSession.View.MapModelToDrawing([null], numArray, numArray2)

                            Dim objArray As NXObject() = New NXObject(1 - 1) {}
                            Dim tag As Tag
                            Dim pType As String = String.Empty
                            Dim pName As String = String.Empty

                            Dim point As Point = DirectCast(NXObjectManager.Get(tempPoint.Tag), Point)
                            objArray(0) = point
                            Dim prototype As Point = DirectCast(point.Prototype, Point)
                            If (Not prototype Is Nothing) Then
                                If Not String.Equals(prototype.Tag.ToString, point.Tag.ToString) Then
                                    Dim component As Assemblies.Component = DirectCast(theSession.Parts.Display.ComponentAssembly.RootComponent.FindObject(point.OwningComponent.JournalIdentifier), Assemblies.Component)
                                    Dim journalIdentifier As String = ("PROTO#.Features|" & point.JournalIdentifier)
                                    Dim point3 As Point = DirectCast(component.FindObject(journalIdentifier), Point)
                                    If Not String.IsNullOrEmpty(prototype.Name) Then
                                        pName = prototype.Name
                                    Else
                                        GetFeatOfObject(point3.Tag, pName, pType, tag)
                                    End If
                                End If
                                PointName = pName
                            Else
                                pName = point.Name
                                If String.IsNullOrEmpty(pName) Then
                                    GetFeatOfObject(point.Tag, pName, pType, tag)
                                End If
                                PointName = pName
 MsgBox(PointName)
                            End If
                            CreateHPnt_Leader(coordinates, numArray2, num3, strViewName)
                        End If
                    Next
                End If
          
        Next

        On Error GoTo 0
    End Sub

    Private Sub GetFeatOfObject(ByVal tempObjTag As Tag, ByRef pName As String, ByRef pType As String, ByRef featuretag As Tag)
        Dim tag As Tag
        Dim theUfSession As UFSession = UFSession.GetUFSession
        theUfSession.Modl.AskObjectFeat(tempObjTag, tag)
        If (tag > Tag.Null) Then
            Dim feature As Feature = DirectCast(NXObjectManager.Get(tag), Feature)
            If String.IsNullOrEmpty(feature.Name) Then
                pName = feature.GetFeatureName
            Else
                pName = feature.Name
            End If
            pType = feature.FeatureType
            featuretag = tag
            Dim str As String = ("(" & feature.Timestamp.ToString & ")")
            If pName.Contains(str) Then
                pName = pName.Replace(str, "")
            End If
        End If
    End Sub

    Private Sub CreateHPnt_Leader(ByVal point As Point3d, ByVal drawing_pt As Double(), ByVal scale_value As Double, ByVal viewName As String)

        Dim annotation As SimpleDraftingAid = Nothing
        Dim num2 As Integer
        Dim num3 As Integer
        Dim theSession As Session
        Dim workPart As Part
        Dim theUfSession As UFSession
        theSession = Session.GetSession()
        workPart = theSession.Parts.Work
        theUfSession = UFSession.GetUFSession

        Dim builder As DraftingNoteBuilder = workPart.Annotations.CreateDraftingNoteBuilder(annotation)
        builder.Origin.Plane.PlaneMethod = PlaneMethodType.XyPlane
        builder.Origin.Anchor = AlignmentPosition.BottomLeft
        builder.Origin.SetInferRelativeToGeometry(True)
        Dim assocOrigin As New AssociativeOriginData With {.OriginType = AssociativeOriginType.RelativeToView}
        Dim num As Integer = 0

        Dim strPnt(2) As String

       
        strPnt(1) = "X= " & point.X.ToString
        strPnt(2) = "Y= " & point.Y.ToString
        strPnt(3) = "Z= " & point.Z.ToString



        builder.Text.TextBlock.SetText(strPnt)
        builder.TextAlignment = TextAlign.Top
        builder.Style.LetteringStyle.GeneralTextSize = 3.5
        Dim null As Tag
        theUfSession.View.AskTagOfViewName(viewName, [null])
        theUfSession.Obj.AskTypeAndSubtype([null], num2, num3)
        If ((num2 = 60) AndAlso (num3 = 2)) Then
            Dim view As BaseView = DirectCast(workPart.DraftingViews.FindObject(viewName), BaseView)
            assocOrigin.View = view
        Else
            Dim view As BaseView = DirectCast(workPart.DraftingViews.FindObject(viewName), BaseView)
            assocOrigin.View = view
        End If
        builder.Origin.SetAssociativeOrigin(assocOrigin)
        Dim data2 As LeaderData = workPart.Annotations.CreateLeaderData
        data2.StubSize = 3
        data2.Arrowhead = ArrowheadType.FilledArrow
        data2.StubSide = LeaderSide.Right
        Dim pointd As New Point3d(drawing_pt(0), drawing_pt(1), 0)
        data2.Leader.SetValue(Nothing, Nothing, pointd)
        Dim view5 As View = Nothing
        Dim pointd2 As New Point3d((drawing_pt(0) - 40), (drawing_pt(1) + 15), 0)
        builder.Origin.Origin.SetValue(Nothing, view5, pointd2)
        builder.Leader.Leaders.Append(data2)
        Dim obj2 As NXObject = builder.Commit
        builder.Destroy()
    End Sub

End Module

Bhavik S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor