Prod.: Engine, ver.: 6, ID: 60000205, HowTo : Select entity of an XRef

HowTo : Select entity of an XRef

Article60000205
TypeHowTo
ProductEngine
Version6
Date Added7/20/2007
Submitted byDominique PREMILLIEU
Keywords

Subject

Select entity of an XRef

Summary

What would be the best way to find an entity displayed under the cursor ? I would like this selection to detect entity from the current document or any xref attachment.

Solution

The XRef attached documents are treated as vdBlocks with vdInserts in the drawing. So when you attach an External Referense file a block and an insert of this block is added to the document. In vdfCAD if you open a drawing and click on the attached XRef you will see a vdInsert object.
 
You can get the inner entity (of the vdInsert) that you clicked on using a code like :

object ret = vdFramedControl1.BaseControl.ActiveDocument.ActionUtility.getUserPoint();
if (ret is VectorDraw.Geometry.gPoint)
{
    VectorDraw.Geometry.gPoint p1 = vdFramedControl1.BaseControl.ActiveDocument.World2PixelMatrix.Transform(ret as VectorDraw.Geometry.gPoint);
    Point location = new Point((int)p1.x, (int)p1.y);

    // This code will return the xREF as vdInsert
    VectorDraw.Professional.vdPrimaries.vdFigure fig = vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.GetEntityFromPoint(location, vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.Render.GlobalProperties.PickSize, false);
    if (fig != null)
    {
        fig.HighLight = true;
        fig.Invalidate();
        MessageBox.Show("Figure is a : " + fig.ToString());
        fig.HighLight = false;
        fig.Invalidate();
    }

// This code will return the inner entity, this is what you want
    VectorDraw.Professional.vdPrimaries.vdFigure outerfig; // this should be the xREF vdInsert
    VectorDraw.Geometry.Matrix matr = new VectorDraw.Geometry.Matrix();
    VectorDraw.Professional.vdPrimaries.vdFigure innerfig = vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.GetInnerEntityFromPoint(out matr, out outerfig, location, vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.Render.GlobalProperties.PickSize, false);
    if (innerfig != null && outerfig != null)
    {
        innerfig.HighLight = true; //This is the inner entity you want.
        innerfig.Invalidate();
        MessageBox.Show("Figure is a : " + innerfig.ToString() + " contained in " + outerfig.ToString());
        innerfig.HighLight = false;
        innerfig.Invalidate();
    }
}