TheSwamp

Code Red => .NET => Topic started by: netcai on November 28, 2017, 11:32:10 AM

Title: how to solve this problem ?
Post by: netcai on November 28, 2017, 11:32:10 AM
When I change a layout'name, the viewport on it will lost its Original size and scale.

Database currentDatabase = HostApplicationServices.WorkingDatabase;
                Database db = new Database(false, true);
                db.ReadDwgFile(item.FileName, System.IO.FileShare.ReadWrite, true, null);
                HostApplicationServices.WorkingDatabase = db;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                   var layouts = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                   
                    var layoutId = layouts.Contains(item.LayoutName) ? layouts.GetAt(item.LayoutName) : new ObjectId();
                   
                    Layout lay = (Layout)tr.GetObject(layoutId , OpenMode.ForWrite);
                    lay.LayoutName = newLayoutName;
                    tr.Commit();
                }
                db.SaveAs(item.FileName, DwgVersion.Current);
Title: Re: how to solve this problem ?
Post by: Bryco on November 28, 2017, 08:01:39 PM
Does it help if you use the  LayoutManager

LayoutManager lm = LayoutManager.Current;
                    Layout layout = tr.GetObject(lm.GetLayoutId(lm.CurrentLayout), OpenMode.ForWrite) as Layout;
                    layout.LayoutName = sDwg;
                    lm.Dispose();
Title: Re: how to solve this problem ?
Post by: netcai on November 29, 2017, 06:08:37 AM
thanks,but layoutmanager can only be used in actived document,not the side database
Title: Re: how to solve this problem ?
Post by: n.yuan on December 02, 2017, 06:01:57 PM
I can reproduce this behaviour (AutoCAD2018).

These are what I observed after renaming an layout:

1. The viewport on this layout loses its original size, scale (standard/custom), but its AnnotationScale remains unchanged. In my test, the viewport becomes larger.

2. the viewport would also changed to MSPACE mode if it was saved in PSACE mode prior to layout name changing

3. If there is multiple viewport on the layout, only one viewport changes due to the layout name change.

4. As matter of fact, not only name changing, any change made to the layout in side DB has the same affect to the viewport on that layout (I tried to change Layout.TabSelected property).

Of course, these strange behaviours do not happen when the drawing is opened in AutoCAD and layout name is changed (manually, or programmatically). It looks like if layout object is modified without Editor, something would happen.

It would be interesting to see if the same thing would happen or not when run open a drawing in accoreconsole.exe and modify layout, because open drawing and update in accoreconsole.exe is different from open a drawing as side database, even though in both cases editor is absent. I may try it out if I can manage a bit time later.

Title: Re: how to solve this problem ?
Post by: WILL HATCH on December 20, 2017, 04:41:12 AM
just a hunch, but if you set HostApplicationServices.WorkingDatabase to your side db it might help.
Title: Re: how to solve this problem ?
Post by: n.yuan on December 21, 2017, 09:30:50 AM
The OP's code  (and my code to reproduce the issue) does set the side DB as WorkingDatabase.
Title: Re: how to solve this problem ?
Post by: WILL HATCH on December 21, 2017, 03:28:58 PM
that's what I get for just skimming  :whistling: