.NET

Reply
Active Contributor
Posts: 46
Registered: ‎07-31-2009
Message 1 of 3 (311 Views)
Accepted Solution

Principal Moments of a region (or closed polyline)

311 Views, 2 Replies
08-29-2013 06:03 AM

Hi all,

 

I'm trying to calculate the principal moments (and section modulus) of a slection of closed polylines.

On this blog, I read that there are some new classes and functions in the AutoCad 2014 objectARX that can do this.

 

The one that interests me the most is 'RegionAreaProperties.PrincipalMoments Property'.

 

However with my limited programming skills, I can't get it to work in vb.net.

I thought is was just a property of a region, but something like 'myregion.RegionAreaProperties.PrincipalMoments' does not work.

With the code I already have I use a selectionfilter to select multiple closed polylines. I can convert these to regions if nescesary. But what is the next step? I can't find any samples of it. Not even in the Autodesk Developer's Guide.

 

Can anyone point me in the right direction? maybe a small example?

ADN Support Specialist
Balaji_Ram
Posts: 609
Registered: ‎03-21-2011
Message 2 of 3 (268 Views)

Re: Principal Moments of a region (or closed polyline)

08-31-2013 12:17 PM in reply to: R.Gerritsen4967

Hi Gerritsen,

 

Here is a sample VB.Net code to determine the Moment of Inertial of a region about any axis and about its principal axes.

 

        <CommandMethod("Test")> _
        Public Sub TestMethod()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor

            Dim selectedObjectIds As New ObjectIdCollection()

            Dim peo As New PromptEntityOptions(vbLf & "Select a region :")
            peo.SetRejectMessage("Selection is not valid.")
            peo.AddAllowedClass(GetType(Autodesk.AutoCAD.DatabaseServices.Region), True)

            Dim per As PromptEntityResult = ed.GetEntity(peo)
            If per.Status <> PromptStatus.OK Then
                Return
            End If

            Dim ppo As New PromptPointOptions("Select axis origin point : ")
            Dim ppr As PromptPointResult = ed.GetPoint(ppo)
            If ppr.Status <> PromptStatus.OK Then
                Return
            End If
            Dim axisOrigin As Point3d = ppr.Value

            Dim ppo1 As New PromptPointOptions("Select X axis point : ")
            ppo1.BasePoint = axisOrigin
            Dim ppr1 As PromptPointResult = ed.GetPoint(ppo1)
            If ppr1.Status <> PromptStatus.OK Then
                Return
            End If

            Dim xAxis As Vector3d = (ppr1.Value - axisOrigin).GetNormal()
            Dim yAxis As Vector3d = xAxis.GetPerpendicularVector()

            Using tr As Transaction = db.TransactionManager.StartTransaction()
                Dim region As Region = TryCast(tr.GetObject(per.ObjectId, OpenMode.ForRead), Region)
                Dim rap As RegionAreaProperties = region.AreaProperties(axisOrigin, xAxis, yAxis)
                Dim I As Vector2d = rap.MomentsOfInertia
                Dim Ip As Vector2d = rap.PrincipalMoments
                ed.WriteMessage("{0}Moments of Inertia Ia = {1} Ib = {2}", Environment.NewLine, I.X, I.Y)
                ed.WriteMessage("{0}Moments of Inertia about principal axes Ixx {1} Iyy = {2}", Environment.NewLine, Ip.X, Ip.Y)
                tr.Commit()
            End Using
        End Sub

 



Balaji
Developer Technical Services
Autodesk Developer Network

Active Contributor
Posts: 46
Registered: ‎07-31-2009
Message 3 of 3 (243 Views)

Re: Principal Moments of a region (or closed polyline)

09-02-2013 05:29 AM in reply to: R.Gerritsen4967

@Balaji_Ram,

 

Thank you very much for this piece of code.

I've been playing around with your example, and I got it working within my own code.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community