.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

The problem with WblockCloneObjects to demension

1 REPLY 1
Reply
Message 1 of 2
HelloWorlddd
375 Views, 1 Reply

The problem with WblockCloneObjects to demension

I can use WblockCloneObjects to some entity, just like Line, Circle, DBText, BlockReference, it's will wrok ok, but when I use this method to the Demension entity, there is a problem that I can't solve.

 

If a new blank drawing contain any demension entity, whatever it is the default standard demension style or custom ISO-L and ISO-R demension style,, then use WblockCloneObjects, the demension entityies that copyied from the source drawing won't display properly, but they are actually copied, just need to open any block editor and close, or save the drawing and reopen it, the demension will display, it's weird.

 

Blelow is a code example.

   [CommandMethod("SD")]
        static public void createSidebar()
        {
            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            Editor acEd = acDoc.Editor;
            AnnotativeStates anno;
            try
            {
                using (DocumentLock doclock = acDoc.LockDocument())
                {
                    using (Transaction acTrans = acDoc.TransactionManager.StartTransaction())
                    {
                        Database sideDb = new Database(false, true);
                        sideDb.ReadDwgFile(@"D:\AutocadCommandCollectionNew\Data\Drawing\Sidebar.dwg", System.IO.FileShare.ReadWrite, true, "");
                       // sideDb.ReadDwgFile(@"C:\Test\Trusted\Sidebar.dwg", System.IO.FileShare.ReadWrite, true, "");
                        ObjectIdCollection sideDataBaseObjectcIds = new ObjectIdCollection();

                        using (Transaction sideTrans = sideDb.TransactionManager.StartTransaction())
                        {

                            //BlockTableRecord sideBlkTblRec = (BlockTableRecord)sideTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite);
                            BlockTable sideBlkTbl = sideTrans.GetObject(sideDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                            BlockTableRecord sideBlkTblRec = sideTrans.GetObject(sideBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                             anno = sideBlkTblRec.Annotative;
                            foreach (ObjectId id in sideBlkTblRec)
                            {
                                Entity entityObj = sideTrans.GetObject(id, OpenMode.ForRead) as Entity;
                                if (entityObj != null)
                                {
                                    sideDataBaseObjectcIds.Add(id);
                                }
                            }
                            //  sideTrans.Abort();// Do not use Abort inside: try { catch {} } code block
                        }


                        // BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                        // BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                        BlockTableRecord acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite);
                        IdMapping acIdMap = new IdMapping();
                        acCurDb.WblockCloneObjects(sideDataBaseObjectcIds, acBlkTblRec.ObjectId, acIdMap, DuplicateRecordCloning.Replace,false);
                        if (anno == AnnotativeStates.True) acBlkTblRec.Annotative = anno; 
                                      
                        acEd.UpdateScreen();
                        acEd.UpdateTiledViewportsFromDatabase();
                        acTrans.Commit();
                       // Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();//optional
                    }

                }

            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message + "\nFound  " + ex.StackTrace);
            }
            finally
            {

            }
        }

 Below is the result picture:

exsiting.PNG

 

I hope someone can help me, very thanks.

 

Attchment has the source drawing, it should copy to D:\AutocadCommandCollectionNew\Data\Drawing\Sidebar.dwg

1 REPLY 1
Message 2 of 2
HelloWorlddd
in reply to: HelloWorlddd

I find some new information, if execute this command in the new drawing, it will display properly, but if execute this command in a drawing that contain any entity, the dimension won't display properly as explain above.
Is there anyone can help me? Thanks as always.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost