get total number of attributes using GRIP
get total number of attributes using GRIP
(OP)
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
I want to make a script that get all attributes (title and value) from and open part. Please help. Thanks





RE: get total number of attributes using GRIP
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.
RE: get total number of attributes using GRIP
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'.
RE: get total number of attributes using GRIP
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.
RE: get total number of attributes using GRIP
I attached the picture with hightlighted info to be extract.
RE: get total number of attributes using GRIP
RE: get total number of attributes using GRIP
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.
RE: get total number of attributes 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
RE: get total number of attributes using GRIP
Thanks.
RE: get total number of attributes using GRIP
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.
RE: get total number of attributes using GRIP
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.
RE: get total number of attributes using GRIP
How can I select a title and extract value from that title?
RE: get total number of attributes using GRIP
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.
RE: get total number of attributes using GRIP
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)
RE: get total number of attributes using GRIP
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.
RE: get total number of attributes using GRIP
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 Modulewww.nxjournaling.com
RE: get total number of attributes using GRIP