Centre of gravity of a Face

Hello All,

I'm creating a report in the ship structure application, and had dificulty to extract the COG for each face.

I'm using the function ufs.Modl.AskMassProps3d but this function needs a body(solid or sheet body)

Is there another function that ask for a Face rather than a body?

As another option there is any way to generate a "virtual" body from a face, then use the AskMassProps3d ?

Thank you in advance

The "extract geometry" command will create a single face sheet body of the chosen face that can then be used with the AskMassProps3d command. This might not be ideal if you have a lot of faces to process...

A similar question was asked in the Siemens forum a while back. User ChetakKadam gives some code that uses one of the new measuring tools (looks like NX 12 or later); I've not tested the code, but it might work for you.

https://community.sw.siemens.com/s/question/0D54O00006bjGsaSAE/centre-of...

Thank you Nxjournalling.I was trying to investigate and solve without disturbing you again. But I couldn't...
I made some tests considering the solution proposed by ChetakKadam but I could not find the expression created. It's not clear for me the "Saving results as a timestamp, you can fetch results from Expressions."

To save the result as timestamp is this? >> measureMaster1.UpdateAtTimestamp = true

to fetch results from Expressions, I need to loop by the expressions find the expression "FaceExp"(in my example >> measureMaster1.SetNameSuffix("FaceExp") )?

I tryed the following code, after the facepropertiesElement command I loop in the Expressions, but just find p0, p1, p2, p3 and the cog is not in these expressions.


'face cog
Dim measureMaster1 As NXOpen.MeasureMaster = Nothing
measureMaster1 = workPart.MeasureManager.MasterMeasurement()
measureMaster1.SequenceType = NXOpen.MeasureMaster.Sequence.Free
measureMaster1.UpdateAtTimestamp = true
measureMaster1.SetNameSuffix("FaceExp")

Dim faceUnits1(5) As NXOpen.Unit
faceUnits1(0) = unitArea
faceUnits1(1) = unitLen
faceUnits1(2) = unitLen
faceUnits1(3) = unitLen
faceUnits1(4) = unitLen

Dim faces1(0) As NXOpen.Face

faces1(0) = f
Dim faceDumbRule1 As NXOpen.FaceDumbRule = Nothing
faceDumbRule1 = workPart.ScRuleFactory.CreateRuleFaceDumb(faces1)

Dim rules1(0) As NXOpen.SelectionIntentRule
rules1(0) = faceDumbRule1
Dim scCollector1 As NXOpen.ScCollector = Nothing
scCollector1 = workPart.ScCollectors.CreateCollector()

scCollector1.ReplaceRules(rules1, False)

Dim measureElement1 As NXOpen.MeasureElement = Nothing
measureElement1 = workPart.MeasureManager.FacePropertiesElement(measureMaster1, faceUnits1, 0, true, 0.98999999999999999,scCollector1)

lw.Open()
For Each temp As Expression In workPart.Expressions
lw.WriteLine("---------------------------------")
lw.WriteLine("name: " & temp.Name)
lw.WriteLine("right hand side: " & temp.RightHandSide)
Next

Thank you in advance

After investigating better the analysis tool, I was able to create the expression with the values of COG as indicated in the linked post.
With the journal helps bellow you can find the code to extract the COG of a face. Thank you again Nxjournalling to the insights.
In this code you need to provide as arguments the face and the workpart.

Sub MeasureFaceCOG(face1 As NXOpen.Face, wp As NXOpen.Part)

Dim markId As NXOpen.Session.UndoMarkId = Nothing
markId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Measure COG")

Dim scCollector1 As NXOpen.ScCollector = Nothing
scCollector1 = wp.ScCollectors.CreateCollector()

scCollector1.SetMultiComponent()

Dim faces1(0) As NXOpen.Face
faces1(0) = face1
Dim faceDumbRule1 As NXOpen.FaceDumbRule = Nothing
faceDumbRule1 = wp.ScRuleFactory.CreateRuleFaceDumb(faces1)

Dim rules1(0) As NXOpen.SelectionIntentRule
rules1(0) = faceDumbRule1
scCollector1.ReplaceRules(rules1, False)

Dim measureMaster1 As NXOpen.MeasureMaster = Nothing
measureMaster1 = wp.MeasureManager.MasterMeasurement()

measureMaster1.SequenceType = NXOpen.MeasureMaster.Sequence.Free

measureMaster1.UpdateAtTimestamp = True

measureMaster1.SetNameSuffix("Face")

Dim faceUnits1(4) As NXOpen.Unit
Dim unit1 As NXOpen.Unit = CType(wp.UnitCollection.FindObject("SquareMeter"), NXOpen.Unit)

faceUnits1(0) = unit1
Dim unit2 As NXOpen.Unit = CType(wp.UnitCollection.FindObject("Meter"), NXOpen.Unit)

faceUnits1(1) = unit2
faceUnits1(2) = unit2
faceUnits1(3) = unit2
faceUnits1(4) = unit2
Dim measureElement1 As NXOpen.MeasureElement = Nothing
measureElement1 = wp.MeasureManager.FacePropertiesElement(measureMaster1, faceUnits1, 0, True, 0.98999999999999999, scCollector1)

measureElement1.MeasureObject1 = NXOpen.MeasureElement.Measure.Object

measureElement1.SingleSelect1 = True

measureElement1.SetExpressionState(0, False)

measureElement1.SetGeometryState(0, False)

measureElement1.SetAnnotationState(0, False)

measureElement1.SetApproximateState(0, False)

measureElement1.SetExpressionState(1, False)

measureElement1.SetGeometryState(1, False)

measureElement1.SetAnnotationState(1, False)

measureElement1.SetApproximateState(1, False)

measureElement1.SetExpressionState(2, False)

measureElement1.SetGeometryState(2, False)

measureElement1.SetAnnotationState(2, False)

measureElement1.SetApproximateState(2, False)

measureElement1.SetExpressionState(3, True)

measureElement1.SetGeometryState(3, False)

measureElement1.SetAnnotationState(3, False)

measureElement1.SetApproximateState(3, False)

measureElement1.SetExpressionState(4, False)

measureElement1.SetGeometryState(4, False)

measureElement1.SetAnnotationState(4, False)

measureElement1.SetApproximateState(4, False)

measureElement1.SetExpressionState(5, False)

measureElement1.SetGeometryState(5, False)

measureElement1.SetAnnotationState(5, False)

measureElement1.SetApproximateState(5, False)

lw.Open()
For Each temp As Expression In wp.Expressions
If temp.RightHandSide like "*centroid*" Then
Dim CG As Point3D = temp.PointValue
lw.WriteLine("X: " & Cstr(CG.X))
lw.WriteLine("Y: " & Cstr(CG.Y))
lw.WriteLine("Z: " & Cstr(CG.Z))
End If
Next

Dim marksRecycled1 As Boolean = Nothing
Dim undoUnavailable1 As Boolean = Nothing
theSession.UndoLastNVisibleMarks(1, marksRecycled1, undoUnavailable1)

End Sub

Best regards