Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

NXOPEN Inherent Parent Name

Status
Not open for further replies.

jonathan8388

Aerospace
Jul 31, 2015
20
0
0
US
Hi Everybody

Looking for some help with an NXOPEN problem that I cant seem to get around.

The problem: I have bunch of mirrored entities in my part created using the "Mirror Geometry" command. All of these "Mirrored Geometry" entities have custom names assigned to them in the NX tree. From here, I do another "Extract Geometry" from these mirrored entities. These "Extract Geometry" entities get published to the NX Wave Interface for linking to other components. The challenge I have is that when I do an "Extract Geometry" from the "Mirrored Geometry", the custom names dont get carried over.

I had made an NXOPEN code to handle this nicely when the "Extract Geometry" is extracted from something else (points, curves, etc). This loops through the tags of all of the selected "Extract Geometries" by using the "getparents()" statement to get the Extract Geometry parent, then setting the extract geometry tree name to that parents name. I am able to loop through many selected "Extract geometry" objects and get them to inherit the parent name nicely in most cases.

However, My main issue is this method wont work when the extracted body is a child of a "Mirrored Geometry" entity. Doing the .getparents() on the extracted geometry seems to give me an features.extractedface with no name tied to it. I cant seem to get the .getparents command to get me back to the "Mirrored Gometry" that the "Extract Geometry" was created from.

Does anyone know how to do that?

 
Replies continue below

Recommended for you

What version of NX are you using?
I've spent some time this afternoon, but have not been able to replicate what you are describing. I have some code that iterates through the features and lists some info about each one. I modified it slightly to list out the results from the .GetParents call. When I run the journal on my NX file, it correctly reports the mirror geometry feature as the parent of the extract body feature. One thing you might want to watch for is the .IsInternal property of each feature. Some features don't show up in the part navigator and your code shouldn't modify them (generally speaking).

Can you post the relevant part of your code? My test journal is below.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features

Module Module222
    Sub Main()

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

        Dim featArray() As Feature = theSession.Parts.Work.Features.GetFeatures()
        Dim featEntities() As NXObject

        lw.WriteLine("*** All Features ***")
        For Each myFeature As Feature In featArray
            lw.WriteLine(".GetFeatureName: " & myFeature.GetFeatureName)
            lw.WriteLine(".Name: " & myFeature.Name)

            Dim featIsBrowseable As Boolean = False
            Const report_inactive As Boolean = False
            Const report_unable_to_make_current As Boolean = False
            theUfSession.Modl.IsBrowseableFeature(myFeature.Tag, report_inactive, report_unable_to_make_current, featIsBrowseable)
            lw.WriteLine("Is Browseable: " & featIsBrowseable.ToString())

            lw.WriteLine(".IsInternal: " & myFeature.IsInternal.ToString)
            If IsNothing(myFeature.ContainerFeature) Then
                lw.WriteLine(".ContainerFeature: Nothing")
            Else
                lw.WriteLine(".ContainerFeature: " & myFeature.ContainerFeature.JournalIdentifier)
            End If
            'lw.writeline(".IsContainedFeature: " & myFeature.IsContainedFeature.ToString)
            lw.WriteLine(".FeatureType: " & myFeature.FeatureType)
            lw.WriteLine(".GetType: " & myFeature.GetType.ToString)
            lw.WriteLine(".Timestamp: " & myFeature.Timestamp.ToString)
            If TypeOf myFeature Is Features.SketchFeature Then
                Dim mySketchFeature As Features.SketchFeature = myFeature
                lw.WriteLine("sketch .Name: " & mySketchFeature.Sketch.Name)
            End If
            lw.WriteLine(".Suppressed: " & myFeature.Suppressed.ToString)
            lw.WriteLine("number of parents: " & myFeature.GetParents.Length.ToString)
            For Each featParent As Features.Feature In myFeature.GetParents
                lw.WriteLine("  " & featParent.GetFeatureName)
            Next
            lw.WriteLine("number of children: " & myFeature.GetChildren.Length.ToString)

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

            Try
                Dim Xdir(2) As Double
                Dim Ydir(2) As Double
                theUfSession.Modl.AskFeatDirection(myFeature.Tag, Xdir, Ydir)
                lw.WriteLine("AskFeatDirection: " & Xdir(0).ToString)
            Catch ex As NXException
                lw.WriteLine("Direction error: " & ex.Message)
            End Try

            Dim xform As Tag
            Try
                theUfSession.Wave.AskLinkXform(myFeature.Tag, xform)
                lw.WriteLine("wave feature has xform")
            Catch ex As NXException
                lw.WriteLine("Xform error: " & ex.ErrorCode & ": " & ex.Message)
            End Try


            lw.WriteLine("")

        Next
        lw.Close()

    End Sub
