<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Accessing Drawings in Background is Breaking Viewports on Layout in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/accessing-drawings-in-background-is-breaking-viewports-on-layout/m-p/12684527#M4687</link>
    <description>&lt;P&gt;I wanted to post an update to this with something that I found which seems to have resolved my issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On the code I mentioned that updates layers, I found that the database.SaveAs method had the bBakAndRename parameter set to false. After changing this to true, the viewport shifting issue ceased.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tested it multiple times, and 100% of the time, if bBakAndRename was set to false, the viewports would be broken. Changing this to true resolved the issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not exactly sure why bBakAndRename has this impact, but clearly it causes issues in the database. For context, this is what the developer guide has to say about it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;If bBakAndRename is false, then no .bak file is created, a full save is always done, and if the Database being saved is the main database for a document in AutoCAD, then the document's filename will NOT change to the saved name.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Apr 2024 15:56:57 GMT</pubDate>
    <dc:creator>richardpangburn</dc:creator>
    <dc:date>2024-04-03T15:56:57Z</dc:date>
    <item>
      <title>Accessing Drawings in Background is Breaking Viewports on Layout</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-drawings-in-background-is-breaking-viewports-on-layout/m-p/12678777#M4686</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We have some simple code that accesses a list of drawings that the user loads up in the UI (Winforms). The user inputs the desired brightness and contrast for any raster image found, and the program will run through the drawings and update accordingly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This has worked fine in the past but lately we have experienced an issue where, upon opening the edited drawings, the following situation has occurred:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The first paperspace layout tab has been made active&lt;/LI&gt;&lt;LI&gt;A viewport has been moved from it's original location up and to the right&lt;/LI&gt;&lt;LI&gt;The viewport has been made active&lt;/LI&gt;&lt;LI&gt;The viewport has been set to 1:1&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The exact same situation occurs in another program we have that updates layers. The code does not reference which layout to use, and simply gets the model space BlockTableRecord, iterates through it to find the rasters, and edits them accordingly. Likewise in the layer updating tool, the program only access the layer table to make changes, yet a viewport on the first layout tab will always be screwed up afterwards.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone have any ideas about what may be happening? We're using AutoCAD Map3D 2022. This tool has been in use for a while and hasn't done this to us in the past. Wondering if maybe an update has changed something we're not accounting for?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the snippet of code that is accessing the second drawing, editing the raster, saving, and closing. The get_modelspace() method just takes the transaction and database and returns the model space BlockTableRecord.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;if (is_opened == false)
{
    using (Database Database2 = new Database(false, true))
    {
        Database2.ReadDwgFile(file1, FileOpenMode.OpenForReadAndAllShare, true, "");
        //System.IO.FileShare.ReadWrite, false, null);
        Database2.CloseInput(true);
        HostApplicationServices.WorkingDatabase = Database2;

        using (Autodesk.AutoCAD.DatabaseServices.Transaction Trans2 = Database2.TransactionManager.StartTransaction())
        {

            BlockTableRecord BtrecordMS2 = Functions.get_modelspace(Trans2, Database2);
            BtrecordMS2.UpgradeOpen();


            foreach (ObjectId id1 in BtrecordMS2)
            {
                RasterImage image = Trans2.GetObject(id1, OpenMode.ForWrite) as RasterImage;
                double contrast = 50;
                double brightness = 50;
                if (Functions.IsNumeric(textBox_image_brightness.Text) == true) brightness = Convert.ToDouble(textBox_image_brightness.Text);
                if (Functions.IsNumeric(textBox_image_contrast.Text) == true) contrast = Convert.ToDouble(textBox_image_contrast.Text);
                if (image != null)
                {
                    image.Contrast = Convert.ToByte(contrast);
                    image.Brightness = Convert.ToByte(brightness);
                }
            }


            Trans2.Commit();
            Database2.SaveAs(file1, true, DwgVersion.Current, ThisDrawing.Database.SecurityParameters);
        }
        HostApplicationServices.WorkingDatabase = ThisDrawing.Database;
        Database2.Dispose();
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2024 14:52:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-drawings-in-background-is-breaking-viewports-on-layout/m-p/12678777#M4686</guid>
      <dc:creator>richardpangburn</dc:creator>
      <dc:date>2024-04-01T14:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing Drawings in Background is Breaking Viewports on Layout</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-drawings-in-background-is-breaking-viewports-on-layout/m-p/12684527#M4687</link>
      <description>&lt;P&gt;I wanted to post an update to this with something that I found which seems to have resolved my issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On the code I mentioned that updates layers, I found that the database.SaveAs method had the bBakAndRename parameter set to false. After changing this to true, the viewport shifting issue ceased.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tested it multiple times, and 100% of the time, if bBakAndRename was set to false, the viewports would be broken. Changing this to true resolved the issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not exactly sure why bBakAndRename has this impact, but clearly it causes issues in the database. For context, this is what the developer guide has to say about it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;If bBakAndRename is false, then no .bak file is created, a full save is always done, and if the Database being saved is the main database for a document in AutoCAD, then the document's filename will NOT change to the saved name.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 15:56:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-drawings-in-background-is-breaking-viewports-on-layout/m-p/12684527#M4687</guid>
      <dc:creator>richardpangburn</dc:creator>
      <dc:date>2024-04-03T15:56:57Z</dc:date>
    </item>
  </channel>
</rss>

