<?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: Can't save boolean operation to disk. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8761730#M22607</link>
    <description>&lt;P&gt;That's what I see when I open the file:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TT.png" style="width: 659px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/631528i0E721E3E59180014/image-size/large?v=v2&amp;amp;px=999" role="button" title="TT.png" alt="TT.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Apr 2019 09:51:39 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2019-04-30T09:51:39Z</dc:date>
    <item>
      <title>Can't save boolean operation to disk.</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8755860#M22600</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;In the following routine, w&lt;SPAN style="font-family: inherit;"&gt;hile cycling through all the entities, i delete some of them and i do a boolean operation for some of them.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;At the end I save the drawing with a new name. When I open the drawing, the deleted entites are gone, as they should be, but the ones which went through the boolean operation are not modified. On the screen they look like the boolean operation was successful. If i save the drawing manually, they are saved correctly.&lt;/P&gt;
&lt;P&gt;Should I do more than committing the transaction before saving the drawing?&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;PRE&gt;Document acDoc = Application.DocumentManager.MdiActiveDocument;

            Editor ed = acDoc.Editor;

            Database acCurDb = acDoc.Database;

            // LOCK DOCUMENT BEFORE TRANSACTION
            using (DocumentLock docLock = acDoc.LockDocument())
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Block table record for read
                ed.WriteMessage("\nDAP");
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                                OpenMode.ForRead) as BlockTable;

                // Open the Block table record Model space for write
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;
                foreach (ObjectId id in acBlkTblRec)
                {

                    Solid3d entity = (Solid3d)acTrans.GetObject(id, OpenMode.ForWrite);
                    ObjectId intityId = entity.ObjectId;
                    Extents3d ext = entity.GeometricExtents;

                    
                    if ((ext.MaxPoint.X &amp;lt; tileMin.X)||
                        (ext.MinPoint.X&amp;gt;tileMax.X)||
                        (ext.MaxPoint.Y&amp;lt;tileMin.Y)||
                        (ext.MinPoint.Y&amp;gt;tileMax.Y)
                        )//if outside
                    {
                        //delete entity
                        entity.Erase(true);
                    }
                    else if (!((ext.MinPoint.X &amp;gt; tileMin.X) &amp;amp;&amp;amp; (ext.MinPoint.Y &amp;gt; tileMin.Y) &amp;amp;&amp;amp;
                        (ext.MaxPoint.X &amp;lt; tileMax.X) &amp;amp;&amp;amp; (ext.MaxPoint.Y &amp;lt; tileMax.Y)))//else if not completely inside
                    {
                        // start creating box
                        using (var box = new Solid3d())
                        {
                            box.CreateBox(250.0, 250, 800.0);
                            box.TransformBy(Matrix3d.Displacement(new Vector3d(tileMin.X+125.0, tileMin.Y+125.0, 0.0)));
                            entity.BooleanOperation(BooleanOperationType.BoolIntersect, box);
                        }
                        // end creating box
                    }
                }

                // Save the new objects to the database
                acTrans.Commit();
            }
            ed.WriteMessage(cale + deTaiat + "\\" + deTaiat + "_" + quarter[ct] + "_" + sixteen[4 * ct + ct1] + "_SOLID.dwg");
            acCurDb.SaveAs(cale + deTaiat + "\\" + deTaiat + "_" + quarter[ct] +"_" + sixteen[4*ct+ct1]+ "_SOLID.dwg", DwgVersion.Current);&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Apr 2019 15:32:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8755860#M22600</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-26T15:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: Can't save boolean operation to disk.</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8756044#M22601</link>
      <description>&lt;P&gt;Does the following snippet works for you? (run it in an empty drawing)&lt;/P&gt;
&lt;P&gt;If so, you should search the context differences between this code and yours.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("TEST", CommandFlags.Session)]
        public static void Test()
        {
            var docs = Application.DocumentManager;
            var doc = docs.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            using (doc.LockDocument())
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var cs = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                var sphere = new Solid3d();
                sphere.CreateSphere(7.0);
                sphere.TransformBy(Matrix3d.Displacement(new Vector3d(5.0, 5.0, 5.0)));
                cs.AppendEntity(sphere);
                tr.AddNewlyCreatedDBObject(sphere, true);
                using (var box = new Solid3d())
                {
                    box.CreateBox(10.0, 10.0, 10.0);
                    box.TransformBy(Matrix3d.Displacement(new Vector3d(5.0, 5.0, 5.0)));
                    sphere.BooleanOperation(BooleanOperationType.BoolIntersect, box);
                }
                    tr.Commit();
            }
            db.SaveAs(@"C:\Temp\BooleanTest.dwg", DwgVersion.Current);
            docs.Open(@"C:\Temp\BooleanTest.dwg");
            docs.MdiActiveDocument.SendStringToExecute("_-view _seiso\n", false, false, false);
        }&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Apr 2019 16:52:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8756044#M22601</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-04-26T16:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: Can't save boolean operation to disk.</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8759791#M22602</link>
      <description>&lt;P&gt;There are many minor differences between the codes, so i changed gradually your code to see if I end up getting the same error.&lt;/P&gt;
