How to iterate through all entities

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
odenlou
Posts: 11
Joined: 16 Jul 2014, 23:57

How to iterate through all entities

Post by odenlou » 17 Jul 2014, 01:39

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.

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

Re: How to iterate through all entities

Post by support » 17 Jul 2014, 12:08

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
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

odenlou
Posts: 11
Joined: 16 Jul 2014, 23:57

Re: How to iterate through all entities

Post by odenlou » 17 Jul 2014, 14:39

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.

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

Re: How to iterate through all entities

Post by support » 17 Jul 2014, 15:57

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
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply