cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the parent face of a point?

Hi all,

 

I am creating a point on a surface manually in NX and then in BlockStyler, I select this point and I can't get the surface that it lies on.

 

Here is the code that I use. I intended to use the function "UF_SO_ask_parent".

 

// get the selected point from BlockStyler
TaggedObject[] points = selPoint.GetSelectedObjects();

int n_parents;
Tag [] parents;
Tag pointTag = points[0].Tag;

// ask parents theUF.So.AskParents(pointTag, UFConstants.UF_SO_ASK_ALL_PARENTS, out n_parents, out parents);
// loop through all the parents and report their types for(int i=0;i<n_parents;i++) { theUF.Obj.AskTypeAndSubtype(parents[i], out type, out subType); string str1 = "type =" + type.ToString() + " subtype = " + subType.ToString(); }

The results are 

 

type =2 subType = 0  (This means, the "parent" is a point)

type = 205 subType = 0 (This means, the parent is feature type)

 

none of which is of solid type or face type.

 

Am i missing something? 

 

Thanks for your help.

 

Steph

7 REPLIES

Re: How to get the parent face of a point?

Legend
Legend

Try using 'UF_SO_ASK_PARENTS_RECURSIVELY'.

Re: How to get the parent face of a point?

Hi Technisites,

 

Thank you for your reply.

 

I just tried it. It doesn't seem to work. With UF_SO_ASK_ALL_PARENTS,the function UF_SO_ask_parents returns 2 parents. But with UF_SO_ASK_PARENTS_RECURSIVELY, no parent of my selected object(which is a point on a face) is returned. This is the code that I use.

 

TaggedObject[] points = selPoint.GetSelectedObjects();

// Get parent tag
int n_parents;
Tag[] parents;
Tag pointTag = points[0].Tag;
theUF.So.AskParents(points[0].Tag, UFConstants.UF_SO_ASK_PARENTS_RECURSIVELY, out n_parents, out parents);
theUF.Ui.DisplayMessage(n_parents.ToString(), 1);

The output of n_parents is 0.

 

Re: How to get the parent face of a point?

Phenom
Phenom

Did you create a point feature that is associative to the face or did you create an unassociative point using the "point on face" snap? If the point is unassociative, it will show as having zero parents.

Re: How to get the parent face of a point?

Phenom
Phenom

Below is some code I wrote a while back to examine the parents of point objects.

 

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 point parents")

        lw.Open()

        For Each tempPt As Point In theSession.Parts.Work.Points
            lw.WriteLine("Point Tag: " & tempPt.Tag.ToString)
            GetSmartParents(tempPt, 2)
            lw.WriteLine("")
        Next

        lw.Close()

    End Sub

    Sub GetSmartParents(ByRef theSmartObject As NXObject, ByVal indent As Integer)

        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)

                lw.WriteLine(New String(" "c, indent) & "number of parents: " & numParents.ToString)
                For Each tempTag As Tag In theParentTags
                    Dim objParent As TaggedObject = Utilities.NXObjectManager.Get(tempTag)


                    lw.WriteLine(New String(" "c, indent) & "parent type: " & objParent.GetType.ToString)
                    lw.WriteLine(New String(" "c, indent) & "parent tag: " & objParent.Tag.ToString)


                    If TypeOf (objParent) Is Scalar Then
                        Dim theScalar As Scalar = objParent
                        lw.WriteLine(New String(" "c, indent) & "dimensionality: " & theScalar.Dimensionality.ToString)
                        lw.WriteLine(New String(" "c, indent) & "value: " & theScalar.Value.ToString)
                    End If

                    If TypeOf (objParent) Is Offset Then
                        Dim theOffset As Offset = objParent
                        lw.WriteLine(New String(" "c, indent) & "vector: " & theOffset.Vector.ToString)
                    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


    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

Re: How to get the parent face of a point?

Hello cowski1,

 

I think you are right about the associative relationship. Here is what I've tried.

 

1) I created a point in NX through Insert -> Datumn/Point -> Point. When creating the point, I chose the point type as "on surface" and I also checked the "associative" check-box.

 

2) I created a Blockstyler, with a "Select Object" control and an "Action Button" control.

 

3) I set the Select Object property Snap -> PointOverlay as True and SnapPointTypesOnByDefault as both "existing point" and "point on surface".

Capture2.JPG

4) I use this code in my button callback

TaggedObject[] thePoint = selection0.GetSelectedObjects();
                
int n_parents;
Tag [] parents;

theUF.So.AskParents(thePoint[0].Tag, UFConstants.UF_SO_ASK_ALL_PARENTS, out n_parents, out parents);

theUF.Ui.DisplayMessage(n_parents.ToString(), 1);

int type, subType;
for(int i =0 ; i < n_parents; i++)
    {
       theUF.Obj.AskTypeAndSubtype(parents[i], out type, out subType);
       string str = "Type = " + type + " subType = " + subType;
       theUF.Ui.DisplayMessage(str, 1);
    }

These are what I got.

 

1) When selecting an existing point, n_parent returns 2, which are of feature type and point type.

2) When selecting(snapping) a point on a surface, n_parent returns 4, which includes solid type and face type. 

 

 

Is there a workaround for this? I want to be able to choose an existing point and query its parents and I also want to snap a point on the fly and query its parents as well. Based on what I found, it looks like if I am selecting an existing point, I can't query its parents.

Re: How to get the parent face of a point?

I believe your sample code is the solution. Thank you very much and what an elegant use of the recursive function call!

Re: How to get the parent face of a point?

Phenom
Phenom

Thanks! Glad it helped.