Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

get total number of attributes using GRIP

Status
Not open for further replies.

thuanle777

Automotive
Joined
Sep 17, 2014
Messages
9
Location
CA
Hi, I just join eng-tips.

I want to make a script that get all attributes (title and value) from and open part. Please help. Thanks
 
Are we talking about Part Attributes or Object Attributes? And do you actually have a GRIP execute license?

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Hi John,

Thanks for quick reply.
Yes I have a GRIP execute license.
I usually have a .prt file of weld points in which each weld point contains info like X_Pos,... ID, and more info that I want to extract these info. My plan is getting the total number of all attributes in each weld point and later use it as upper bound array to extract each 'title' and 'value'.
 
Can you supply a Part file with what you're looking for? Are you looking to simply dump all the attributes are would want to select something and then get only the 'Object Attributes' assigned to that object?

I have no guarantee that I could get this to work nor am I sure that I could do it quickly (I've just started my annual Fall Regional one-day User Group meeting tour, 3 down and 14 to go).

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
You are aware that you can simply go to...

Menu -> Information -> Object...

...and select all or some of the points and hit OK, and you'll get a listing window showing the names and all the attributes assigned to each point.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Does it have to be done using GRIP?
This journal code will create a green sphere on a '2 sheet' weld and a red sphere on a '3 sheet' weld. I realize it doesn't do exactly what you asked for, but it does loop through the weld points and extract an attribute from them. With a bit more work you could extract the other attributes that you need.

www.nxjournaling.com
 
Can we do it with GRIP to only select a certain titles like ID, X_pos,Y_Pos,Z_Pos, and 'Number of sheets welded'?
Thanks.
 
Yes, you could parse the data, using GRIP and perhaps a journal as well, so that only items which met your criteria would be included in the output.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Thanks cowski,

it does not have to be in GRIP (the only reason is I can run GRIP).
Your code is very close to what I need. My ultimate goal in this is weld points with color code (as in your code) and with axis (axis of approaching for weld tip). So a colored sphere with an axis going through it is good. Please give advice. Thanks.
 
John,

How can I select a title and extract value from that title?
 
Not sure what you mean by 'title'. Could you be a bit more detailed in your request?

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Hi John,
I mean attribute title and attribute value. Can I extract value from a title 'X_Pos' of one point? (Please see the previous attached picture file)
 
Yes, you should be able to select an object, check for the presence of an Attribute with a certain name (title) and extract the value of said Attribute which could then be displayed on the screen as a 'Message' or shown in the listing window or written to text file.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Here's an update to the code I linked to in my earlier post:

Code:
'report_weld_point_location

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module3

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

    Sub Main()

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

        Const undoMarkName As String = "weld point spheres"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Dim sphereDia As Double
        If workPart.PartUnits = BasePart.Units.Millimeters Then
            sphereDia = 5
        Else
            sphereDia = 0.25
        End If

        Dim theAttributeInfo As NXObject.AttributeInformation
        Dim numSheets As Integer
        Dim strWeldIVal As String
        Dim strWeldJVal As String
        Dim strWeldKVal As String
        Dim weldIVal As Double
        Dim weldJVal As Double
        Dim weldKVal As Double
        Dim weldID As String

        For Each myPt As Point In workPart.Points

            Try
                theAttributeInfo = myPt.GetUserAttribute("ID", NXObject.AttributeType.String, -1)
                weldID = theAttributeInfo.StringValue
                'lw.WriteLine("weldID: " & weldIVal.ToString)
            Catch ex As NXException
                lw.WriteLine("NX exception: " & ex.Message)
                Continue For
            Catch ex As Exception
                lw.WriteLine("exception: " & ex.Message)
                Continue For
            End Try

            Try
                theAttributeInfo = myPt.GetUserAttribute("NUMBER OF SHEETS WELDED", NXObject.AttributeType.Integer, -1)
                numSheets = theAttributeInfo.IntegerValue
                Dim sphereColor As Integer = 103
                Select Case numSheets
                    Case 2
                        'default cdf green = 36
                        sphereColor = 36
                    Case 3
                        'default cdf red = 186
                        sphereColor = 186
                    Case Else
                        sphereColor = 103
                End Select
                CreateSphereOnPoint(myPt, sphereDia, sphereColor, weldID)

            Catch ex As NXException
                Continue For
            End Try

            Try
                theAttributeInfo = myPt.GetUserAttribute("WELD_I_VALUE", NXObject.AttributeType.String, -1)
                strWeldIVal = theAttributeInfo.StringValue
                weldIVal = Double.Parse(strWeldIVal)
            Catch ex As NXException
                lw.WriteLine("NX exception: " & ex.Message)
                Continue For
            Catch ex As Exception
                lw.WriteLine("exception: " & ex.Message)
                Continue For
            End Try

            Try
                theAttributeInfo = myPt.GetUserAttribute("WELD_J_VALUE", NXObject.AttributeType.String, -1)
                strWeldJVal = theAttributeInfo.StringValue
                weldJVal = Double.Parse(strWeldJVal)
            Catch ex As NXException
                lw.WriteLine("NX exception: " & ex.Message)
                Continue For
            Catch ex As Exception
                lw.WriteLine("exception: " & ex.Message)
                Continue For
            End Try

            Try
                theAttributeInfo = myPt.GetUserAttribute("WELD_K_VALUE", NXObject.AttributeType.String, -1)
                strWeldKVal = theAttributeInfo.StringValue
                weldKVal = Double.Parse(strWeldKVal)
            Catch ex As NXException
                lw.WriteLine("NX exception: " & ex.Message)
                Continue For
            Catch ex As Exception
                lw.WriteLine("exception: " & ex.Message)
                Continue For
            End Try

            Dim origin1 As Point3d = New Point3d(0.0, 0.0, 0.0)
            Dim vector1 As Vector3d = New Vector3d(weldIVal, weldJVal, weldKVal)
            Dim direction1 As Direction
            direction1 = workPart.Directions.CreateDirection(origin1, vector1, SmartObject.UpdateOption.WithinModeling)

            CreateWeldAxis(myPt, direction1, weldID)

            lw.WriteLine("ID: " & weldID)
            lw.WriteLine("location: " & myPt.Coordinates.ToString)
            lw.WriteLine("weld vector: " & direction1.Vector.ToString)
            lw.WriteLine("number of sheets: " & numSheets.ToString)
            lw.WriteLine("")

        Next

        lw.Close()


    End Sub

    Sub CreateSphereOnPoint(ByVal cenPoint As Point, _
                            ByVal diameter As Double, _
                            ByVal color As Integer, _
                            ByVal name As String)

        Dim theColor As Integer
        If color < 0 Or color > 216 Then
            theColor = 103
        Else
            theColor = color
        End If

        Dim nullFeatures_Sphere As Features.Sphere = Nothing

        Dim sphereBuilder1 As Features.SphereBuilder
        sphereBuilder1 = workPart.Features.CreateSphereBuilder(nullFeatures_Sphere)

        Dim displayModification1 As DisplayModification
        displayModification1 = theSession.DisplayManager.NewDisplayModification()

        Try
            sphereBuilder1.Diameter.RightHandSide = diameter.ToString
            sphereBuilder1.BooleanOption.Type = GeometricUtilities.BooleanOperation.BooleanType.Create
            sphereBuilder1.CenterPoint = cenPoint

            Dim theSphere As Features.Sphere
            theSphere = sphereBuilder1.Commit()
            theSphere.SetName(name)

            displayModification1.ApplyToAllFaces = True
            displayModification1.ApplyToOwningParts = False
            displayModification1.NewColor = theColor

            Dim objects1(0) As DisplayableObject
            Dim body1 As Body = theSphere.GetBodies(0)

            objects1(0) = body1
            displayModification1.Apply(objects1)


        Catch ex As NXException

        Finally
            sphereBuilder1.Destroy()
            displayModification1.Dispose()


        End Try

    End Sub

    Sub CreateWeldAxis(ByVal thePoint As Point, _
                       ByVal theDirection As Direction, _
                       ByVal theName As String)

        Dim nullFeatures_Feature As Features.Feature = Nothing

        Dim datumAxisBuilder1 As Features.DatumAxisBuilder
        datumAxisBuilder1 = workPart.Features.CreateDatumAxisBuilder(nullFeatures_Feature)

        datumAxisBuilder1.Type = Features.DatumAxisBuilder.Types.PointAndDir

        datumAxisBuilder1.Point = thePoint

        datumAxisBuilder1.Vector = theDirection

        datumAxisBuilder1.IsAssociative = False

        Dim weldAxis As Features.DatumAxisFeature
        weldAxis = datumAxisBuilder1.CommitFeature()

        datumAxisBuilder1.Destroy()

        weldAxis.SetName(theName)

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

End Module

www.nxjournaling.com
 
hi cowski, your code works very good. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top