Author Topic: how to solve this problem ?  (Read 228 times)

0 Members and 1 Guest are viewing this topic.

netcai

  • Mosquito
  • Posts: 10
how to solve this problem ?
« 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);

Bryco

  • Water Moccasin
  • Posts: 1812
Re: how to solve this problem ?
« Reply #1 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();

netcai

  • Mosquito
  • Posts: 10
Re: how to solve this problem ?
« Reply #2 on: November 29, 2017, 06:08:37 am »
thanks,but layoutmanager can only be used in actived document,not the side database

n.yuan

  • Bull Frog
  • Posts: 240
Re: how to solve this problem ?
« Reply #3 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.