Page 1 of 1
Re: Find a location of specif text
Posted: 10 Jul 2019, 05:47
by CoffeeShop
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 ?
highlight an object in cadPictBox
Posted: 10 Jul 2019, 16:16
by CoffeeShop
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...
Re: highlight an object in cadPictBox
Posted: 10 Jul 2019, 18:55
by support
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
Re: Find a location of specif text
Posted: 10 Jul 2019, 19:22
by support
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
Re: Find a location of specif text
Posted: 10 Jul 2019, 20:41
by CoffeeShop
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.
Re: highlight an object in cadPictBox
Posted: 10 Jul 2019, 21:40
by support
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
Re: highlight an object in cadPictBox
Posted: 11 Jul 2019, 08:28
by CoffeeShop
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
Re: highlight an object in cadPictBox
Posted: 11 Jul 2019, 20:48
by support
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):
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