70002224 Explode all objects to simple objects and save it as a new drawing

Article 70002224
Type HowTo
Product Engine
Version 9
Date Added 5/31/2022 12:00:00 AM
Fixed 10.1001.0.5 (5/31/2022 12:00:00 AM)
Submitted by BEN VAN DEN HEEVER

Summary

I would like to explode all objects of a drawing that is already created/loaded into simple objects of vdLine, vdArc, vdCircle, vdText, vdEllipse and save this exploded drawing to a new file. How can I do this?

Solution

You can use a code like:

        private void button1_Click(object sender, EventArgs e)
        {
            vdDocument document = vdFramedControl1.BaseControl.ActiveDocument;

            //create a temporary block to hold the exploded entities
            //Entities are exploded until to the vdLine,vdArc,vdCircle,vdEllipse, vdText types
            VectorDraw.Professional.vdPrimaries.vdBlock block = new VectorDraw.Professional.vdPrimaries.vdBlock(document);
            document.MeterProgress.start("Explode to lines", document.Model.Entities.Count);
            foreach (VectorDraw.Professional.vdPrimaries.vdFigure item in document.Model.Entities)
            {
                document.MeterProgress.Progress();
                block.Entities.AddItem(item.Clone(null));
            }
            document.MeterProgress.stop();
            int c = 0;
            do
            {
                c = 0;
                int nitems = block.Entities.Count;
                document.MeterProgress.start("Explode to lines", nitems);
                for (int i = 0; i < nitems; i++)
                {
                    document.MeterProgress.Progress();
                    VectorDraw.Professional.vdPrimaries.vdFigure fig = block.Entities[i];
                    if (fig.Deleted) continue;
                    ////explode all entities except the following  types.
                    if (fig is VectorDraw.Professional.vdFigures.vdText) continue;//comment this line if you want also texts to be exploded to lines
                    VectorDraw.Professional.vdCollections.vdEntities ents = fig.Explode();
                    if (ents == null || ents.Count == 0) continue;
                    fig.Deleted = true;

                    foreach (VectorDraw.Professional.vdPrimaries.vdFigure fig2 in ents)
                    {
                        block.Entities.AddItem(fig2);
                        c++;
                    }

                }
                document.MeterProgress.stop();
            } while (c > 0);
            //create a document fro the block entities and save it to a new file
            vdDocument doc2 = block.ToDocument();
            doc2.SaveAs(document.FileName + ".exploded.vdcl");
            block.Dispose();
            block = null;
        }
  

Send comments on this topic.