Message 1 of 2
DeepCloneObjects
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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();
}
}
}
}