Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've been testing moving selected items from one drawing to another.
I prompt the user to select what they would like to move.
I then move those objects to the "0" layer, as I dont want to bring layers from the source file to the destination.
I run this to move the objects over
static void CopyObjects(string destFileName, ObjectIdCollection idsToCopy)
{
using (Database destDb = new Database(false, true))
{
destDb.ReadDwgFile(TemplatePath, System.IO.FileShare.Read, true, "");
using (Transaction sourceTr = Active.Database.TransactionManager.StartOpenCloseTransaction())
using (Transaction destTr = destDb.TransactionManager.StartOpenCloseTransaction())
using(BlockTable destBt = destTr.GetObject(destDb.BlockTableId, OpenMode.ForRead, false, true) as BlockTable)
{
try
{
var mapping = new IdMapping();
Active.Database.WblockCloneObjects(idsToCopy, destBt[BlockTableRecord.ModelSpace], mapping, DuplicateRecordCloning.Ignore,
false);
_mapping = mapping;
destTr.Commit();
sourceTr.Commit();
}
catch
{
destTr.Abort();
sourceTr.Abort();
}
}
destDb.SaveAs(destFileName, DwgVersion.Current);
}
}
And then after I take the IdMapping and use Contains and Lookup to get the object id for the other side. But the ObjectId for the other side is not the same type?
I've tested by selecting just 1 polyline. And when I look through the mapping, I find one polyline on the source side of the pairs. But the destination side is of type Layer?
CopyObjects(DESTINATION_FILE, ids);
using (Database destDb = new Database(false, true))
{
destDb.ReadDwgFile(DESTINATION_FILE, FileShare.Read, true, "");
using (Transaction destTr = destDb.TransactionManager.StartOpenCloseTransaction())
{
try
{
foreach (IdPair pair in _mapping)
{
Active.WriteMessage($"\nSource: {pair.Key.ObjectClass.DxfName} | Destination: {pair.Value.ObjectClass.DxfName}");
}
destTr.Commit();
}
catch
{
destTr.Abort();
}
}
}
How do I get the ObjectId for the corresponding object in the destination file?
Solved! Go to Solution.