Author Topic: ACAD & C# ... Howto make new drawing from existing layer?  (Read 2069 times)

0 Members and 1 Guest are viewing this topic.

kaster

  • Guest
ACAD & C# ... Howto make new drawing from existing layer?
« on: February 05, 2015, 10:01:39 AM »
Howto make new ACAD drawing file from existing layer (with all entities)?

I'm trying with Database.WblockCloneObjects and this works, but subsequently publishing of drawings (many layers from one drawing -> many opened drawings) give me uninitialized drawings in publishing window.

Code: [Select]
sourceDb.WblockCloneObjects(sourceIds, destDbMsId, mapping, DuplicateRecordCloning.Replace, false);
destDb.SaveAs("c:\\temp\\dwgs\\CopyTest.dwg", DwgVersion.Current);

How to do that properly that so created drawings are "publishable"?

Thanks
« Last Edit: February 05, 2015, 10:20:14 AM by kaster »

n.yuan

  • Bull Frog
  • Posts: 348
Re: ACAD & C# ... Howto make new drawing from existing layer?
« Reply #1 on: February 06, 2015, 09:26:18 AM »
The following article may be closely or remotely relevant to your problem and worth of looking at:

http://adndevblog.typepad.com/autocad/2015/01/using-wblockcloneobjects-copied-modelspace-entities-disappear-in-the-current-drawing.html

kaster

  • Guest
Re: ACAD & C# ... Howto make new drawing from existing layer?
« Reply #2 on: February 22, 2015, 09:30:17 AM »
That was first good orientation. Following is my standing now:

Code: [Select]
// doc is opened multilayer drawing document
// LOOP OVER many layers
//foreach (string layerName in layerNames) {

string dwgFile = Path.GetDirectoryName(doc.Name) + "\\" + layerName + DocUtil.DWG_EXTENSION;
Document acNewDoc = DocUtil.OpenDocument(dwgFile, true, false, true); ;
using (Transaction transNew = acNewDoc.Database.TransactionManager.StartTransaction()) {
using (DocumentLock doclck = acNewDoc.LockDocument()) {
using (Database destDb = acNewDoc.Database) {
ObjectId destDbMsId = SymbolUtilityServices.GetBlockModelSpaceId(destDb);
ObjectIdCollection layerEntities = elements[layerName];
transNew.TransactionManager.QueueForGraphicsFlush();
// next prepare to deepclone the recorded ids to the destdb
IdMapping mapping = new IdMapping();
// now clone the objects into the destdb
doc.Database.WblockCloneObjects(layerEntities, destDbMsId, mapping, DuplicateRecordCloning.Replace, false);
// hier I must delete my (non standard named layout)
LayoutUtil.deleteLayout("Work");
// and after this i have regenerated "Layout1" with all graphic elements into
}
}
transNew.Commit();
// regen all
}
// } loop

But I have new issue:

Code: [Select]
doc.SendStringToExecute("publish\n", false, false, false);

Calls command "publish" but, all my pdf sheets (from multisheet pdf - one per layout) are empty.

If I run it manually each my pdf sheet (from multisheet pdf) is OK and contains drawing elements.

Any ideas?

Thanks
« Last Edit: February 22, 2015, 03:40:09 PM by kaster »