.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get MLine length in Autocad2010 using C# .net

2 REPLIES 2
Reply
Message 1 of 3
sudhakar.peddi
1219 Views, 2 Replies

How to get MLine length in Autocad2010 using C# .net

Please can any body help,how to get MLine length in Autocad2010 using C# .net(2008).

2 REPLIES 2
Message 2 of 3

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);
}

}
}
}

 

Message 3 of 3
CADbloke
in reply to: sudhakar.peddi

or more briefly..

double mlineLength = 0;

for (int i = 0; i < mline.NumberOfVertices -1; i++)
{
    minLineLength += mline.VertexAt(0).DistanceTo(mline.VertexAt(i + 1));
}
- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost