Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is WblockCloneObjects Valid for Civil3D Entities?

0 REPLIES 0
Reply
Message 1 of 1
daniel.jeffery
98 Views, 0 Replies

Is WblockCloneObjects Valid for Civil3D Entities?

I'm creating zero touch nodes for dynamo where I'm adding properties to various pipe networks, pressure pipe networks, and their child pipes, fittings, etc. and then exporting them out to another drawing. I'm gathering up a list of ObjectIds, which include the various networks, fittings, etc. and using WblockCloneObjects to export them. All seemed relatively well, however, when I tried to duplicate the folder structure for these networks, I would always get the root folder of the "toDatabase" as a null ObjectId. Better yet, saving this damaged database, then trying to create a new folder using UI would cause nothing to happen. I can get the root folder Id and recreate the folder structure before calling WblockCloneObjects with no issue. However, cloning the objects to the new database would override this change. 

 

I been fumbling trying different combinations for a bit now and feel like I've landed on two options: either WblockCloneObjects is the improper tool for the job, or this is unexpected behaviour. Any help would be greatly appreciated.

 

The following is my current process for the export (shrunken a little).

 

 

public static void WBlock(string filepath, ObjectId[] objectIds, bool append = false, string templatePath_Optional = "", bool remove_References_Optional = false)
        {
            Autodesk.AutoCAD.DynamoApp.Services.DocumentContext ctx = new Autodesk.AutoCAD.DynamoApp.Services.DocumentContext((Autodesk.AutoCAD.ApplicationServices.Document)null);
            Database fromDatabase = ctx.Document.Database;
            AAA.Document doc = ctx.Document;
            using (doc.LockDocument())
            {
                if (templatePath_Optional == "") templatePath_Optional = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                         @"Autodesk\C3D 2022\enu\Template\_Autodesk Civil 3D (Metric) NCS.dwt");
                using (Database toDatabase = new Database(false, true))
                {
                    if (!append) { toDatabase.ReadDwgFile(templatePath_Optional, FileOpenMode.OpenForReadAndWriteNoShare, false, null); }
                    else { toDatabase.ReadDwgFile(filepath, FileOpenMode.OpenForReadAndWriteNoShare, false, null); }

                    toDatabase.CloseInput(true);

                    ObjectIdCollection coll = new ObjectIdCollection(objectIds);
                    
                    using (Transaction trans = toDatabase.TransactionManager.StartTransaction())
                    {
                        BlockTable outdbBlockTable = toDatabase.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                        BlockTableRecord outdbBlkTbleRec = outdbBlockTable[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForRead) as BlockTableRecord;

						IdMapping idMap = new IdMapping();
                        fromDatabase.WblockCloneObjects(coll, outdbBlkTbleRec.ObjectId, idMap, DuplicateRecordCloning.Replace, false);
                                               
						ObjectId fromFolderId = ACD.FolderUtil.GetNonAlignmentRootFolder(RXClass.GetClass(typeof(ACD.Network)), fromDatabase);
						
						//will always come back null, unless called before WblockCloneObjects
						ObjectId toFolderId = ACD.FolderUtil.GetNonAlignmentRootFolder(RXClass.GetClass(typeof(ACD.Network)), toDatabase);
						
                        trans.Commit();
                    }

                    toDatabase.SaveAs(filepath, DwgVersion.Current);
                }
            }
        }

 

 

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report