Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Journal - find attribute of .BodyFeature

Status
Not open for further replies.

MANox

Mechanical
Apr 2, 2007
117
0
0
PL
Hello,

I need a litte help:
I add atributte ENDTYPE to BodyFeature:
Code:
    Private Sub AddAttribute(nxObject2 As NXObject, endAttr As String, isSubstract As Boolean)

        If isSubstract = False Then
            Dim bodyFeature1 As NXOpen.Features.BodyFeature = CType(nxObject2, NXOpen.Features.BodyFeature)
            Dim edges1() = bodyFeature1.GetEdges
            Dim body1 As Body = edges1(0).GetBody
            Dim feature1 As Features.Feature = body1.GetFeatures(0)
            feature1.SetUserAttribute("EndType", -1, endAttr, Update.Option.Now)
        End If
    End Sub

And I can find this BodyFeature with:
Code:
 For Each feature1 As Features.BodyFeature In Body1.GetFeatures
            If feature1.FeatureType = "SIMPLE HOLE" Or feature1.FeatureType = "HOLE PACKAGE" Then
                Dim exps() As Expression
                Dim index2 As Integer = -1
                exps = feature1.GetExpressions()
                index2 = exps(0).Description.IndexOf("Threaded")
                If index2 > 0 Then
                    If feature1.HasUserAttribute("ENDTYPE", NXObject.AttributeType.String, -1) Then
                        Dim attributeInfo As NXObject.AttributeInformation = feature1.GetUserAttribute("ENDTYPE", NXObject.AttributeType.String, 0)
                        lw.WriteLine(attributeInfo.StringValue)
                    Else
                        lw.WriteLine("no attributte")
                    End If
                End If
            End If
        Next

And now I want add posibility fo change attribute by select this BodyFeature.
I try with:
Code:
    Function SelectFeature(ByVal prompt As String, ByRef featureToReturn As NXObject) As Boolean

        Dim theUI As UI = UI.GetUI
        Dim title As String = prompt
        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.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple
        Dim selObj1 As TaggedObject = Nothing


        With selectionMask_array(0)
            .Type = UFConstants.UF_feature_type
            '.Subtype = 
            '.SolidBodySubtype = UFConstants.UF_dim_hole_subtype
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, title, scope, selAction, includeFeatures, keepHighlighted, selectionMask_array, selObj1, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            Dim i As Integer = 0
            featureToReturn = Utilities.NXObjectManager.Get(selObj1.Tag)
            Return True
        Else
            featureToReturn = Nothing
            Return False
        End If

    End Function

and
Code:
Do While SelectFeature("Select thread to edition", myFeature) = True
            'MsgBox(myFeature.JournalIdentifier)
            Dim myBodyFeature = CType(myFeature, BodyFeature)
            If myBodyFeature.FeatureType = "SIMPLE HOLE" Or myBodyFeature.FeatureType = "HOLE PACKAGE" Then

                Dim exps() As Expression
                Dim index2 As Integer = -1
                exps = myBodyFeature.GetExpressions()
                index2 = exps(0).Description.IndexOf("Threaded")
                If index2 > 0 Then
                    ' MsgBox(myFeature.FeatureType)
                    If myBodyFeature.HasUserAttribute("ENDTYPE", NXObject.AttributeType.String, -1) Then
                        Dim attributeInfo As NXObject.AttributeInformation = myBodyFeature.GetUserAttribute("ENDTYPE", NXObject.AttributeType.String, 0)
                        MsgBox(attributeInfo.StringValue)
                    Else
                        MsgBox("Selected feature haven't attribute ENDTYPE. I'm so sorry bro (or sis)")
                    End If
                Else
                    MsgBox("select thread, please...")
                End If
            End If
        Loop

(and many other combination), but I can't find solution.
Maybe somebody see where I wrong.

Best regards

MANok
TC14
NX2027

 
Replies continue below

Recommended for you

