215 Posts
0 Kudos
Registered: ‎01-16-2006
Post 1 of 1

WblockCloneObjects Layout of Inventor DWG

150 Views, 0 Replies
01-19-2012 05:58 AM



I'm trying to WblockCloneObjects an Inventor2012 dwg in Autocad 2012.

In this file there is just 1 layout called "Blad"

I get the objectIDs (23 in my case) but I can't see them in Autocad displayed.

I only see the new Layout!

My routine works well for WblockCloneObjects Autocad2012 dwg!


What am I missing? or isn't this possible at all because its an Inventor dwg?





 public static Database WblockCloneFromExternalDWGfile(string filename, bool isinventorfile)


         Database targetDatabase = Active.WorkingDatabase;

         Database sourchDatabase = new Database(false, true);

         sourchDatabase.ReadDwgFile(filename, FileOpenMode.OpenForReadAndAllShare, true, "");

         targetDatabase.Dimscale = sourchDatabase.Dimscale;


        using (Transaction sourchTransaction = sourchDatabase.TransactionManager.StartTransaction())


             BlockTable sourchBlockTable = (BlockTable)sourchDatabase.BlockTableId.GetObject(OpenMode.ForRead);

             BlockTableRecord sourchSpace;

             if (isinventorfile) { sourchSpace = (BlockTableRecord)sourchBlockTable

                                                                   [BlockTableRecord.PaperSpace].GetObject(OpenMode.ForRead); }

            else { sourchSpace = (BlockTableRecord)sourchBlockTable[BlockTableRecord.ModelSpace].GetObject

                                               (OpenMode.ForRead); }

            ObjectIdCollection objectIDCollection = new ObjectIdCollection();

            foreach (ObjectId objectID in sourchSpace) { objectIDCollection.Add(objectID); }


            using (Transaction targetTransaction = targetDatabase.TransactionManager.StartTransaction())


                BlockTable targetBlockTable = (BlockTable)targetDatabase.BlockTableId.GetObject(OpenMode.ForRead);                 BlockTableRecord targetSpace;

                 if (isinventorfile)


                     ObjectId newLayoutId = LayoutManager.Current.CreateLayout("Blad");

                     Layout newLayout = (Layout)newLayoutId.GetObject(OpenMode.ForWrite);

                     LayoutManager.Current.CurrentLayout = newLayout.LayoutName;

                     //targetSpace = (BlockTableRecord)targetBlockTable[BlockTableRecord.PaperSpace].GetObject


                     targetDatabase.WblockCloneObjects(objectIDCollection, newLayout.BlockTableRecordId, new IdMapping(),

                                                                                 DuplicateRecordCloning.Replace, false);


                 else  //Autocad DWG


                     targetSpace = (BlockTableRecord)targetBlockTable[BlockTableRecord.ModelSpace].GetObject


                     targetDatabase.WblockCloneObjects(objectIDCollection, targetSpace.ObjectId, new IdMapping(),

                                                                                 DuplicateRecordCloning.Replace, false);





         return targetDatabase;


Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!