&lt;P&gt;First i did the boolean operation between an existing sphere and a newly generated box. I ran Test in a drawing that was containing already the sphere.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, when I tried to open the drawing automatically, then do the boolean operation, i got the same problem with the boolean operation not being saved.&lt;/P&gt;
&lt;P&gt;It's definitely something i'm not doing just before saving.&lt;/P&gt;
&lt;P&gt;I attached the drawing that contains the sphere.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help so far.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please see attached code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;[CommandMethod("TEST", CommandFlags.Session)]
        public static void Test()
        {
            var docs = Application.DocumentManager;
            string file = "C:\\Temp\\BooleanTest1.dwg";
            if (File.Exists(file))
            {
                Document almeu = docs.Open(file, false);
                docs.MdiActiveDocument = almeu;
                string drName = Path.GetFileName(almeu.Name);
            }
            else
            {
                docs.MdiActiveDocument.Editor.WriteMessage("File " + file + " does not exist.");
            }
            var doc = docs.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            using (doc.LockDocument())
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var cs = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                foreach (ObjectId id in cs)
                {
                    Solid3d entity = (Solid3d)tr.GetObject(id, OpenMode.ForWrite);
                    //var sphere = new Solid3d();
                    //sphere.CreateSphere(7.0);
                    //sphere.TransformBy(Matrix3d.Displacement(new Vector3d(5.0, 5.0, 5.0)));
                    //cs.AppendEntity(sphere);
                    //tr.AddNewlyCreatedDBObject(sphere, true);
                    using (var box = new Solid3d())
                    {
                        box.CreateBox(10.0, 10.0, 10.0);
                        box.TransformBy(Matrix3d.Displacement(new Vector3d(5.0, 5.0, 5.0)));
                        entity.BooleanOperation(BooleanOperationType.BoolIntersect, box);
                    }
                }
                tr.Commit();
            }
            db.SaveAs("C:\\Temp\\BooleanTest.dwg", DwgVersion.Current);

            docs.Open("C:\\Temp\\BooleanTest.dwg");
            docs.MdiActiveDocument.SendStringToExecute("_-view _seiso\n", false, false, false);
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 14:51:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8759791#M22602</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-29T14:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: Can't save boolean operation to disk.</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8759838#M22603</link>
      <description>&lt;P&gt;I just tested your code and it worked fine.&lt;/P&gt;
&lt;P&gt;Which version of AutoCAD are you using?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 15:07:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8759838#M22603</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-04-29T15:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Can't save boolean operation to disk.</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8759868#M22604</link>
      <description>&lt;P&gt;2019 Vanilla AutoCAD.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 15:16:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8759868#M22604</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-29T15:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can't save boolean operation to disk.</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8759891#M22605</link>
      <description>&lt;P&gt;It works fine for me with 2019 Vanilla AutoCAD.&lt;/P&gt;
&lt;P&gt;Perhaps some settings, but I cannot see which.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 15:23:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8759891#M22605</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-04-29T15:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Can't save boolean operation to disk.</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8761674#M22606</link>
      <description>&lt;P&gt;I discovered that it's a visualisation issue probably.&lt;/P&gt;
&lt;P&gt;The boolean operation is saved, but i't not visible in 2d wireframe. any other visual style shows the objects as they should be.&lt;/P&gt;
&lt;P&gt;Also, even if I am in 2d wireframe, if I orbit, it looks the right way, with the trimmed solids.&lt;/P&gt;
&lt;P&gt;Can you open the attached file to see how it looks?&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 09:34:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8761674#M22606</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-30T09:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can't save boolean operation to disk.</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8761730#M22607</link>
      <description>&lt;P&gt;That's what I see when I open the file:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TT.png" style="width: 659px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/631528i0E721E3E59180014/image-size/large?v=v2&amp;amp;px=999" role="button" title="TT.png" alt="TT.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 09:51:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8761730#M22607</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-04-30T09:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Can't save boolean operation to disk.</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8761774#M22608</link>
      <description>&lt;P&gt;So the issue with is my computer. The code works perfectly.&lt;/P&gt;
&lt;P&gt;when i open the drawing, it looks like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 363px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/631541i97034E81865BA3E2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If i orbit, it looks like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 357px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/631543i08959C434C70EC58/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;When i exit orbit, it looks like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2.png" style="width: 298px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/631545i0ECC7A8E780796E3/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.png" alt="2.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I'll have to figure out what's wrong with my autocad, but i can use the routine as is.&lt;/P&gt;
&lt;P&gt;Thank you so much for all your help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 10:16:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8761774#M22608</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-30T10:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: Can't save boolean operation to disk.</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8766980#M22609</link>
      <description>&lt;P&gt;The solution was a workaround.&lt;/P&gt;
&lt;P&gt;Instead of using database.saveas, the routine is copying the original file, runs on the new file and uses doc.closeandsave.&lt;/P&gt;
&lt;P&gt;This way the weird display doesn't happen anymore.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 13:37:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-save-boolean-operation-to-disk/m-p/8766980#M22609</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-05-02T13:37:06Z</dc:date>
    </item>
  </channel>
</rss>

