using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcEd = Autodesk.AutoCAD.EditorInput;
[assembly: CommandClass(typeof(TestLength.Commands))]
namespace TestLength
{
public class Commands
{
[CommandMethod("TLen")]
static public void TLen()
{
AcAp.Document doc = AcAp.Application.DocumentManager.MdiActiveDocument;
AcEd.Editor ed = doc.Editor;
AcDb.Database db = doc.Database;
double nTotalLength = 0;
using (AcDb.BlockTable bt = db.BlockTableId.Open(AcDb.OpenMode.ForRead) as AcDb.BlockTable) {
AcDb.ObjectId modelId = bt[AcDb.BlockTableRecord.ModelSpace];
using (AcDb.BlockTableRecord btr = modelId.Open(AcDb.OpenMode.ForRead) as AcDb.BlockTableRecord) {
foreach (AcDb.ObjectId id in btr) {
if (id.ObjectClass.IsDerivedFrom(AcRx.RXObject.GetClass(typeof(AcDb.Curve)))) {
using (AcDb.Curve curve = id.Open(AcDb.OpenMode.ForRead) as AcDb.Curve) {
nTotalLength += curve.GetDistanceAtParameter(curve.EndParam);
}
}
}
}
}
ed.WriteMessage("\nСуммарная длина: {0}", nTotalLength);
}
}
}