Cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Get IJK point normal from PointTag

Solution Partner Creator Solution Partner Creator
Solution Partner Creator
BTW, since the smart point tag is not being recognized as an occurrence, I tried UF_ASSEM_ask_occs_of_entity() to see if I could find any occurrences for it, but it returns none.

Only when querying parents of the smart point, am I able to get a list of occurrences via UF_ASSEM_ask_occs_of_entity() (for either the parent faces or parent point objects). But of course, I need the specific occurrence that was selected, not a list.

Re: Get IJK point normal from PointTag

Legend
Legend

I think you should use UF_SO_ask_parents() to get the parents of a smart object.

 

Highlighted

Re: Get IJK point normal from PointTag

Solution Partner Creator Solution Partner Creator
Solution Partner Creator

Thanks for the reply, Technisites

 

However, UF_SO_ask_parents() is not giving any parent components.  It did give me the parent Face, from which I was able to get a normal vector, which I needed.  But even that Face is not an occurrence, so I can't get the parent from it either.

Re: Get IJK point normal from PointTag

Honored Contributor
Honored Contributor

Here's a quick & dirty journal (VB) that will allow you to select a point and if it is associated to a face object, will find the face normal at the point location.

 

Option Strict Off
Imports System
Imports NXOpen
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")

        lw.Open()

        Dim thePoint As Point = Nothing
        If SelectPointObject("select point", thePoint) = Selection.Response.Cancel Then
            Return
        End If

        lw.WriteLine("point is occurrence: " & thePoint.IsOccurrence.ToString)
        lw.WriteLine("point coordinates (absolute): " & thePoint.Coordinates.ToString)

        Dim parentFace As Face = Nothing
        Dim occFace As Face = Nothing

        If thePoint.IsOccurrence Then
            parentFace = GetParentFace(thePoint.Prototype)
            occFace = thePoint.OwningComponent.FindOccurrence(parentFace)
        Else
            parentFace = GetParentFace(thePoint)
        End If

        If IsNothing(parentFace) Then
            'point is not associated to a face
            lw.WriteLine("the selected point is not associated to a face object")
            Return
        End If

        Dim inPt(2) As Double
        inPt(0) = thePoint.Coordinates.X
        inPt(1) = thePoint.Coordinates.Y
        inPt(2) = thePoint.Coordinates.Z
        Dim outParam(1) As Double
        Dim outPt(2) As Double
        Dim faceTag As Tag = Tag.Null

        If IsNothing(occFace) Then
            'use prototype face
            faceTag = parentFace.Tag
        Else
            'use occurrence face
            faceTag = occFace.Tag
        End If

        Dim u1(2) As Double
        Dim v1(2) As Double
        Dim u2(2) As Double
        Dim v2(2) As Double
        Dim norm(2) As Double
        Dim radii(1) As Double
        theUfSession.Modl.AskFaceParm(faceTag, inPt, outParam, outPt)
        theUfSession.Modl.AskFaceProps(faceTag, outParam, outPt, u1, v1, u2, v2, norm, radii)

        lw.WriteLine("face normal at selected point location (absolute coordinates): " & norm(0).ToString & ", " & norm(1).ToString & ", " & norm(2).ToString)

        lw.Close()

    End Sub

    Function SelectPointObject(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a Point"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UFConstants.UF_point_type
            .Subtype = UFConstants.UF_all_subtype
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt,
         title, scope, selAction,
         includeFeatures, keepHighlighted, selectionMask_array,
         selObj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    Function GetParentFace(ByRef theSmartObject As NXObject) As Face

        Dim numParents As Integer
        Dim theParentTags() As Tag = Nothing
        Dim isSmart As Boolean = False

        Try
            theUfSession.So.IsSo(theSmartObject.Tag, isSmart)
            If isSmart Then
                theUfSession.So.AskParents(theSmartObject.Tag, UFConstants.UF_SO_ASK_ALL_PARENTS, numParents, theParentTags)

                For Each tempTag As Tag In theParentTags
                    Dim objParent As TaggedObject = Utilities.NXObjectManager.Get(tempTag)

                    If TypeOf (objParent) Is Face Then
                        Dim theFace As Face = objParent
                        Return theFace
                    End If

                    'GetSmartParents(objParent, indent + 2)
                Next

                lw.WriteLine("")

            End If

        Catch ex As NXException
            lw.WriteLine("error: " & ex.ErrorCode)
            lw.WriteLine("  " & ex.Message)
        End Try

        Return Nothing

    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: Get IJK point normal from PointTag

Solution Partner Creator Solution Partner Creator
Solution Partner Creator

Thanks again cowski,

 

I think this time I've got it going smoothly.

 

The problem I was having was in the referred thread (a few posts above), it was suggested by the user to switch the Select Object property Snap -> PointOverlay to True.  This was so that the selected point would be returned as a Smart Point.  However, it now seems to me that if that's the case, the selection process returns the Point prototype.  Thus there is no specific point occ obtained from the selection process.

 

From your Journal I deduced that I had to undo that setting to get an occ returned to me by the selection process.  And that did the trick, now I get an occ for the point and pretty much follow your posts for the rest of it.

 

Thanks so much for all of the help, extremely appreciated.