iLogic Code to Find Area Moment of Inertia

iLogic Code to Find Area Moment of Inertia

Anonymous
Not applicable
2,394 Views
8 Replies
Message 1 of 9

iLogic Code to Find Area Moment of Inertia

Anonymous
Not applicable

Hi,

 

Is there a way to find the area moment of inertia using iLogic? I know that the area moment of inertia can be found by the Cross Section Analysis tool (Inspect -> Section) and the Region Properties Tool (Inspect -> Measure). Is there any way to access area moment of inertia properties using iLogic?

 

I don't want to use iProperties because that gives the mass moment of inertia, not area moment of inertia.

 

Thanks.

0 Likes
Accepted solutions (1)
2,395 Views
8 Replies
Replies (8)
Message 2 of 9

Sergio.D.Suárez
Mentor
Mentor

Hi, try this ilogic code when selecting a flat face.

 

Dim doc = ThisDoc.Document
oCD = doc.componentdefinition
Dim oCommandMgr As CommandManager 
oCommandMgr = ThisApplication.CommandManager 

oFace = oCommandMgr.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select planar Face")
	If oFace Is Nothing Then Exit Sub

oSk = oCD.Sketches.Add(oFace)
oSk.Edit

oCommandMgr.ControlDefinitions("SketchProjectCutEdgesCmd").Execute

oProfile = oSk.Profiles.AddForSolid 
dArea = oProfile.RegionProperties.Area
 
 Dim adPrincipalMoments(2) As Double
 oProfile.RegionProperties.PrincipalMomentsOfInertia( _
    adPrincipalMoments(0), _
    adPrincipalMoments(1), _
    adPrincipalMoments(2))

MsgBox("Area: " & Round(dArea,3)  & " cm^2" & vbCrLf & _
		"Ix: " & Round(adPrincipalMoments(0),3) & " cm^4" & vbCrLf & _
		"Iy: " & Round(adPrincipalMoments(1),3) & " cm^4" )

For i As Integer = 1 To 4
oCommandMgr.ControlDefinitions.Item("AppUndoCmd").Execute 
next

 I have developed it based on these two great contributions if you want to study them.

 

https://adndevblog.typepad.com/manufacturing/2014/06/region-properties-for-section-view.html

 

https://forums.autodesk.com/t5/inventor-customization/cross-section-analysis-vba/td-p/8462247


I hope you find them useful. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 9

Anonymous
Not applicable

Thank you very much for your help, this code works and is extremely useful for me. Is there a way to automatically make the Area, Ix, and Iy into parameters or custom iProperties once the planar face has been selected?

 

Thanks again!

0 Likes
Message 4 of 9

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, try the following code

 

Dim doc = ThisDoc.Document
oCD = doc.componentdefinition
Dim oCommandMgr As CommandManager 
oCommandMgr = ThisApplication.CommandManager 

oFace = oCommandMgr.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select planar Face")
	If oFace Is Nothing Then Exit Sub

oSk = oCD.Sketches.Add(oFace)
oSk.Edit

oCommandMgr.ControlDefinitions("SketchProjectCutEdgesCmd").Execute

oProfile = oSk.Profiles.AddForSolid 
dArea = oProfile.RegionProperties.Area
 
 Dim adPrincipalMoments(2) As Double
 oProfile.RegionProperties.PrincipalMomentsOfInertia( _
    adPrincipalMoments(0), _
    adPrincipalMoments(1), _
    adPrincipalMoments(2))

MsgBox("Area: " & Round(dArea,3)  & " cm^2" & vbCrLf & _
		"Ix: " & Round(adPrincipalMoments(0),3) & " cm^4" & vbCrLf & _
		"Iy: " & Round(adPrincipalMoments(1),3) & " cm^4" )

For i As Integer = 1 To 4
oCommandMgr.ControlDefinitions.Item("AppUndoCmd").Execute 
Next

iProperties.Value("Custom", "Section_Ix") = Round(adPrincipalMoments(0), 3) & " cm^4"
iProperties.Value("Custom", "Section_Iy") = Round(adPrincipalMoments(1), 3) & " cm^4"

 I hope it is useful for you. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 9

Anonymous
Not applicable

Thank you again, I appreciate your help. I'm curious, is there a way to get these values in inches instead of centimeters? I already applied the unit conversions to my code, but I'm wondering if there is a way to calculate the values in inches.

 

 

0 Likes
Message 6 of 9

Sergio.D.Suárez
Mentor
Mentor
' Get the active part document.
Dim oDoc As PartDocument = ThisDoc.Document

Dim Num_cm As Double = 2.54
' Get the UnitsOfMeasure object which is used to do unit conversions.
Dim oUOM As UnitsOfMeasure= oDoc.UnitsOfMeasure
' Convert the volume to the current document units.
Dim Num_in As String = oUOM.GetStringFromValue(Num_cm, oUOM.GetStringFromType(11272))
		
MessageBox.Show(Num_in)

