DeepCloneObjects

DeepCloneObjects

fsl88
Contributor Contributor
572 Views
1 Reply
Message 1 of 2

DeepCloneObjects

fsl88
Contributor
Contributor

Good day,

 

What does the line  "db.DeepCloneObjects(ids, db.CurrentSpaceId, idMap, false);" do?

 

The code follows.

 

using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;

namespace CC
{
    public class CCClass
    {
        [CommandMethod("CC")]
        public static void CC()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor edt = doc.Editor;

            // Prompt the user to select objects
            PromptSelectionResult psr = edt.GetSelection();
            if (psr.Status != PromptStatus.OK) return;

            // Enter base point
            var ppo = new PromptPointOptions("\nSpecify base point: ");
            var ppr = edt.GetPoint(ppo);
            if (psr.Status != PromptStatus.OK) return;
            var basePt = ppr.Value;

            // prompt the user to specify the desination point
            ppo.Message = "\nSpecify destination point: ";
            ppo.BasePoint = basePt;
            ppo.UseBasePoint = true;
            ppr = edt.GetPoint(ppo);

            if (ppr.Status != PromptStatus.OK) return;
            
            
            
            var destPt = ppr.Value;
            // compute the displacement matrix
            Vector3d vect = basePt.GetVectorTo(destPt).TransformBy(edt.CurrentUserCoordinateSystem);
            var disp = Matrix3d.Displacement(vect);

            edt.WriteMessage("\nppr.Status " + ppr.Status);
            edt.WriteMessage("\ndestPt " + destPt);
            edt.WriteMessage("\nvect " + vect);
            edt.WriteMessage("\ndisp " + disp);
            

            using (Transaction trans = doc.TransactionManager.StartTransaction())
            {

                // copy the selected entities
                var ids = new ObjectIdCollection(psr.Value.GetObjectIds());
                edt.WriteMessage("\nids " + ids);
                var idMap = new IdMapping();
                edt.WriteMessage("\nidMap " + idMap);
                
                db.DeepCloneObjects(ids, db.CurrentSpaceId, idMap, false);

                // displace the copied entities
                foreach (IdPair pair in idMap)
                {
                    edt.WriteMessage("\ndb.CurrentSpaceId " + db.CurrentSpaceId);
                    edt.WriteMessage("\nids " + ids);
                    edt.WriteMessage("\nidMap " + idMap);
                    edt.WriteMessage("\npair " + pair);
                    
                    if (pair.IsPrimary && pair.IsCloned)
                    {
                        Entity ent = (Entity)trans.GetObject(pair.Value, OpenMode.ForWrite);
                        ent.TransformBy(disp);
                    }
                }
                trans.Commit();
            }
            

          
        }


    }
}

 

0 Likes
573 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant

Hi,

Quick reply: it copies the objects.

More complete reply in the documentation.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes