Please can any body help,how to get MLine length in Autocad2010 using C# .net(2008).
using acadApp = Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace acad_rury_opisy
{
public class Class1
{
[CommandMethod("mll")]
public void mll()
{
acadApp.Document doc = acadApp.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
try
{
TypedValue[] tvf = new TypedValue[] {
new TypedValue((int)DxfCode.Start,"MLINE")};
SelectionFilter psr_filrt = new SelectionFilter(tvf);
PromptSelectionOptions psr_opt = new PromptSelectionOptions();
psr_opt.MessageForAdding = "Zaznacz obszar z multiliniami:";
PromptSelectionResult psr = ed.GetSelection(psr_opt, psr_filrt);
if (psr.Status != PromptStatus.OK)
return;
ObjectId[] ids = psr.Value.GetObjectIds();
double dlugosc = 0;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
DBObject obj;
foreach (ObjectId id in ids)
{
obj = tr.GetObject(id, OpenMode.ForRead);
if (obj == null)
continue;
Mline acMline = obj as Mline;
List<Point3d> pt_Mline = new List<Point3d>();
for (int i = 0; i < acMline.NumberOfVertices; i++)
{
pt_Mline.Add(acMline.VertexAt(i));
}
for (int i = 0; i < pt_Mline.Count - 1; i++)
{
dlugosc += pt_Mline[i].DistanceTo(pt_Mline[i + 1]);
}
MessageBox.Show(dlugosc.ToString());
}
}
}
catch (System.Exception e)
{
ed.WriteMessage("\nException {0}.", e);
}
}
}
}
or more briefly..
double mlineLength = 0;
for (int i = 0; i < mline.NumberOfVertices -1; i++)
{
minLineLength += mline.VertexAt(0).DistanceTo(mline.VertexAt(i + 1));
}