Community
Hi,
i want to copy alle the Block and the NamedObjectsDictionaryId from a DWT to the current DWG.
I have this code, the copy from Block are OK but not the Copy from the NamedObjectsDictionaryId. What is wrong on my code ?
Wenn you can help me. Thanks
public static void DragNDropEntitiesFromDWT(string sPath, Point3d basePoint)
{
AcAp.Document doc = AcAp.Application.DocumentManager.MdiActiveDocument;
AcDataService.Database acCurDb = doc.Database;
Editor ed = doc.Editor;
try
{
//string strTemplatePath = @"C:\ProgramData\AKG Software\INFRASIGN8\DACH\CAD_X\RSA\DE\RegelplanBI2.dwt";
using (doc.LockDocument())
{
AcDataService.ObjectIdCollection objectIds = new AcDataService.ObjectIdCollection();
AcDataService.ObjectIdCollection dictionaryIds = new AcDataService.ObjectIdCollection();
var mIdMap = new AcDataService.IdMapping();
var mDictionaryIdMap = new AcDataService.IdMapping();
using (var trans = acCurDb.TransactionManager.StartTransaction())
{
//holt den aktuell BlockTable
var btCur = trans.GetObject(acCurDb.BlockTableId, AcDataService.OpenMode.ForRead) as AcDataService.BlockTable;
using (AcDataService.Database sourceDb = new AcDataService.Database(false, true))
{
//Load DWT File
sourceDb.ReadDwgFile(sPath, AcDataService.FileOpenMode.OpenForReadAndAllShare, false, null);
sourceDb.CloseInput(true);
using (var transsourcedb = sourceDb.TransactionManager.StartTransaction())
{
AcDataService.BlockTableRecord btr = (AcDataService.BlockTableRecord)transsourcedb.GetObject(AcDataService.SymbolUtilityServices.GetBlockModelSpaceId(sourceDb), AcDataService.OpenMode.ForRead);
foreach (AcDataService.ObjectId id in btr)
{
objectIds.Add(id);
}
var NOD = (AcDataService.DBDictionary)transsourcedb.GetObject(sourceDb.NamedObjectsDictionaryId, AcDataService.OpenMode.ForRead);
if (NOD.Contains(SettingsManager.dictionaryKey))
{
dictionaryIds.Add(NOD.GetAt(SettingsManager.dictionaryKey));
}
transsourcedb.Commit();
//Clone die Objekte in der BlockTableRecordId from aktuell DWG
sourceDb.WblockCloneObjects(objectIds, btCur[AcDataService.BlockTableRecord.ModelSpace], mIdMap, AcDataService.DuplicateRecordCloning.Ignore, false);
}
//Clone die Dictionary
sourceDb.WblockCloneObjects(dictionaryIds, acCurDb.NamedObjectsDictionaryId, mDictionaryIdMap, AcDataService.DuplicateRecordCloning.Replace, false);
}
MoveRotationScaleJig jigger = new MoveRotationScaleJig(basePoint);
foreach (AcDataService.ObjectId objectId in objectIds)
{
AcDataService.Entity ent = (AcDataService.Entity)trans.GetObject(mIdMap[objectId].Value, AcDataService.OpenMode.ForWrite);
jigger.AddEntity(ent);
}
//Start den Positionierung mit Jig
if (jigger.Jig(1))
{
//Passt alle Entities an
jigger.TransformEntities();
trans.Commit();
}
else
{
trans.Abort();
}
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.ToString());
}
}
Can't find what you're looking for? Ask the community or share your knowledge.