Hi,
The RXObject.Clone() method does not deep clone the entity (i.e. does not copy the entity xdata and extension dictionary), you should use DeepCloneObjects instead.
Assuming convertedLayerNames is a Dictionary<string, string> where each pair key is the old layer name and each pair value is the corresponding new layer name, assuming these new layers already exist in the drawing LayerTable, you can do something laike this:
public void CopyModelSpaceEntitiesToNewLayer()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
using (var tr = db.TransactionManager.StartTransaction())
{
// Deep clone all the entities in model space
var modelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(db);
var modelSpace = (BlockTableRecord)tr.GetObject(modelSpaceId, OpenMode.ForWrite);
var ids = new ObjectIdCollection();
foreach (ObjectId id in modelSpace)
{
ids.Add(id);
}
var mapping = new IdMapping();
db.DeepCloneObjects(ids, modelSpaceId, mapping, false);
// change the layer of cloned entities
foreach (IdPair pair in mapping)
{
if (pair.IsCloned && pair.IsPrimary)
{
var entity = (Entity)tr.GetObject(pair.Value, OpenMode.ForWrite);
entity.Layer = convertedLayerNames[entity.Layer];
}
}
tr.Commit();
}
}