[CommandMethod ("getlen")]
public static void LineLengths()
{
Document Adoc = Application.DocumentManager.MdiActiveDocument;
Database db = Adoc.Database;
Editor ed = Adoc.Editor;
double len;
ed.WriteMessage("\nSelect Lines: ");
TypedValue
[] Tvals
= new TypedValue
[] { new TypedValue
(0,
"LINE") }; SelectionFilter ssf
= new SelectionFilter
(Tvals
); PromptSelectionOptions opt
= new PromptSelectionOptions
(); PromptSelectionResult psr = ed.GetSelection(opt, ssf);
if (psr.Status == PromptStatus.OK && psr.Value.Count > 0)
using (Transaction trans = db.TransactionManager.StartTransaction())
{
foreach (SelectedObject item in psr.Value)
{
Line line = (Line)trans.GetObject(item.ObjectId, OpenMode.ForWrite);
len += line.Length; /// <-- this len variable shows as an error
}
ed.WriteMessage("Lengths of line(s) :" + len.ToString());
trans.Commit();
}
}