Page 1 of 1
How to iterate through all entities
Posted: 17 Jul 2014, 01:39
by odenlou
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
Posted: 17 Jul 2014, 12:08
by support
Hello,
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;
}
}
}
Mikhail
Re: How to iterate through all entities
Posted: 17 Jul 2014, 14:39
by odenlou
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
Posted: 17 Jul 2014, 15:57
by support
Hello,
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;
}
}
}
}
Mikhail