highlight an object in cadPictBox

Discuss and ask questions about CAD .NET library.

Moderators: support, SDS, admin

Post Reply
CoffeeShop
Posts: 8
Joined: 10 Jul 2019, 05:36

Re: Find a location of specif text

Post by CoffeeShop » 10 Jul 2019, 05:47

Hi,
I want to highlight an object in cadPictBox by select blockname or how to know this object is selected.
How can I do it ?

CoffeeShop
Posts: 8
Joined: 10 Jul 2019, 05:36

highlight an object in cadPictBox

Post by CoffeeShop » 10 Jul 2019, 16:16

please help me some questions
1/ I want to highlight an object in cadPictBox when I select it in treeview. ex: block, text...
2/ when my clients open a cad file, it shows many objects in cadPictBox. how to config some objects allow selection and some not. ex: allow select block, text; not allow select line...

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

Re: highlight an object in cadPictBox

Post by support » 10 Jul 2019, 18:55

Hello,
CoffeeShop wrote:
10 Jul 2019, 16:16
1/ I want to highlight an object in cadPictBox when I select it in treeview. ex: block, text...
Could you please specify what you mean by highlighting? Is it changing of the entity line type and/or color or anything else?
CoffeeShop wrote:
10 Jul 2019, 16:16
2/ when my clients open a cad file, it shows many objects in cadPictBox. how to config some objects allow selection and some not. ex: allow select block, text; not allow select line...
You should use a CADImage.Selector.DoSelectEntity method that allows to show visual selection only for a certain CADEntity and should check the entity type prior to calling this method:

Code: Select all

CADEntity ent;
...

if (ent.EntType == EntityType.Text)
  CADImage.Selector.DoSelectEntity(ent);
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

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

Re: Find a location of specif text

Post by support » 10 Jul 2019, 19:22

CoffeeShop wrote:
10 Jul 2019, 05:47
Hi,
I want to highlight an object in cadPictBox by select blockname or how to know this object is selected.
How can I do it ?
Do you want to highlight CADInsert object(s) by a given block name?
To know whether a certain object is selected, use a CADEntity.Selected property.

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

CoffeeShop
Posts: 8
Joined: 10 Jul 2019, 05:36

Re: Find a location of specif text

Post by CoffeeShop » 10 Jul 2019, 20:41

support wrote:
10 Jul 2019, 19:22
Do you want to highlight CADInsert object(s) by a given block name?
yes.
Ex: object has 1 in 3 status: normal(black),red,blue
when open cad file, I want to change its color based on status by a given block name.

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

Re: highlight an object in cadPictBox

Post by support » 10 Jul 2019, 21:40

Hello,

The following method applies a new color to all the CADInsert objects of a given block that are located on the current layout:

Code: Select all

public static void ChangeBlockColor(CADImage drawing, string blockName, Color newColor)
{
    CADBlock block = drawing.Converter.BlockByName(blockName);
    if (block != null)
    {
        block.Entities.ForEach(entity => entity.Color = CADConst.clByBlock);
        drawing.Converter.Loads(block);

        List<CADEntity> inserts = drawing.CurrentLayout.Entities.FindAll(ent => ent.EntType == EntityType.Insert);
        List<CADEntity> blockInserts = inserts.FindAll(ent => (ent as CADInsert).Block.Name == blockName);

        foreach (CADEntity insert in blockInserts)
        {
            insert.Color = newColor;
            drawing.Converter.Loads(insert);
        }
    }
}
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

CoffeeShop
Posts: 8
Joined: 10 Jul 2019, 05:36

Re: highlight an object in cadPictBox

Post by CoffeeShop » 11 Jul 2019, 08:28

Thanks Mikhail.
It works ok.
I can change color of Text object, but it not work on MText.
I saw every object has a handle number. Is this unique on cad file?

Code: Select all

Shared Function ChangeColorByText(cadImage As CADImage, objType As EntityType, _text As String, newColor As Color) As Boolean
        If cadImage Is Nothing Then Return False
        For i As Integer = 0 To cadImage.CurrentLayout.Entities.Count - 1
            If cadImage.CurrentLayout.Entities(i).EntType = objType Then
                Dim entity As CADEntity = cadImage.CurrentLayout.Entities(i)
                Select Case entity.EntType
                    Case EntityType.Text
                        Dim cadText As CADText = CType(entity, CADText)
                        If cadText.Text.ToLower = _text.ToLower Then
                            cadText.Color = newColor
                            Return True
                        End If
                    Case EntityType.MText
                        Dim cadMText As CADMText = CType(entity, CADMText)
                        If cadMText.Text.ToLower = _text.ToLower Then
                            cadMText.Color = newColor
                            Return True
                        End If
                End Select
            End If
        Next
        Return False
    End Function

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

Re: highlight an object in cadPictBox

Post by support » 11 Jul 2019, 20:48

Hello,

You are welcome.

The code you posted actually cannot change a color of entity because of the missing line which should go right after assigning a new color (or changing any other property of CADEntity derivatives):

Code: Select all

cadImage.Converter.Loads(cadText)
or

Code: Select all

cadImage.Converter.Loads(cadMText)
I can change color of Text object, but it not work on MText.
Are you sure that the condition cadMText.Text.ToLower = _text.ToLower is satisfied?
I saw every object has a handle number. Is this unique on cad file?
Yes, CADEntity.Handle value is unique for each object within a CAD file.

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

Post Reply