Message 1 of 5
DeepCloneObjects between two databases
Not applicable
06-11-2009
08:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The command is 5rep:
docA is the target database, it is where 5rep is entered
docB is the source database, and it's opened by 5rep
5rep is meant to copy objects from docB to docA
It requires a complex selection filter, that's why I need to open docB to get an Editor.
The following simplified code works when deep cloning objects within the same database, i.e docB
It fails when deep cloning objects from docB to docA (see commented portion)
Thanks for any help
Jf
{code}
[CommandMethod("5REP", CommandFlags.Session)]
public void SynchREP()
{
DocumentCollection docs = Application.DocumentManager;
Document docA = docs.MdiActiveDocument;
Database dbA = docA.Database;
Document docB = docs.Open("docB.dwg");
Database dbB = docB.Database;
DocumentLock dlockA = docA.LockDocument();
Transaction trA = dbA.TransactionManager.StartTransaction();
using (trA)
{
BlockTable btA = (BlockTable)trA.GetObject(
dbA.BlockTableId,
OpenMode.ForRead
);
BlockTableRecord msA = (BlockTableRecord)trA.GetObject(
btA[BlockTableRecord.ModelSpace],
OpenMode.ForWrite
);
DocumentLock dlockB = docB.LockDocument();
Transaction trB = dbB.TransactionManager.StartTransaction();
using (trB)
{
BlockTable btB = (BlockTable)trB.GetObject(
dbB.BlockTableId,
OpenMode.ForRead
);
BlockTableRecord msB = (BlockTableRecord)trB.GetObject(
btB[BlockTableRecord.ModelSpace],
OpenMode.ForRead
);
Editor edB = docB.Editor;
TypedValue[] tvsB = new TypedValue[]
{
new TypedValue( 67, "0" ),
new TypedValue( (int)DxfCode.Start, "INSERT" )
};
SelectionFilter sfB = new SelectionFilter(tvsB);
PromptSelectionResult psrB = edB.SelectAll(sfB);
SelectionSet ssetB = psrB.Value;
ObjectId[] ena = ssetB.GetObjectIds();
ObjectIdCollection oicB = new ObjectIdCollection(ena);
dbB.DeepCloneObjects(
oicB,
msB.Id, /* <-- targets the same database */
new IdMapping(), /* ...and it works */
false);
/*
dbB.DeepCloneObjects(
oicB,
msA.Id, <-- targets another database
new IdMapping(), ...and fails
false);
It raises an exception:
Autodesk.AutoCAD.Runtime.Exception: eWrongDatabase
in Autodesk.AutoCAD.DatabaseServices.Database.DeepCloneObjects */
trB.Commit();
}
trB.Dispose();
dlockB.Dispose();
}
trA.Dispose();
dlockA.Dispose();
}
{code}
docA is the target database, it is where 5rep is entered
docB is the source database, and it's opened by 5rep
5rep is meant to copy objects from docB to docA
It requires a complex selection filter, that's why I need to open docB to get an Editor.
The following simplified code works when deep cloning objects within the same database, i.e docB
It fails when deep cloning objects from docB to docA (see commented portion)
Thanks for any help
Jf
{code}
[CommandMethod("5REP", CommandFlags.Session)]
public void SynchREP()
{
DocumentCollection docs = Application.DocumentManager;
Document docA = docs.MdiActiveDocument;
Database dbA = docA.Database;
Document docB = docs.Open("docB.dwg");
Database dbB = docB.Database;
DocumentLock dlockA = docA.LockDocument();
Transaction trA = dbA.TransactionManager.StartTransaction();
using (trA)
{
BlockTable btA = (BlockTable)trA.GetObject(
dbA.BlockTableId,
OpenMode.ForRead
);
BlockTableRecord msA = (BlockTableRecord)trA.GetObject(
btA[BlockTableRecord.ModelSpace],
OpenMode.ForWrite
);
DocumentLock dlockB = docB.LockDocument();
Transaction trB = dbB.TransactionManager.StartTransaction();
using (trB)
{
BlockTable btB = (BlockTable)trB.GetObject(
dbB.BlockTableId,
OpenMode.ForRead
);
BlockTableRecord msB = (BlockTableRecord)trB.GetObject(
btB[BlockTableRecord.ModelSpace],
OpenMode.ForRead
);
Editor edB = docB.Editor;
TypedValue[] tvsB = new TypedValue[]
{
new TypedValue( 67, "0" ),
new TypedValue( (int)DxfCode.Start, "INSERT" )
};
SelectionFilter sfB = new SelectionFilter(tvsB);
PromptSelectionResult psrB = edB.SelectAll(sfB);
SelectionSet ssetB = psrB.Value;
ObjectId[] ena = ssetB.GetObjectIds();
ObjectIdCollection oicB = new ObjectIdCollection(ena);
dbB.DeepCloneObjects(
oicB,
msB.Id, /* <-- targets the same database */
new IdMapping(), /* ...and it works */
false);
/*
dbB.DeepCloneObjects(
oicB,
msA.Id, <-- targets another database
new IdMapping(), ...and fails
false);
It raises an exception:
Autodesk.AutoCAD.Runtime.Exception: eWrongDatabase
in Autodesk.AutoCAD.DatabaseServices.Database.DeepCloneObjects */
trB.Commit();
}
trB.Dispose();
dlockB.Dispose();
}
trA.Dispose();
dlockA.Dispose();
}
{code}