Select entities programmatically

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
StefanChrist
Posts: 22
Joined: 06 Jul 2018, 10:52

Select entities programmatically

Post by StefanChrist » 09 Jul 2018, 16:25

Hello Support,

I am trying to select an entity programmatically using the SelectedEntities property. While the count returns 1 there is no visible selection on the screen. What am I missing?

Thanks,
Stefan

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: Select entities programmatically

Post by support » 09 Jul 2018, 22:26

Hello Stefan,

In general, entity selection may be visual and non-visual. CADImage.SelectedEntities collection is intended for managing the list of selected entities, regardless of the selection type. The SelectedEntities collection itself doesn't implement visual selection, it is supported through a CADImport.Professional.Marker class. The Marker object represents a yellow square drawn at some point on the selected CADEntity.

Markers can be created with the following code:

Code: Select all

using CADImport.Professional;

...

Marker marker1 = new Marker(ent, 0, 0, ent.Box.TopLeft);
Marker marker2 = new Marker(ent, 0, 1, ent.Box.BottomRight);
where ent is one of CADEntity objects in the SelectedEntities collection.

Normally you need to create multiple markers for a single entity, so it would be better to combine them in a CADCollection:

Code: Select all

private CADCollection<Marker> markers;

...

markers = new CADCollection<Marker>();

...

markers.Add(marker1);
markers.Add(marker2);
Once you have the markers collection, you can easily draw them on the Graphics object associated with a certain drawing surface (for example, the Graphics object associated with a CADPictureBox control) using a Marker.Paint() method. The simplest way to get the Graphics object associated with a form or control is to use the Paint event handler and PaintEventArgs.Graphics property:

Code: Select all

        cadPictureBox.Paint += CADPictureBox_Paint;

        ...

        private void CADPictureBox_Paint(object sender, PaintEventArgs e)
        {
            if ((cadImage != null) && (markers != null))
            {
                markers.ForEach(marker => marker.Paint(e.Graphics, cadImage));
            }
           
        }
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: Select entities programmatically

Post by support » 23 Jul 2018, 20:20

Stefan,

It is also possible to show visual selection for all the entities in a CADImage.SelectedEntities collection with a one line of code, using a CADImage.Selector.DoSelectEntities method:

Code: Select all

cadImage.Selector.DoSelectEntities(cadImage.SelectedEntities);
If you want to show visual selection only for a certain entity in the CADImage.SelectedEntities collection, you may use a CADImage.Selector.DoSelectEntity method as follows:

Code: Select all

cadImage.Selector.DoSelectEntity(cadImage.SelectedEntities[0]);
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

StefanChrist
Posts: 22
Joined: 06 Jul 2018, 10:52

Re: Select entities programmatically

Post by StefanChrist » 24 Jul 2018, 11:39

Hello Mikhail,

I made a small sample with a block and three inserts using the same block. Then I wanted to visually select one of the inserts. The result is this:

Image

As you can see there are markers around one of the inserts which is fine, but why are the entities of the block dashed in the other inserts too? This also happens when the user selects an insert with the mouse.

Another issue with the selection occurs when the last insert is selected. When the last insert gets selected it shows the rectangle around the insert with a solid line instead of a dashed one:

Image

Code: Select all

Private Sub CadPictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles CadPictureBox1.MouseDown
    Me.cadImage.ClearSelection()
    Me.cadImage.ClearMarkers()
    Me.cadImage.SelectExt(e.X, e.Y, True, True)
    CadPictureBox1.Invalidate()
End Sub
There's no difference if selected with the mouse or using DoSelectEntity.

Thank you!

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: Select entities programmatically

Post by support » 24 Jul 2018, 20:40

Hello Stefan,

We are aware of the given problem. It is a bug in the source code of the library which is currently resolved in a development branch, but the bug fix has not yet been tested by our QA team. You will have to wait until a new CAD .NET version with the bug fix is released, so it would be possible to add the fix to the version you are currently using.

Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply