Jump to content

area of a selected object vb.net


Recommended Posts

Posted

this is probably a very easy question, but how do you get the area of an polygon? i have created a polyline and selected it via

 

Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.SelectLast()

 

ive spent ages on google looking to find how to do the simple task of reading the area but cant find how to do it! anyone got any pointers? vb.net is the script.

Posted (edited)

You iterate the SelctionSet's ObjectIds, opening the ObjectId as Polyline via Database Transaction, and cull the Area Property.

 

Cheers

Edited by BlackBox
Posted
You iterate the SelctionSet's ObjectIds, opening the ObjectId as Polyline via Database Transaction, and cull the Area Property.

 

Example (C#):

//<snip>
       private static void FOO()
       {
           Document doc = acDocs.MdiActiveDocument;
           Database db = doc.Database;
           Editor ed = doc.Editor;

           try
           {
               PromptSelectionResult psr = ed.SelectLast();

               if (psr.Status != PromptStatus.OK)
                   return;

               SelectionSet ss = psr.Value;
               ObjectId id = ss.GetObjectIds()[0];

               using (Transaction tr =
                       db.TransactionManager.StartOpenCloseTransaction())
               {
                   Polyline polyline = tr.GetObject(id, OpenMode.ForRead) as Polyline;

                   if (polyline != null)
                   {
                       ed.WriteMessage("\nPolyline Area: {0} \n", polyline.Area.ToString());
                   }
                   else
                   {
                       ed.WriteMessage("\n** Last object is not a Polyline. \n");
                   }                    

                   tr.Commit();
               }
           }
           catch (System.Exception ex)
           {
               ed.WriteMessage("\n; error: System.Exception: " + ex.Message);
           }
       }
//<snip>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...