• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Mentor
    Posts: 215
    Registered: ‎01-16-2006

    WblockCloneObjects Layout of Inventor DWG

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

    Hi,

     

    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?

     

    Geert

     

    Code:

     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

                                                   (OpenMode.ForWrite);

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

                                                                                     DuplicateRecordCloning.Replace, false);

                     }

                     else  //Autocad DWG

                     {

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

                                                 (OpenMode.ForWrite);

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

                                                                                     DuplicateRecordCloning.Replace, false);

                     }

                    targetTransaction.Commit();

                 }

             }

             return targetDatabase;

         }

    Please use plain text.