'------------------Available units------------------------------------------
'kAcreAreaUnits 11301 Acre Area. 
'kAmpElectricalCurrentUnits 11327 Amp electrical Current. 
'kBooleanUnits 11347 Boolean (Yes/No). 
'kBTUWorkUnits 11320 BTU Work. 
'kCalorieWorkUnits 11319 Calorie Work. 
'kCandelaLuminousIntensityUnits 11342 Candela luminous intensity. 
'kCelsiusTemperatureUnits 11296 Celsius Temperature. 
'kCentimeterLengthUnits 11268 Centimeter Length. 
'kCircularMilAreaUnits 11326 CircularMil Area. 
'kCompositeUnits 11322 Composite. 
'kCoulombElectricalChargeUnits 11330 Coulomb electrical Charge. 
'kCupVolumeUnits 11306 Cup Volume. 
'kDatabaseAngleUnits 11277 Database units for angle -- ALWAYS Radian. 
'kDatabaseLengthUnits 11267 Database units for length -- ALWAYS Centimeter. 
'kDatabaseMassUnits 11282 Database units for mass -- ALWAYS Kilogram. 
'kDatabaseTemperatureUnits 11294 Database units for temperature -- ALWAYS Kelvin. 
'kDatabaseTimeUnits 11289 Database units for time -- ALWAYS Second. 
'kDefaultDisplayAngleUnits 11276 Current default display units for Angle. 
'kDefaultDisplayLengthUnits 11266 Current default display units for length. 
'kDefaultDisplayMassUnits 11281 Current default display units for Mass. 
'kDefaultDisplayTemperatureUnits 11293 Current default display units for Temperature. 
'kDefaultDisplayTimeUnits 11288 Current default display units for Time. 
'kDegreeAngleUnits 11279 Degree Angle. 
'kDyneForceUnits 11312 Dyne Force. 
'kErgWorkUnits 11318 Erg Work. 
'kFahrenheitTemperatureUnits 11297 Fahrenheit Temperature. 
'kFaradElectricalCapacitanceUnits 11331 Farad electrical Capacitance. 
'kFeetPerSecondSpeedUnits 11299 FeetPerSecond Speed. 
'kFootLengthUnits 11273 Foot Length. 
'kGallonVolumeUnits 11303 Gallon Volume. 
'kGammaMagneticInductionUnits 11337 Gamma magnetic Induction. 
'kGaussMagneticInductionUnits 11338 Gauss magnetic Induction. 
'kGradAngleUnits 11280 Grad Angle. 
'kGramMassUnits 11284 Gram Mass. 
'kHenryElectricalInductanceUnits 11339 Henry electrical Inductance. 
'kHertzFrequencyUnits 11341 Hertz Frequency. 
'kHorsePowerPowerUnits 11316 HorsePower Power. 
'kHourTimeUnits 11292 Hour Time. 
'kInchLengthUnits 11272 Inch Length. 
'kJouleWorkUnits 11317 Joule Work. 
'kKelvinTemperatureUnits 11295 Kelvin Temperature. 
'kKilogramMassUnits 11283 Kilogram Mass. 
'kKSIPressureUnits 11310 KSI Pressure. 
'kLbForceUnits 11313 Lb Force. 
'kLbMassMassUnits 11286 LbMass Mass. 
'kLiterVolumeUnits 11302 Liter Volume. 
'kLumenLuminousFluxUnits 11343 Lumen luminous flux. 
'kLuxIlluminationUnits 11344 Lux illumination. 
'kMaxwellMagneticFluxUnits 11335 Maxwell magnetic Flux. 
'kMeterLengthUnits 11270 Meter Length. 
'kMetersPerSecondSpeedUnits 11298 MetersPerSecond Speed. 
'kmhoElectricalConductanceUnits 11333 mho electrical Conductance. 
'kMicronLengthUnits 11271 Micron Length. 
'kMileLengthUnits 11275 Mile Length. 
'kMilesPerHourSpeedUnits 11300 MilesPerHour Speed. 
'kMilLengthUnits 11324 Mil Length. 
'kMillimeterLengthUnits 11269 Millimeter Length. 
'kMinuteTimeUnits 11291 Minute Time. 
'kMoleSubstanceUnits 11345 Mole Substance Or gram molecular weight. 
'kNauticalMileLengthUnits 11323 NauticalMile Length. 
'kNewtonForceUnits 11311 Newton Force. 
'kOerstedMagneticInductionUnits 11340 Oersted magnetic Induction. 
'kOhmElectricalResistanceUnits 11329 Ohm electrical Resistance. 
'kOunceForceUnits 11314 Ounce Force. 
'kOunceMassUnits 11287 Ounce Mass. 
'kOunceVolumeUnits 11307 Ounce Volume. 
'kPascalPressureUnits 11308 Pascal Pressure. 
'kPintVolumeUnits 11305 Pint Volume. 
'kPSIPressureUnits 11309 PSI Pressure. 
'kQuartVolumeUnits 11304 Quart Volume. 
'kRadianAngleUnits 11278 Radian Angle. 
'kRPMAngularVelocityUnits 11321 RPM AngularVelocity. 
'kSecondTimeUnits 11290 Second Time. 
'kSiemensElectricalConductanceUnits 11332 Siemens electrical Conductance. 
'kSlugMassUnits 11285 Slug Mass. 
'kSteradianAngleUnits 11325 Steradian Angle. 
'kTeslaMagneticInductionUnits 11336 Tesla magnetic Induction. 
'kTextUnits 11346 Text (String). 
'kUnitlessUnits 11265 No dimension associated with this value. 
'kVoltElectricalVoltageUnits 11328 Volt electrical Voltage. 
'kWattPowerUnits 11315 Watt Power. 
'kWeberMagneticFluxUnits 11334 Weber magnetic Flux. 
'kYardLengthUnits 11274 Yard Length. 

 Here you have a code to change units of the string.
I have placed the list below. Execute it in a new rule and study it.
Remember to mark as a solution if any answer has served you. Best regards!!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 7 of 9

Anonymous
Not applicable

Thank you so much for your help, this is exactly what I needed! I appreciate it.

0 Likes
Message 8 of 9

jrohit1110
Enthusiast
Enthusiast

Hi! @Sergio.D.Suárez  

Can you provide me a code to export Mass Moment of Inertia from properties to parameters for an assembly? I intend to use it to export the highlighted parameters to an excel sheet. 

 
 

Warm Regards,

Rohit Kumar 

 

0 Likes
Message 9 of 9

tomislav.peran
Advocate
Advocate

Amazing!

0 Likes