Hi everyone.
The code bellow, creates a feature point into Part Navigator, named CoG. Great for now, even for single body.
Some questions came out to improve this code.
1st - Selection mode is looking for everything in the wok part. I'm just looking for displayed parts and components. How can I set this?
2nd - Regarding 1st, the mass in some cases that I've tested, was double when using Wave linked geometry, except when set the body base as non-geometric (as reference, for Teamcenter users). There's some tips for that too?
3rd - how can I set this point to be updated if its already exists and send it to the last feature order?
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 lw As ListingWindow = theSession.ListingWindow
Sub Main()
Dim workPart As Part = theSession.Parts.Work
lw.Open()
Dim max As Integer
If workPart.PartUnits = Part.Units.Inches Then
max = 10
Else 'metric file
max = 250
End If
Const undoMarkName As String = "report assembly mass props"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim bodyTags As New List(Of Tag)
bodyTags = AskAllBodyTags(theSession.Parts.Display)
lw.WriteLine("number of body tags found: " & bodyTags.Count.ToString)
Dim acc_value(10) As Double
acc_value(0) = 0.999
Dim mass_props(46) As Double
Dim stats(12) As Double
theUfSession.Modl.AskMassProps3d(bodyTags.ToArray, bodyTags.Count, 1, 1, 0.03, 1, acc_value, mass_props, stats)
lw.WriteLine("Mass: " & mass_props(2).ToString & " lbf")
lw.WriteLine("Center of Mass:")
lw.writeline("X: " & mass_props(3).ToString)
lw.writeline("Y: " & mass_props(4).ToString)
lw.writeline("Z: " & mass_props(5).ToString)
Dim p1 = NXOpen.Session.GetSession.Parts.Work.Points.CreatePoint(New Point3d(mass_props(3), mass_props(4), mass_props(5)))
p1.SetVisibility(SmartObject.VisibilityOption.Visible)
Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature = Nothing
Dim pointFeatureBuilder1 As NXOpen.Features.PointFeatureBuilder = Nothing
pointFeatureBuilder1 = workPart.BaseFeatures.CreatePointFeatureBuilder(nullNXOpen_Features_Feature)
pointFeatureBuilder1.Point = p1
Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = pointFeatureBuilder1.Commit()
nXObject1.SetName("CoG")
pointFeatureBuilder1.Destroy()
lw.Close()
End Sub
Function AskAllBodyTags(ByVal thePart As Part) As List(Of Tag)
Dim theBodyTags As New List(Of Tag)
Dim aBodyTag As Tag = Tag.Null
Do
theUfSession.Obj.CycleObjsInPart(thePart.Tag,
UFConstants.UF_solid_type, aBodyTag)
If aBodyTag = Tag.Null Then
Exit Do
End If
Dim theType As Integer, theSubtype As Integer
theUfSession.Obj.AskTypeAndSubtype(aBodyTag, theType, theSubtype)
If theSubtype = UFConstants.UF_solid_body_subtype Then
Dim bodyType As Integer = 0
theUfSession.Modl.AskBodyType(aBodyTag, bodyType)
If bodyType = UFConstants.UF_MODL_SOLID_BODY Then
theBodyTags.Add(aBodyTag)
End If
End If
Loop While True
Return theBodyTags
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module
re: center of gravity
NX has some functionality built into its measure commands that will create a point at the center of gravity of the chosen bodies and will associatively update the point location as the bodies change (the feature needs to be updated if/when new bodies are added). This functionality can be found in the measure, or measure bodies command, depending on the version of NX that you are using.
Now, on to your questions.
1) you are only looking for displayed parts and components. Does this mean that you are only interested in the bodies that are currently visible (i.e. not hidden or assigned to an invisible layer)? If so, you can get the body object from the tag and check its hidden and layer status. If the body is visible, add it to the list; if invisible, ignore it.
2) In some cases this depends on how the wave link was created, but I'm going to assume that a body in a component was wave linked up to the assembly level. To exclude the original body in this case you can suppress the component (using the "always suppressed" option) or change the component reference set to something that does not include the original body (such as the "empty" ref set).
3) If the "CoG" name is unique, you check for the existence of this point feature before creating a new one. If it exists, you can update the coordinates of the existing point and reorder the feature to the end instead of creating a new point feature.
Hi, thanks for reply.
Hi, thanks for reply.
Just for the record, I know that functionality. The problem came from someone assuming that it's time and processing consuming by using this tool.
I'll working around those topics that you've raised.
Thanks.
Fernando Alves
Mechanical Designer / NX11 - TeamCenter