There is another selection function: "SelectWithSingleDialog", that will allow more filtering options than available to "SelectTaggedObject". This example shows how to filter for tube features. The filter function could be modified to look for a specific attribute rather than the feature type.

www.nxjournaling.com
 
Thank You cowski for proposition.
I try with it without sucess. But I think problem is in different part of code.
In attachent is example file.
Each thread has attribute ENDTYPE.
When I use journal:
Code:
Option Strict Off
Option Explicit On
Imports NXOpen
Imports NXOpen.UF

Module Helper2
    Sub Main()
        Dim theSession As Session = Session.GetSession()
        Dim theUI As UI = UI.GetUI()
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        Dim lw As ListingWindow = theSession.ListingWindow
        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display
        Dim Body1 As Body
        Dim Bryla As NXObject
        Dim prompt As String = "Wskaż bryłę do której dodajesz końcówki"

        If SelectSolid("wskaż bryłę", Bryla) = Selection.Response.Cancel Then
            Exit Sub
        Else
            If TypeOf Bryla Is Body Then
                Body1 = CType(Bryla, Body)
            End If
        End If
        lw.Open()
        For Each feature1 As Features.BodyFeature In Body1.GetFeatures
            If feature1.HasUserAttribute("ENDTYPE", NXObject.AttributeType.String, -1) Then
                Dim attributeInfo As NXObject.AttributeInformation = feature1.GetUserAttribute("ENDTYPE", NXObject.AttributeType.String, 0)
                lw.WriteLine(attributeInfo.StringValue)
            End If
        Next
    End Sub

    Function SelectSolid(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response
        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a solid"
        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.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
        End With
        Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(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

End Module

It listing attribute for all feature with ENDTYPE Attribute.

But when I want select single feature:

Code:
Option Strict Off
Option Explicit On

Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features

Module Helper2

    Sub Main()
        Dim theSession As Session = Session.GetSession()
        Dim theUI As UI = UI.GetUI()
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        Dim lw As ListingWindow = theSession.ListingWindow
        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display

        Dim object1 As NXObject = Nothing

        Dim featureBody1 As BodyFeature = Nothing
        If SelectFeature("Select thread", object1) = Selection.Response.Cancel Then
            Exit Sub
        Else
            If TypeOf object1 Is BodyFeature Then
                featureBody1 = CType(object1, BodyFeature)
            End If
        End If
        lw.Open()

        If Not featureBody1 Is Nothing Then
            If featureBody1.HasUserAttribute("ENDTYPE", NXObject.AttributeType.String, -1) Then
                Dim attributeInfo As NXObject.AttributeInformation = featureBody1.GetUserAttribute("ENDTYPE", NXObject.AttributeType.String, 0)
                lw.WriteLine(attributeInfo.StringValue)
            Else
                lw.WriteLine("no attribute")
            End If
        Else
            lw.WriteLine("no feature")
        End If
    End Sub

    Function SelectFeature(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a feature"
        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.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UFConstants.UF_feature_type
            .Subtype = UFConstants.UF_all_subtype
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(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
End Module

journal says: "no attribute".
I can't find different between those journals. Why one give me value, the other - no.
I think it something stupid, but I don't see it.

Maybe somebody can help

Best regards

MANok
NX2027
TC14
 
 https://files.engineering.com/getfile.aspx?folder=5b783a81-6987-4426-8783-ab5951589a23&file=End_type_helper.prt
When you create a threaded hole with the "hole" command, NX creates a number of features: a "hole package" (what you see in the part navigator) and for each location specified, it creates a body feature (the hole) and a thread feature, both of which are internal to the hole package and cannot be directly accessed by the user. It appears that your code is assigning the attribute to the internal hole feature instead of the external "package" feature that the user sees in the navigator.

www.nxjournaling.com
 
Thanks cowski,

now it is clear for me.
One element - three features with same name... - Gods of NX must be crazy...

Many thanks.

Best regards

MANok
NX2027
TC14
 
Status
Not open for further replies.
Back
Top