How to iterate through all entities
Moderators: SDS, support, admin
How to iterate through all entities
I need to go through every thing that exists on the drawing and examine the properties of each. I guess the things on the drawing are called "entities"? If someone could show me how to do this layer by layer that would be great.
Re: How to iterate through all entities
Hello,
The code below shows how to iterate through all entities and read the properties of each entity depending of its type
Mikhail
The code below shows how to iterate through all entities and read the properties of each entity depending of its type
Code: Select all
private void ReadEntities(CADImage cadImage)
{
foreach (CADEntity ent in cadImage.Converter.Entities)
{
switch (ent.EntType)
{
case EntityType.Line:
CADLine line = ent as CADLine;
double x1, y1, x2, y2;
x1 = line.Point.X;
y1 = line.Point.Y;
x2 = line.Point1.X;
y2 = line.Point1.Y;
break;
case EntityType.Arc:
CADArc arc = ent as CADArc;
double radius = arc.Radius;
break;
case EntityType.MText:
CADMText mText = ent as CADMText;
string txt = mText.Text;
break;
}
}
}
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
Re: How to iterate through all entities
Thank you, and useful, but my question was how to iterate all entities of a particular layer. So let me rephrase: Given a particular layer of drawing, how do you iterate through all entities of that layer.
Re: How to iterate through all entities
Hello,
It is possible to iterate through all entities in CADConverter and read only those that are on a specific layer:
Mikhail
It is possible to iterate through all entities in CADConverter and read only those that are on a specific layer:
Code: Select all
private void ReadEntitiesOnLayer(CADImage cadImage, string layerName)
{
foreach (CADEntity ent in cadImage.Converter.Entities)
{
if (ent.Layer.Name == layerName)
{
switch (ent.EntType)
{
case EntityType.Line:
CADLine line = ent as CADLine;
break;
case EntityType.Arc:
CADArc arc = ent as CADArc;
break;
case EntityType.Text:
CADText text = ent as CADText;
break;
}
}
}
}
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support