Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

NX journal : how to access to the items in specific groups 1

Status
Not open for further replies.

zhonyang

Structural
Jul 27, 2022
8
0
0
ES
Hello guys:
I'm creating a journal on exporting all info. from part navigator table. Specially on the items in groups. It can't record any code for "export to spreadsheet" operation
I can get all features by "for each fea as feature in workpart.features", but how to get all items in a specific groups only?
It's quite different from catia and fail to find some API doc. online. Anyone can tell the key point on looping through all groups and looping through all features in the groups I want? Thanks.
 
Replies continue below

Recommended for you

cowski (Mechanical)23 May 23 14:21
Are you talking about feature groups or normal groups (that contain geometric objects)?

The link below has code to get the normal groups:

THanks for your reply cowski !
Yes, I'm talking about normal groups. Do you know how to loop through all item in specific group?
Like :
if myGroup.Name = balabala then
for each fea as feature in mygroup.features ' how to access
do something on the feature I want
next
end if
 
The code at NXJournaling returns an array of object tags that represent the objects in the group. Once you have a tag, you can use the NXObjectManager to get the object associated with the tag.

Modified code below:
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession
        Dim workPart As Part = theSession.Parts.Work

        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()


        Dim tmpGrp As NXOpen.Tag = NXOpen.Tag.Null
        Dim myGroup As Group

        Dim numMembers As Integer
        Dim memberTags() As Tag

        Dim numOwningGroups As Integer
        Dim owningGroups() As Tag

        Do
            theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_group_type, tmpGrp)
            'skip the initial null tag
            If tmpGrp = NXOpen.Tag.Null Then
                Continue Do
            End If

            myGroup = Utilities.NXObjectManager.Get(tmpGrp)
            lw.WriteLine("group name: " & myGroup.Name)

            theUfSession.Group.AskGroupData(myGroup.Tag, memberTags, numMembers)
            lw.WriteLine("  group contains: " & numMembers.ToString & " members")

            For Each tempTag As Tag In memberTags
                Dim tempTaggedObj As TaggedObject = Utilities.NXObjectManager.Get(tempTag)
                lw.WriteLine("    " & tempTaggedObj.GetType.ToString)
            Next

            theUfSession.Group.AskAllOwningGroups(myGroup.Tag, numOwningGroups, owningGroups)
            If numOwningGroups > 0 Then
                lw.WriteLine("  owned by: " & numOwningGroups.ToString & " other group(s)")
                'theUfSession.UF.Free(owningGroups)
            End If

            lw.WriteLine("")
        Loop Until tmpGrp = NXOpen.Tag.Null

    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

www.nxjournaling.com
 
Thanks. Cowski. Highly appreciated.
Now I use "GetAssociatedFeature" to get the feature from tag.
But when I run the code below. I find for some feature. I can't get its name or any attributes. Could you kindly point out my fault?

Code:
       For Each tempTag As Tag In memberTags
                Dim tempTaggedObj As TaggedObject = Utilities.NXObjectManager.Get(tempTag)
                dim abody as NXOPEN.FEATURES.feature
                abody = workPart.Features.GetAssociatedFeature(tempTaggedObj)
                kk = kk+1
                lw.WriteLine(ABODY.NAME & "   " & kk)
                Dim attributes() As NXObject.AttributeInformation = aBody.GetUserAttributes()  
                For Each attribute As NXObject.AttributeInformation In attributes         
                    if attribute.Title = "Robustness" then 
                    lw.WriteLine(aBody.name & attribute.Title & " = " & attribute.StringValue) 
                    end if
                next          
            Next
 
 https://files.engineering.com/getfile.aspx?folder=df0a9842-3678-4f9a-807b-9de2ef6ea76c&file=result.jpg
It is difficult to diagnose without access to the NX file. I suspect it is one of the following:
[ul]
[li]Some geometry (such as points and curves) may not have an associated feature.[/li]
[li]A body may have more than 1 associated feature; you might want to try "abody.GetFeatureName" to see if the desired feature is returned for that particular object.[/li]
[li]The body and/or feature doesn't have the attribute you are looking for.[/li]
[/ul]

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