Find a location of specif text
Moderators: SDS, support, admin
-
- Posts: 13
- Joined: 19 Jun 2019, 07:30
Find a location of specif text
Hello
I would like to know how to find a location of specific text
I would like to know how to find a location of specific text
Re: Find a location of specif text
Hello,
Is the text located on a certain CAD drawing layout (Model, Layout1, etc.) or in a block?
Mikhail
Is the text located on a certain CAD drawing layout (Model, Layout1, etc.) or in a block?
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 13
- Joined: 19 Jun 2019, 07:30
Re: Find a location of specif text
both. I want to know location of specific text in layout and block.
Re: Find a location of specif text
Hello,
Please try the code below:
cadBlockName parameter in the GetTextLocation method is optional and should be specified when you need to search a specific text in the block definition (CADBlock) with a given name.
Mikhail
Please try the code below:
Code: Select all
private static CADText FindCADTextByValue(CADEntityCollection entities, string value)
{
Predicate<CADEntity> cadTextEntities = new Predicate<CADEntity>(ent => ent.EntType == EntityType.Text);
Predicate<CADEntity> cadTextByValue = new Predicate<CADEntity>(ent => (ent as CADText).Text == value);
return entities.FindAll(cadTextEntities).Find(cadTextByValue) as CADText;
}
public static DPoint GetTextLocation(CADImage cadImage, string text, string cadBlockName = "")
{
CADText cadText = null;
Predicate<CADEntity> cadInsertEntities = new Predicate<CADEntity>(ent => ent.EntType == EntityType.Insert);
Predicate<CADEntity> cadAttribByValue = new Predicate<CADEntity>(ent => (ent as CADAttrib).Value == text);
if (cadBlockName != "")
{
// Search a CADBlock by a given name
CADBlock cadBlock = cadImage.Converter.BlockByName(cadBlockName);
if (cadBlock != null)
{
// Search the text in the given CADBlock
cadText = FindCADTextByValue(cadBlock.Entities, text);
if (cadText != null)
return cadText.Point;
}
}
else
{
// Search the text on the current layout
cadText = FindCADTextByValue(cadImage.CurrentLayout.Entities, text);
if (cadText != null)
return cadText.Point;
else
{
// Search the text in CADInsert objects on the current layout
var cadInserts = cadImage.CurrentLayout.Entities.FindAll(cadInsertEntities);
foreach (CADEntity ent in cadInserts)
{
CADInsert cadInsert = ent as CADInsert;
// Search the text in the CADInsert's block
cadText = FindCADTextByValue(cadInsert.Block.Entities, text);
if (cadText != null)
return DPoint.Offset(cadText.Point, cadInsert.Point, true);
else
{
// Search the text in the CADInsert attributes
CADAttrib cadAttrib = cadInsert.Attribs.Find(cadAttribByValue) as CADAttrib;
if (cadAttrib != null)
return cadAttrib.Point;
}
}
}
}
return new DPoint(0, 0, 0);
}
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support