Hide part of polyline that across a block

kittichai.n
Explorer
Explorer

Hide part of polyline that across a block

kittichai.n
Explorer
Explorer

I try to hide some part of polyline when it across a block. I used overrule to hide it but not success because the WorldDraw method not allow me to use Document doc = Application.DocumentManager.MdiActiveDocument;.

In the WorldDraw method, I wrote some code to select blocks that across the polyline and find the intersection between the polyline and blocks. so I need to use Editor.SelectFence() to select block object.

Have any ways to avoid this? Thanks in advances.

my code:

public override bool WorldDraw(Drawable drawable, WorldDraw wd)
{
GrxCAD.DatabaseServices.Polyline pl = drawable as GrxCAD.DatabaseServices.Polyline;
DBObject plobj = drawable as GrxCAD.DatabaseServices.DBObject;

Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;

if (_overruling)
{
// Get xdata
List<HiddenSegment> hs = ReadXDataHiddenSegment(plobj);

// Get polyline's vertices
Point3d[] pts = new Point3d[pl.NumberOfVertices];
for (int i = 0; i < pl.NumberOfVertices; i++)
{
pts[i] = pl.GetPoint3dAt(i);
}

// Draw each segments
int n = 0;
//Tolerance tol = new Tolerance(0.0001, 0.0001);
while (n < pts.Length)
{
if ((n + 1) < pts.Length)
{
// create fence to select
Point3dCollection fe = new Point3dCollection
{
pts[n],
pts[n + 1]
};
// select object that the segment was across
PromptSelectionResult PromptSel = ed.SelectFence(fe);

// if objects were found on the current segment.
if ((PromptSel.Status == PromptStatus.OK) && (PromptSel.Value.Count > 0))
{
SelectionSet sset = PromptSel.Value;

// get all intersection points between the segment and objects
foreach (SelectedObject selobj in sset)
{
// get the intersection points (between pline and object)
Point3dCollection interPt = EntityInters.GetIntersectionPointInAndOut(selobj.ObjectId, plobj.ObjectId);
if (interPt.Count == 2)
{
fe.Add(interPt[0]);
fe.Add(interPt[1]);
}
}
// sorting all points
Point3dCollection SortedFe = SortPoints.SortPoint3d(fe);

// draw
int i = 0;
while (i < pts.Length)
{
if ((i + 1) < pts.Length)
wd.Geometry.WorldLine(SortedFe[i], SortedFe[i + 1]);
i += 2;
}

} else
{
wd.Geometry.WorldLine(pts[n], pts[n + 1]);
}

}
n += 1;
}

return true;
}
else
{
return base.WorldDraw(drawable, wd);
}
}

0 Likes
Reply
Accepted solutions (1)
408 Views
2 Replies
Replies (2)

norman.yuan
Mentor
Mentor
Accepted solution

So, the issue you have is to identify entities (BlockReferences in your case) that intersect with the overruled Polyline. You should not use Editor.SelectFence/Window...() method, even you can MdiActiveDocument is reachable: these methods only works while the selecting fence/window is within current view, which cannot be certain when you overrule the polyline.

 

You can simply loop through the current space in which the polyline resides to test if a BlockReference intersects with it.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes

kittichai.n
Explorer
Explorer

Thanks very much for your helpful answer.
I have another question. Overrule does not refresh (regen) after I moved the block from the overrule polyline.
Should I have an editor reactor for the move command? or can I have another overrule for blocks?

0 Likes