Area moment of inertia

Hello,
Is there any way to get area moment of inertia of a section by parametically?
Thanks

In NX, the result of the "Section Inertia" command is not associative (at least not up through NX 9). However, you can create a journal that will update existing measurements. The code below is a "proof of concept" journal; it will probably need some tweaking to get what you want out of it.

Before you run it, create at least one associative intersection curve feature in your part and rename it (right click the feature in the tree and choose rename) to section_n, where n is a number. When you run the journal, it will search for intersection curve features with section in the name, run the section command on the feature curves, extract the area of the section, and create/update an expression named section_n_area with the section area value. Edit the model so that the section curve feature changes and run the journal again, the PMI note and the expression values will update.


'NXJournaling.com
'June 12, 2013
'NX8
'Journal looks for intersection curve features named "section_n", extracts section properties
'from the section curves, and creates/updates expressions with the desired section properties.

'test version: only the section area is extracted and saved as an expression.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features
Imports NXOpen.UF
Imports NXOpenUI

Module Module1

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

Sub Main()

Dim response As Integer

If workPart Is Nothing Then
response = theUISession.NXMessageBox.Show("Warning", NXMessageBox.DialogType.Warning, "Journal requires an active part to run")
Exit Sub
End If

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

For Each myFeature As Feature In workPart.Features
If myFeature.FeatureType.ToUpper = "INTERSECTION_CURVES" Then
myFeature = DirectCast(myFeature, Features.IntersectionCurve)
Dim featureName As String = myFeature.Name
If featureName.ToLower.Contains("section") Then
'delete existing pmi note if it exists
For Each myPmi As Annotations.PmiNote In workPart.Notes
If myPmi.Name.ToUpper = featureName.ToUpper Then
DeleteObject(myPmi)
End If
Next

AnalyzeSection(myFeature)
End If
End If
Next

End Sub

Public Sub AnalyzeSection(ByVal sectionCurves As Features.IntersectionCurve)

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim nullFeatures_SectionInertiaAnalysis As Features.SectionInertiaAnalysis = Nothing

Dim sectionInertiaAnalysisBuilder1 As Features.SectionInertiaAnalysisBuilder
sectionInertiaAnalysisBuilder1 = workPart.Features.CreateSectionInertiaAnalysisBuilder(nullFeatures_SectionInertiaAnalysis)
sectionInertiaAnalysisBuilder1.Type = Features.SectionInertiaAnalysisBuilder.Types.ExistingSection
sectionInertiaAnalysisBuilder1.MassPropertyType = Features.SectionInertiaAnalysisBuilder.PropertyType.Solid
sectionInertiaAnalysisBuilder1.ValidityFlag = False
sectionInertiaAnalysisBuilder1.CurveCollector.SetAllowedEntityTypes(Section.AllowTypes.OnlyCurves)

Dim features1(0) As Features.Feature

features1(0) = sectionCurves
Dim curveFeatureRule1 As CurveFeatureRule
curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1)

sectionInertiaAnalysisBuilder1.CurveCollector.AllowSelfIntersection(True)

Dim rules1(0) As SelectionIntentRule
rules1(0) = curveFeatureRule1
Dim curve1 As Curve = sectionCurves.GetEntities(0)

Dim nullNXObject As NXObject = Nothing

'use AskCurveProps to find start point of curve
'curve parameter is normalized (0 to 1)
Dim stPt(2) As Double
Dim junk3(2) As Double
Dim junk1 As Double
theUfSession.Modl.AskCurveProps(curve1.Tag, 0.0, stPt, junk3, junk3, junk3, junk1, junk1)
Dim curveStartPoint As Point3d = New Point3d(stPt(0), stPt(1), stPt(2))

Dim helpPoint1 As Point3d = curveStartPoint
sectionInertiaAnalysisBuilder1.CurveCollector.AddToSection(rules1, curve1, nullNXObject, nullNXObject, helpPoint1, Section.Mode.Create, False)

sectionInertiaAnalysisBuilder1.ValidityFlag = False

Dim nXObject1 As NXObject
nXObject1 = sectionInertiaAnalysisBuilder1.Commit()

Dim myNotes() As Annotations.PmiNote
myNotes = sectionInertiaAnalysisBuilder1.GetAnnotation
'MsgBox("set note name = section name: " & sectionCurves.Name)
myNotes(0).SetName(sectionCurves.Name)
Dim myText() As String = myNotes(0).GetText

'show multi line messages
'theUISession.NXMessageBox.Show("Multiple line message", NXMessageBox.DialogType.Information, myText)

theSession.SetUndoMarkName(markId1, "Section Inertia Analysis")

sectionInertiaAnalysisBuilder1.Destroy()

UpdateSectionExpressions(sectionCurves.Name, myText)

End Sub

Sub UpdateSectionExpressions(ByVal sectionName As String, ByVal sectionProps() As String)

Dim sectionArea As String
Dim sectionAreaUnits As String
For Each propLine As String In sectionProps
If propLine.ToLower.Contains("area") Then
sectionAreaUnits = propLine.Substring(propLine.IndexOf("[") + 1, propLine.IndexOf("]") - propLine.IndexOf("[") - 1)
sectionArea = propLine.Substring(propLine.IndexOf(":") + 1, propLine.IndexOf("[") - propLine.IndexOf(":") - 1)
End If
Next

'edit/create area expression
Try
Dim myAreaExpression As Expression
myAreaExpression = workPart.Expressions.FindObject(sectionName & "_area")
myAreaExpression.Value = CDbl(sectionArea)

Catch ex As NXException
If ex.ErrorCode = 3520016 Then
'not found, let's create it
Dim unit1 As Unit

If workPart.PartUnits = BasePart.Units.Inches Then
unit1 = CType(workPart.UnitCollection.FindObject("SquareInch"), Unit)
Else
unit1 = CType(workPart.UnitCollection.FindObject("SquareMilliMeter"), Unit)
End If
workPart.Expressions.CreateWithUnits(sectionName & "_area = " & sectionArea, unit1)
Else
'other NX error, report it
MsgBox("error: " & ex.ErrorCode & ", " & ex.Message)
End If

Catch ex As Exception
'other error, report it
MsgBox("error: " & ex.GetType.ToString & ", " & ex.Message)

End Try

End Sub

Sub DeleteObject(ByVal objDelete As NXObject)

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Delete")

Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete

theSession.UpdateManager.ClearErrorList()

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")

Dim objects1(0) As NXObject
objects1(0) = objDelete

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(objects1)

Dim notifyOnDelete2 As Boolean
notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete

Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId2)

theSession.DeleteUndoMark(markId1, Nothing)

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

Thank you very much!
What is the maximum and minimum area moment of inertia values (instead of area)?

The code above shows how to parse the PMI note for the area value. A similar strategy can be used for the min/max moment of inertia values.