using System;
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: AcRx.CommandClass(typeof(Rivilis.RemoveAssoc))]
namespace Rivilis
{
public class RemoveAssoc
{
[AcRx.CommandMethod("RemAssoc", AcRx.CommandFlags.Modal | AcRx.CommandFlags.UsePickSet)]
public void RemAssoc()
{
AcAp.Document curDoc = AcAp.Application.DocumentManager.MdiActiveDocument;
AcEd.Editor ed = curDoc.Editor;
//////////////////////////////////////////////////////////////////////////
// Запрашиваем пользователя выбрать размеры и мультивыноски.
//////////////////////////////////////////////////////////////////////////
AcEd.SelectionFilter flt = new AcEd.SelectionFilter(
new AcDb.TypedValue[] { new AcDb.TypedValue(0, "DIMENSION,MULTILEADER") }
);
AcEd.PromptSelectionResult result = ed.GetSelection(flt);
if (result.Status == AcEd.PromptStatus.OK) {
AcDb.ObjectId[] ids = result.Value.GetObjectIds();
using (AcDb.Transaction tr = curDoc.TransactionManager.StartTransaction()) {
foreach (AcDb.ObjectId id in ids) {
try {
AcDb.DBObject obj = tr.GetObject(id, AcDb.OpenMode.ForRead);
if (obj != null) {
// Получаем Extension Dictionary
AcDb.ObjectId idExt = obj.ExtensionDictionary;
try {
AcDb.DBDictionary dict = tr.GetObject(idExt, AcDb.OpenMode.ForRead) as AcDb.DBDictionary;
if (dict != null) {
AcDb.ObjectId idDimAssoc = dict.GetAt("ACAD_DIMASSOC");
if (!idDimAssoc.IsNull) {
AcDb.DBObject dimAssoc = tr.GetObject(idDimAssoc, AcDb.OpenMode.ForWrite);
// Если это DimAssoc - удаляем его
// Тем самым мы разрываем связь размера и примитива
if (dimAssoc.GetRXClass().Name == "AcDbDimAssoc") {
dimAssoc.Erase();
}
}
}
}
catch { };
}
} catch { }
}
tr.Commit();
}
}
}
}
}