Hello Martin,
I tried a sample code that overrules polyline and then turned GRID on/off but the overrule did work correctly in both cases. Here is a very simple drawable overrule code that I am using to draw circles at each vertex of the overruled pline. I have tried it with AutoCAD 2011 and 2013 and it worked ok. Which version are you using ?
Is it system specific ? If so, have you tried resetting the AutoCAD settings by using the "Reset Settings to Default" ?
Here is the sample code. You can draw a pline and then run the Test command to select the pline.
public class MyDrawOverrule : DrawableOverrule
{
public override bool WorldDraw(Drawable drawable, WorldDraw wd)
{
Autodesk.AutoCAD.DatabaseServices.Polyline pline = drawable as Autodesk.AutoCAD.DatabaseServices.Polyline;
if (pline != null)
{
short clr = 1;
int segCount = pline.NumberOfVertices;
for (int cnt = 0; cnt < segCount; cnt++)
{
Point3d vertexPt = pline.GetPoint3dAt(cnt);
SegmentType type = pline.GetSegmentType(cnt);
switch (type)
{
case SegmentType.Arc:
CircularArc2d arc2d = pline.GetArcSegment2dAt(cnt);
clr = wd.SubEntityTraits.Color;
wd.SubEntityTraits.Color = 2;
wd.Geometry.Circle(vertexPt, arc2d.GetLength(arc2d.GetParameterOf(arc2d.StartPoint), arc2d.GetParameterOf(arc2d.EndPoint)) * 0.2, pline.Normal);
wd.SubEntityTraits.Color = clr;
break;
case SegmentType.Line:
LineSegment2d line2d = pline.GetLineSegment2dAt(cnt);
clr = wd.SubEntityTraits.Color;
wd.SubEntityTraits.Color = 2;
wd.Geometry.Circle(vertexPt, line2d.GetLength(line2d.GetParameterOf(line2d.StartPoint), line2d.GetParameterOf(line2d.EndPoint)) * 0.2, pline.Normal);
wd.SubEntityTraits.Color = clr;
break;
case SegmentType.Coincident:
break;
case SegmentType.Empty:
break;
case SegmentType.Point:
break;
}
}
}
return base.WorldDraw(drawable, wd);
}
}
public class Commands
{
static MyDrawOverrule pldo = null;
static List<ObjectId> plineIds = new List<ObjectId>();
[CommandMethod("Test")]
public void TestMethod()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptEntityResult per = ed.GetEntity("\nSelect a polyline");
if (per.Status != PromptStatus.OK)
return;
plineIds.Add(per.ObjectId);
if (pldo == null)
{
pldo = new MyDrawOverrule();
Overrule.AddOverrule(RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline)), pldo, true);
pldo.SetIdFilter(plineIds.ToArray());
Overrule.Overruling = true;
}
else
{
pldo.SetIdFilter(plineIds.ToArray());
}
using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
{
Entity reg = (Entity)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
reg.RecordGraphicsModified(true);
tr.TransactionManager.QueueForGraphicsFlush();
tr.Commit();
}
}
}
Balaji
Developer Technical Services
Autodesk Developer Network