Select entities programmatically
Moderators: SDS, support, admin
-
- Posts: 22
- Joined: 06 Jul 2018, 10:52
Select entities programmatically
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
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
Re: Select entities programmatically
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:
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:
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:
Mikhail
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);
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);
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));
}
}
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
Re: Select entities programmatically
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:
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:
Mikhail
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);
Code: Select all
cadImage.Selector.DoSelectEntity(cadImage.SelectedEntities[0]);
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 22
- Joined: 06 Jul 2018, 10:52
Re: Select entities programmatically
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:

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:

There's no difference if selected with the mouse or using DoSelectEntity.
Thank you!
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:

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:

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
Thank you!
Re: Select entities programmatically
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
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
Chat support on Skype: cadsofttools.support