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

0 Members and 1 Guest are viewing this topic.

netcai

  • Mosquito
  • Posts: 12
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: 1882
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: 12
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: 348
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.


WILL HATCH

  • Bull Frog
  • Posts: 450
Re: how to solve this problem ?
« Reply #4 on: December 20, 2017, 04:41:12 AM »
just a hunch, but if you set HostApplicationServices.WorkingDatabase to your side db it might help.

n.yuan

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

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: how to solve this problem ?
« Reply #6 on: December 21, 2017, 03:28:58 PM »
that's what I get for just skimming  :whistling: