using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using System;
namespace AcadTest
{
public class DynBlockSpeedTest
{
[CommandMethod("DynBlockSpeedTest")]
public void RunTest()
{
Document adoc = Application.DocumentManager.MdiActiveDocument;
if (adoc == null) return;
Database db = adoc.Database;
Editor ed = adoc.Editor;
PromptSelectionOptions selOpts = new PromptSelectionOptions();
selOpts.MessageForAdding = "\nSelect dynamic blocks:";
selOpts.MessageForRemoval = "\nRemoved from selection:";
SelectionFilter selFl = new SelectionFilter(new[]
{
new TypedValue((int)DxfCode.Start, "INSERT")
});
PromptSelectionResult selRes = ed.GetSelection(selOpts, selFl);
if (selRes.Status != PromptStatus.OK) return;
ObjectId[] blkRefIds = selRes.Value.GetObjectIds();
DateTime start = DateTime.Now;
foreach (ObjectId blkRefId in blkRefIds)
{
using (BlockReference blkRef = blkRefId.Open(OpenMode.ForRead) as BlockReference)
{
if (blkRef.IsDynamicBlock)
{
var dynPropCol = blkRef.DynamicBlockReferencePropertyCollection;
}
}
}
DateTime end = DateTime.Now;
TimeSpan time = end - start;
ed.WriteMessage
("\nBlocks: {0}. Processing time: {1} ms",
blkRefIds.Length, time.TotalMilliseconds);
}
}
}