private void ubaci_Click(object sender, EventArgs e)
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database wdb = doc.Database;
Editor ed = doc.Editor;
//Database wdb = HostApplicationServices.WorkingDatabase;
try
{
using (Transaction tr = wdb.TransactionManager.StartTransaction())
{
LayerTable lt = (LayerTable)wdb.LayerTableId.GetObject(OpenMode.ForWrite);
TextStyleTable tt = (TextStyleTable)wdb.TextStyleTableId.GetObject(OpenMode.ForWrite);
DimStyleTable dt = (DimStyleTable)wdb.DimStyleTableId.GetObject(OpenMode.ForWrite);
BlockTable bt = (BlockTable)wdb.BlockTableId.GetObject(OpenMode.ForWrite);
Database ndb
= new Database
(false,
true); ndb.ReadDwgFile(putanja, FileOpenMode.OpenForReadAndAllShare, true, "");
using (Transaction tr2 = ndb.TransactionManager.StartTransaction())
{
LayerTable nlt = (LayerTable)ndb.LayerTableId.GetObject(OpenMode.ForWrite);
IdMapping mylMap
= new IdMapping
(); ObjectIdCollection lidcol
= new ObjectIdCollection
(); foreach (string laye in ULayer.SelectedItems)
{
LayerTableRecord nltr = (LayerTableRecord)nlt[laye].GetObject(OpenMode.ForRead);
lidcol.Add(nltr.ObjectId);
}
//ndb.WblockCloneObjects(lidcol, lt.ObjectId, mylMap, DuplicateRecordCloning.Replace, false);
ndb.WblockCloneObjects(lidcol, wdb.LayerTableId, mylMap, DuplicateRecordCloning.Replace, false);
TextStyleTable ntt = (TextStyleTable)ndb.TextStyleTableId.GetObject(OpenMode.ForWrite);
IdMapping mytMap
= new IdMapping
(); ObjectIdCollection tidcol
= new ObjectIdCollection
(); foreach (string tsty in Utst.SelectedItems)
{
TextStyleTableRecord nltr = (TextStyleTableRecord)ntt[tsty].GetObject(OpenMode.ForRead);
tidcol.Add(nltr.ObjectId);
}
ndb.WblockCloneObjects(tidcol,wdb.TextStyleTableId, mytMap, DuplicateRecordCloning.Replace, false);
DimStyleTable ndt = (DimStyleTable)ndb.DimStyleTableId.GetObject(OpenMode.ForWrite);
IdMapping mydMap
= new IdMapping
(); ObjectIdCollection didcol
= new ObjectIdCollection
(); foreach (string dimsty in Dst.SelectedItems)
{
DimStyleTableRecord ndtr = (DimStyleTableRecord)ndt[dimsty].GetObject(OpenMode.ForRead);
didcol.Add(ndtr.ObjectId);
}
ndb.WblockCloneObjects(didcol, wdb.DimStyleTableId, mydMap, DuplicateRecordCloning.Replace, false);
BlockTable nbt = (BlockTable)ndb.BlockTableId.GetObject(OpenMode.ForWrite);
IdMapping mybMap
= new IdMapping
(); ObjectIdCollection bidcol
= new ObjectIdCollection
(); foreach (string blok in Ublok.SelectedItems)
{
BlockTableRecord nbtr = (BlockTableRecord)nbt[blok].GetObject(OpenMode.ForRead);
bidcol.Add(nbtr.ObjectId);
}
ndb.WblockCloneObjects(bidcol, wdb.BlockTableId, mybMap, DuplicateRecordCloning.Replace, false);
//tr2.Commit();
//wdb.SaveAs("c:\\temp\\dwgs\\CopyTest.dwg", DwgVersion.Current);
}
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage("\nError during clone: " + ex.Message);
}
}