.NET

Reply
Mentor
GVDB
Posts: 215
Registered: ‎01-16-2006
Message 1 of 1 (136 Views)

WblockCloneObjects Layout of Inventor DWG

136 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;

     }

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community