End Module

www.nxjournaling.com
 
Below is the relevant portion of my code. I have another sub within this module that opens up a selection box where I click on the extracted body in the tree. It then gets the tag of that extracted body and passes it to the code below as "Feature Tag". Then there is a .getparents to get the parent.

when I do this for an extracted body that is specifically an extract of the mirrored geometry, the parent seems to be some no-name "extract face". For some reason the .getparents wont give me the tag/name of the mirrored geometry entity.

Code:
Sub Rename_Feature (Feature_Tag as tag) 

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim features1(0) As NXOpen.features.feature
Dim features2(0) As NXOpen.nxobject

features1(0)= NXOpen.Utilities.NXObjectManager.Get(Feature_Tag)


    features2(0)=features1(0).getparents(0)
    features1(0).setname (features2(0).name) 

End Sub
 
Does your selection routine limit the user to selecting a feature or a certain type of feature? If not, I suggest starting there. I suspect that the selection being returned may not be your intended entity. I don't suggest working with tags unless you have to.

What result do you get if you run my test code on your part? Does it show the expected parent feature(s)?

www.nxjournaling.com
 

My selection process is below. so when I click on the exported geometry in the tree and run this, it will store it in the "Items" Array as a Nxopen.Features.Feature. Then get the tag of the selected extracted geometry using cv.tag and then that is passed to the code i have above.

The funny thing is that the tag of the selected feature (extracted geometry) seems correct. I ran another test code where I took the CV.Tag and printed some information to the info window (type, name, etc) and that all seemed correct with respect to that extracted geometry entity. However the parent of that tag was not correct ONLY when the parent was specifically "mirrored geometry" (it worked great otherwise).

I havent tried your code yet but i will and let you know what I get.

Side note: what is the preferred way to do this without tags? I see you use them as well. Is there supposed to be another alternative "more robust" method for something like this?

Code:
    Sub Main()
   
        Dim theSession As Session = Session.GetSession()
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim Select_Response As Selection.Response = Nothing
        Dim selectedObjects() As NXObject
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        Dim Items as array
        Dim CV as NXOpen.Features.Feature

    
Start1:
Start2:

        Select_Response = Select_Objects(selectedObjects)
        If Select_Response = Selection.Response.Back Then GoTo Start1 ' Select a new face
        If Select_Response = Selection.Response.Cancel Then GoTo End1
        Items=selectedObjects

        for each cv in Items
            call Rename_Feature (cv.tag)
        next    
 End1:       

    End Sub
 
So I ran the code and the code works fine. Ignore the sketch in the image below, but I have 4 entities in there. "Main Body" and then a "Main Body Extract" which is obviously an extract of the "Main Body"

Then I have a "Mirrored Parent" with a "Mirrored Body Extract".

When your code gets to the "Mirrored Body Extract" in the tree, I essentially want it to find the parent (in this case the Mirrored geometry) and print the name of the parent "MIRRORED_PARENT" to the listing window.

Can the code be adapted to do that? If that is possible, I can adapt that solution to my code. But I cant seem to get the "MIRRORED_PARENT" name to print from getting the parent of "MIRRORED_BODY_EXTRACT"

NXOPEN_t9euns.png
 
jonathan8388 said:
Side note: what is the preferred way to do this without tags? I see you use them as well. Is there supposed to be another alternative "more robust" method for something like this?

There are some functions (the older "UF" functions) that require the use of tags; however, from what I've seen of your code so far, it looks like you are working with bodies and features, which are well covered by the NXOpen .net API object model. To access the name that you have assigned to a feature, try using the .Name property:

Code:
For Each featParent As Features.Feature In myFeature.GetParents
    lw.WriteLine("  " & featParent.GetFeatureName)
    lw.WriteLine("  " & featParent.Name)
Next

In the code above, the .GetFeatureName will return the NX feature name, such as "Extrude". The .Name property will return the name assigned to the feature, such as "MAIN_BODY". If no name has been assigned, the .Name property will be empty.

www.nxjournaling.com
 
Status
Not open for further replies.
Back
Top