Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal to add attribute to selected face

Status
Not open for further replies.

UGMasters

Automotive
Jan 22, 2008
51
Hi All,
I want to pick a face and assign an attribute
can some body help me with a Journal?
Regards
Girish.
 
Replies continue below

Recommended for you

Not certain what you are looking for. I have a journal that someone gave me once that adds an attribute to the face of a hole. This only works on cylindrical faces though. Might be simple enough to change over to what you need.


Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
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, "Face attributes")

        lw.Open()

        Dim selobj As NXObject
        Dim type As Integer
        Dim subtype As Integer
        Dim theFaces As New List(Of Face)
        Dim theUI As UI = UI.GetUI
        Dim numsel As Integer = theUI.SelectionManager.GetNumSelectedObjects()

'process the preselected Faces
        If numsel > 0 Then

            For inx As Integer = 0 To numsel - 1
                selobj = theUI.SelectionManager.GetSelectedTaggedObject(inx)

                theUfSession.Obj.AskTypeAndSubtype(selobj.Tag, type, subtype)

                If type = UFConstants.UF_solid_type Then

                    theFaces.Add(selobj)

                End If
            Next
        Else
'prompt to select Faces

            If SelectFaces("Select Faces to reset attributes", theFaces) = Selection.Response.Cancel Then
                Return
            End If

        End If

        For Each temp As Face In theFaces
            DeleteAllAttributes(temp)
'            AddFaceAttribute(temp, "TOOL_CLASS", "ALT STD")
            AddFaceAttribute(temp, "HOLE_SIZE", "DIA 9")
'            AddFaceAttribute(temp, "PURCH_OPTION", "P")
'            AddFaceAttribute(temp, "DB_PART_NAME", "NC BLANK")
        Next

        lw.Close()
    End Sub

    Function SelectFaces(ByVal prompt As String, ByRef selFace As List(Of Face)) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select Faces"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple
        Dim selObj() As TaggedObject

        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = 0
			.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_CYLINDRICAL_FACE

        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt,
        title, scope, selAction,
        includeFeatures, keepHighlighted, selectionMask_array, selObj)
        If resp = Selection.Response.Ok Then
            For Each temp As TaggedObject In selObj
                selFace.Add(temp)
            Next
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    Sub AddFaceAttribute(ByVal theFace As Face, ByVal attTitle As String, ByVal attValue As String)

        Dim markId4 As Session.UndoMarkId
        markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "add Face attribute")

        Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
        attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(theSession.Parts.Work, {theFace}, AttributePropertiesBuilder.OperationType.None)

        attributePropertiesBuilder1.IsArray = False
        attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String

        attributePropertiesBuilder1.Title = attTitle
        attributePropertiesBuilder1.StringValue = attValue

        Dim nXObject1 As NXObject
        nXObject1 = attributePropertiesBuilder1.Commit()

        Dim id1 As Session.UndoMarkId
        id1 = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible)

        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.DoUpdate(id1)

        attributePropertiesBuilder1.Destroy()

    End Sub

    Sub DeleteAllAttributes(ByVal theObject As NXObject)

        Dim attributeInfo() As NXObject.AttributeInformation = theObject.GetUserAttributes

        For Each temp As NXObject.AttributeInformation In attributeInfo
            theObject.DeleteUserAttributes(temp.Type, Update.Option.Now)
        Next

    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
 
Try this change:
Code:
.SolidBodySubtype = [s]UFConstants.UF_UI_SEL_FEATURE_CYLINDRICAL_FACE[/s] UFConstants.UF_UI_SEL_FEATURE_ANY_FACE

www.nxjournaling.com
 


Good morning Cowski,

is there any way we can collect the face area value and assign to the part
as shown in the picture.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor