Region Properties for Section View

<?xml encoding=”UTF-8″>By Adam Nagy

The code which is getting Region Properties information from a given sketch can be extended for Section Views as well. You just need to create a sketch on the Section View and project the curves from that view into the region:

Sub CreateSketchForSectionView()
' Select the section view in the UI first
Dim oView As SectionDrawingView
Set oView = ThisApplication.ActiveDocument.SelectSet(1)
' Create the sketch
Dim oDSketch As DrawingSketch
Set oDSketch = oView.sketches.Add()
' Fill it with the curves from the section view
Call oDSketch.Edit
Dim oCurve As DrawingCurve
For Each oCurve In oView.DrawingCurves
Dim oEntity As SketchEntity
Set oEntity = oDSketch.AddByProjectingEntity(oCurve)
Next
Call oDSketch.ExitEdit
' Create a profile from the entities
Dim oProfile As Profile
Set oProfile = oDSketch.Profiles.AddForSolid()
' Get region properties
Dim oRegionProps As RegionProperties
Set oRegionProps = oProfile.RegionProperties
' Set the accuracy to medium.
oRegionProps.Accuracy = AccuracyEnum.kMedium
' Display the region properties of the profile.
Call MsgBox("Area: " & oRegionProps.Area)
Call MsgBox("Perimeter: " & oRegionProps.Perimeter)
Call MsgBox("Centroid: " & _
oRegionProps.Centroid.X & ", " & _
oRegionProps.Centroid.Y)
Dim adPrincipalMoments(2) As Double
Call oRegionProps.PrincipalMomentsOfInertia( _
adPrincipalMoments(0), _
adPrincipalMoments(1), _
adPrincipalMoments(2))
Call MsgBox("Principal Moments of Inertia: " & _
adPrincipalMoments(0) & ", " & _
adPrincipalMoments(1))
Dim adRadiusOfGyration(2) As Double
Call oRegionProps.RadiusOfGyration( _
adRadiusOfGyration(0), _
adRadiusOfGyration(1), _
adRadiusOfGyration(2))
Call MsgBox("Radius of Gyration: " & _
adRadiusOfGyration(0) & ", " & _
adRadiusOfGyration(1))
Dim Ixx As Double
Dim Iyy As Double
Dim Izz As Double
Dim Ixy As Double
Dim Iyz As Double
Dim Ixz As Double
Call oRegionProps.MomentsOfInertia(Ixx, Iyy, Izz, Ixy, Iyz, Ixz)
Call MsgBox(" Ixx: " & Ixx)
Call MsgBox(" Iyy: " & Iyy)
Call MsgBox(" Ixy: " & Ixy)
Call MsgBox("Rotation Angle from projected Sketch " & _
"Origin to Principal Axes: " & _
Str(oRegionProps.RotationAngle))
End Sub

 


Comments

3 responses to “Region Properties for Section View”

  1. Its a good tip, but unfortunately the Inventor ‘region properties’ tool is still inferior to the AutoCAD ‘massprop’ command.
    If you have non symetrical section, the second moment of area is calced from the sketch origin, and not the centroid of the region.
    Also no bounding box data for the region is provided.
    it should really give overall width and height data, and distances from the centroid to these extreme region extents.
    Thanks for the info though.

  2. Hi Adam,
    Thanks for posting this code snippet. You start off with “The code which is getting Region Properties information for a given sketch can be extended …”
    Do you have a reference for that code that uses a given sketch? I looked through the forums and the developer examples and did not find anything.
    Thanks,
    Chris

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading