TheSwamp

Code Red => .NET => Topic started by: latour_g on February 25, 2021, 12:02:45 PM

Title: Center the plot not working
Post by: latour_g on February 25, 2021, 12:02:45 PM
Hi,
I copy the plotsetting from a drawing to some other drawing.  Everything work fine except that when I open the drawing, it doesn't center the plot as it should.  The checkbox for "Center the plot" is correctly checked but I need to open Layout Manager and click "OK" for the change to take effect in my drawing.

Is there something I should add for this to work ?

Here is a portion of my code, the main command is quite long, that's why there is "....." at some place.

Code - C#: [Select]
  1. using (Transaction tr = db.TransactionManager.StartTransaction())
  2. {
  3.       using (var ps = new PlotSettings(layoutObj.ModelType))
  4.       {
  5.             var psv = PlotSettingsValidator.Current;
  6.  
  7.             psv.SetStdScaleType(ps, dictPS.StdScaleType);
  8.             psv.SetPlotCentered(ps, dictPS.PlotCentered);
  9.             psv.Set.......
  10.             .......
  11.  
  12.             ps.PlotViewportBorders = dictPS.PlotViewportBorders;
  13.             ps.PlotTransparency = dictPS.PlotTransparency;
  14.             ps.ScaleLineweights = dictPS.ScaleLineweights;
  15.             ps....
  16.             .......
  17.  
  18.             layoutObj.CopyFrom(ps);
  19.             layoutObj.PlotSettingsName = dictPS.PlotSettingsName;
  20.       }
  21.       tr.Commit();
  22. }
  23.  

Thank you
Title: Re: Center the plot not working
Post by: n.yuan on February 26, 2021, 10:20:33 AM
You may want to provide more information of the copying process (not the details of PlotSettings), such as which drawing (source, or destination) is open in AutoCAD editor? or one of them is opened as side database (then which one, source or destination)? or both open in AutoCAD editor? or both opened as side database?

For example, if the source drawing is currently open in AutoCAD editor and the destination drawing is opened as side database, have you tired to set HostApplication.WrokingDatabase to the side database?
Title: Re: Center the plot not working
Post by: latour_g on February 26, 2021, 10:49:38 AM
Hi,

Both drawing are open as side database so nothing is open AutoCAD.  Maybe that's what make it difficult to get the drawing center when opening it ?

It change correctly the properties but cannot center it since it's not open in AutoCAD I guess.

Title: Re: Center the plot not working
Post by: n.yuan on February 27, 2021, 10:46:01 AM
Have you tried to set the destination side database as WorkingDatabase after it is created (and you would restore the WorkingDataabse back to original database before the destination database is disposed)? Something like this:

var originalDB=HostApplicationServices.WorkingDatabase

using (var sourceDb=new Database(false, true))
{
    sourceDB.ReadDwgFromFile(....);

    // collecting plotsettings information to copy
    ... ...

    using (var destinationDB=new Database(false, true))
    {
        destinationDB.ReadFromDwgFile(...);
        try
        {
            // make this database as WorkingDatabase
            HostApplicationServices.WorkingDatabase=destinationDB
            //Setup plotSettings here
            ...
            desinationDB.SaveAs(...)
        }
        finally
        {
            HostApplicationServices.WorkingDatabase=originalDB
        }
    }
}

Title: Re: Center the plot not working
Post by: latour_g on March 02, 2021, 11:34:01 AM
It's working fine with WorkingDatabase.  THANK YOU SO MUCH !  :lol:
I would never thought about that !