dan_g8 Posted September 7, 2015 Posted September 7, 2015 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. Quote
BlackBox Posted September 7, 2015 Posted September 7, 2015 (edited) You iterate the SelctionSet's ObjectIds, opening the ObjectId as Polyline via Database Transaction, and cull the Area Property. Cheers Edited September 8, 2015 by BlackBox Quote
BlackBox Posted September 8, 2015 Posted September 8, 2015 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> Quote
Recommended Posts
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.