public override void Close(DBObject dbObject)
{
try
{
Document doc = Application.DocumentManager?.MdiActiveDocument;
var db = doc?.Database;
var ed = doc?.Editor;
var lMan
= new LayerManagement
();
{
Hatch hatch = dbObject as Hatch;
if (hatch != null && hatch.IsWriteEnabled && hatch.IsModified && !hatch.IsErased)
{
var rb = hatch.GetXDataForApplication("ASCD").AsArray();
hatch.SetLayerId(lMan.GetLayerObjectId(rb[2].Value.ToString()), true);
hatch.ColorIndex = 256;
hatch.LineWeight = LineWeight.ByLayer;
hatch.Associative = true;
if (!hatch.Associative || hatch.GetAssociatedObjectIds().Count == 0)
{
var allHandlesString = rb[3].Value.ToString();
var allHandles = allHandlesString.Split(';');
if (allHandles.Count() == 1)
{
long result = Convert.ToInt64(allHandles[0], 16);
ObjectId newObjectId
= db
.GetObjectId(false,
new Handle
(result
),
0); hatch
.AppendLoop(HatchLoopTypes
.Default,
new ObjectIdCollection
() { newObjectId
}); }
else
{
for (int i = allHandles.Count() - 1; i > -1; i--)
{
if (String.IsNullOrWhiteSpace(allHandles[i])) continue;
long result = Convert.ToInt64(allHandles[i], 16);
ObjectId newObjectId
= db
.GetObjectId(false,
new Handle
(result
),
0); hatch
.AppendLoop(HatchLoopTypes
.Default,
new ObjectIdCollection
() { newObjectId
}); }
}
}
hatch.Annotative = AnnotativeStates.True;
hatch.HatchStyle = HatchStyle.Outer;
hatch.EvaluateHatch(true);
}
}
else if (dbObject
is BlockReference
) {
BlockReference bReference = dbObject as BlockReference;
if (bReference != null && bReference.IsWriteEnabled && bReference.IsModified && bReference.IsErased == false)
{
var rb = bReference.GetXDataForApplication("ASCD").AsArray();
bReference.SetLayerId(lMan.GetLayerObjectId(rb[2].Value.ToString()), true);
bReference.ColorIndex = 256;
bReference.LineWeight = LineWeight.ByLayer;
}
}
else
{
Entity pline = dbObject as Entity;
if (pline != null && pline.IsWriteEnabled && pline.IsModified && !pline.IsErased)
{
var rb = pline.GetXDataForApplication("ASCD").AsArray();
var pl = pline.GetPersistentReactorIds();
pline.SetLayerId(lMan.GetLayerObjectId(rb[2].Value.ToString()), true);
pline.ColorIndex = 256;
pline.LineWeight = LineWeight.ByLayer;
if (rb.Length > 5 && rb[5].Value.ToString() != "IsAlone" && pline.GetPersistentReactorIds().Count == 0)
{
throw new Autodesk
.AutoCAD.Runtime.Exception(ErrorStatus
.CloseModifyAborted); }
}
}
base.Close(dbObject);
}
}
}