Hi,
I' m creating associated hatches and everything is working perfectly.
My problem is when the user tries to change Associative to false through quick properties or any other way it removes associativity and this generates trouble with my code.
What I would like to do is to use ObjectOverrule to prevent the user from making this change to the entity.
When i create an object i put its associative entities Handles into its Xdata.
Then i try during the overruling to reappend the loops to the hatch but this works unreliably and causes exceptions.
When i try to apoend a loop it throws an eInvalidLayer exception which is caused by the polyline being already opened.
Did anyone else come across a similar problem or does anyone have an idea how to solve this issue?
This is what I m trying:
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);
}
}
}
Any help would be appreciated.