Message 1 of 2
judge the entity where the original dwg file
Not applicable
09-10-2017
07:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i copy all entity from two dwgs to a new dwg fille , the I get all the entity in new file , how to know the entity 's original file ?
public void Merge()
{
Point3d pt1;
Point3d pt2;
ObjectIdCollection SourceObjectIds1 = new ObjectIdCollection();
ObjectIdCollection SourceObjectIds2 = new ObjectIdCollection();
cp(@"E:\2017\P1.dwg", out pt1, SourceObjectIds1);
cp(@"E:\2017\\P2.dwg", out pt2, SourceObjectIds2);
ObjectIdCollection ToObjectid = new ObjectIdCollection();
Database sourceDb = Application.DocumentManager.MdiActiveDocument.Database;
using (Transaction extTrans = sourceDb.TransactionManager.StartTransaction())
{
BlockTable extBlockTable = (BlockTable)extTrans.GetObject(sourceDb.BlockTableId, OpenMode.ForRead);
BlockTableRecord extModelSpace = (BlockTableRecord)extTrans.GetObject(extBlockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead);
foreach (ObjectId id in extModelSpace)
{
ToObjectid.Add(id);
// i want to know which original dwg the objectid from??????
}
extTrans.Commit();
}
}
public void cp(string drawingPath, out Point3d pt, ObjectIdCollection SourceObjectIds)
{
pt = new Point3d();
Database sourceDb = new Database(false, true);
sourceDb.ReadDwgFile(drawingPath, System.IO.FileShare.Read, false, null);
Autodesk.AutoCAD.DatabaseServices.TransactionManager SourceTm = sourceDb.TransactionManager;
using (Transaction extTrans = sourceDb.TransactionManager.StartTransaction())
{
BlockTable extBlockTable = (BlockTable)extTrans.GetObject(sourceDb.BlockTableId, OpenMode.ForRead);
BlockTableRecord extModelSpace = (BlockTableRecord)extTrans.GetObject(extBlockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead);
foreach (ObjectId id in extModelSpace)
{
SourceObjectIds.Add(id);
var ent = extTrans.GetObject(id, OpenMode.ForWrite, true);
if (ent is DBText)
{
DBText text = ent as DBText;
if (text.TextString == "aa")
{
pt = text.Position;
}
}
}
extTrans.Commit();
}
Database destDb = Application.DocumentManager.MdiActiveDocument.Database;
var mapping = new IdMapping();
var targetid = SymbolUtilityServices.GetBlockModelSpaceId(destDb);
var sourcedb = SourceObjectIds[0].Database;
sourcedb.WblockCloneObjects(SourceObjectIds, targetid, mapping, DuplicateRecordCloning.Ignore, false);
}