<?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 : Erase Hatch using Polyline ObjectId in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586982#M53741</link>
    <description>&lt;P&gt;Hallex,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your time and your code. I'll try tomorrow and let you know if this works better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Nag`&lt;/P&gt;</description>
    <pubDate>Sun, 19 Aug 2012 17:15:06 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-08-19T17:15:06Z</dc:date>
    <item>
      <title>Erase Hatch using Polyline ObjectId</title>
      <link>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586760#M53731</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a drawing with a Polyline filled with Hatch. Also I have that Polyline ObjectId. So using this ployline ObjectId I want to erase the Hatch inside polyline. Can anyone give an idea how I can erase the Hatch.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm developing the application using C#.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Nag&lt;/P&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>Sat, 18 Aug 2012 16:00:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586760#M53731</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-18T16:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Erase Hatch using Polyline ObjectId</title>
      <link>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586814#M53732</link>
      <description>&lt;P&gt;I have idea to select hatch by fence selection&lt;/P&gt;&lt;P&gt;here is a quick demo example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        [CommandMethod("ehatch")]
        public void eraseHatch()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            Point3d p1; Point3d p2;
            try
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    //------------------------------------------------------------------
                    // Create filter object, this filter can have any types to select, i.e. lines
                    SelectionFilter filter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "lwpolyline"), new TypedValue(70, 1) });
                    // Select lines on screen
                    PromptSelectionResult psr = ed.GetSelection(filter);
                    // Check if selection is succeed
                    if (psr.Status != PromptStatus.OK) return;

                    // if OK then iterate trough selected lines
                    foreach (SelectedObject selobj in psr.Value)
                    {
                        // Cast SelectedObject as DBObject (or as an Entity)
                        DBObject obj = tr.GetObject(selobj.ObjectId, OpenMode.ForRead) as DBObject;

                        if (obj != null)
                        {
                            // Cast DBObject as Polyline
                            Polyline pline = obj as Polyline;
                            p1 = pline.GetPoint3dAt(0);
                            p2 = pline.GetPoint3dAt(1);
                            Point3dCollection pts = new Point3dCollection();
                            pts.Add(p1);
                            pts.Add(p2);
                            // select hatch by fence
                            filter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "hatch") });
                            psr = ed.SelectFence(pts,filter);
                            SelectionSet hset = psr.Value;
                            ObjectId[] ids= hset.GetObjectIds();
                            ObjectId hid = ids[0];
                            DBObject hobj = tr.GetObject(hid, OpenMode.ForRead) as DBObject;
                            Hatch inhatch = hobj as Hatch;
                            hobj.UpgradeOpen();
                            hobj.Erase();


                        }
                    }

                    tr.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage
                    (ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800000" face="arial,helvetica,sans-serif"&gt;~'J'~&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Aug 2012 21:35:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586814#M53732</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-08-18T21:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Erase Hatch using Polyline ObjectId</title>
      <link>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586842#M53733</link>
      <description>&lt;P&gt;Hello Hallex,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your information.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But here I have few problems.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Hatch erasing process using Polyline ObjectId should be done automatically, no user interaction is required.&lt;/LI&gt;&lt;LI&gt;As I have Polyline ObjectId, I tried to collect the points from the Polyline used it in fence selection. This fence selection will work only when there is no adjusent Hatch attached to this Polyline. For your understanding I have attached a sample drawing which shows a set of continious polylines with hatches. Now I want to erase first Hatch in drawing (Pink color) and I have corresponding Polyline objectid. If I use fence selection in this requirement, adjuscent hatch is also getting selected.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So Is there any other way to erase the Hatch using Polyline ObjectId?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;Nag&lt;/P&gt;</description>
      <pubDate>Sun, 19 Aug 2012 02:44:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586842#M53733</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-19T02:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Erase Hatch using Polyline ObjectId</title>
      <link>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586878#M53734</link>
      <description>&lt;P&gt;Well, I see this hatch is adjanced and associative,&lt;/P&gt;&lt;P&gt;one possiible way is&amp;nbsp;to perform command twice, I'm pretty&lt;/P&gt;&lt;P&gt;sure there is other way to do the&amp;nbsp;job, but I don't know how yet&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        [CommandMethod("ehatch")]
        public void eraseHatch()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            Point3d p1; Point3d p2;
            try
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    //------------------------------------------------------------------
                    // Create filter object, this filter can have any types to select, i.e. lines
                    SelectionFilter filter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "lwpolyline"), new TypedValue(70, 1) });
                    // Select lines on screen
                    PromptSelectionResult psr = ed.GetSelection(filter);
                    // Check if selection is succeed
                    if (psr.Status != PromptStatus.OK) return;

                    // if OK then iterate trough selected lines
                    foreach (SelectedObject selobj in psr.Value)
                    {
                        // Cast SelectedObject as DBObject (or as an Entity)
                        DBObject obj = tr.GetObject(selobj.ObjectId, OpenMode.ForRead) as DBObject;

                        if (obj != null)
                        {
                            // Cast DBObject as Polyline
                            Polyline pline = obj as Polyline;
                            p1 = pline.GetPoint3dAt(0);
                            p2 = pline.GetPoint3dAt(1);
                            Point3dCollection pts = new Point3dCollection();
                            pts.Add(p1);
                            pts.Add(p2);
                            
                            // select hatch by fence
                            filter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "hatch") });
                            psr = ed.SelectFence(pts, filter);
                            SelectionSet hset = psr.Value;
                            ObjectId[] ids = hset.GetObjectIds();
                            ObjectId hid = ids[0];
                            DBObject hobj = tr.GetObject(hid, OpenMode.ForRead) as DBObject;
                            Hatch inhatch = hobj as Hatch;
                            doc.TransactionManager.EnableGraphicsFlush(true);
                            inhatch.UpgradeOpen();
                            if (inhatch.Associative)
                            {
                                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Perform command \"ehatch\" twice");
                                pline.UpgradeOpen();                               
                                inhatch.Associative = false;
                                inhatch.RemoveAssociatedObjectIds();
                                inhatch.EvaluateHatch(true);
                                inhatch.RecordGraphicsModified(true);
                                tr.TransactionManager.QueueForGraphicsFlush();
                            }
                            ed.Regen();
                            
                            inhatch.Erase();

                            

                        }
                    }
                    doc.TransactionManager.FlushGraphics();
                    tr.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage
                    (ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966" face="arial,helvetica,sans-serif"&gt;~'J'~&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Aug 2012 06:29:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586878#M53734</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-08-19T06:29:41Z</dc:date>
    </item>
    <item>
      <title>Re : Erase Hatch using Polyline ObjectId</title>
      <link>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586892#M53735</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the Hatch is associative, you can use the PersistentReactorId.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a little sample:&lt;/P&gt;&lt;PRE&gt;        private void EraseAssocHatch(ObjectId sourceId)
        {
            Database db = sourceId.Database;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Entity ent = (Entity)tr.GetObject(sourceId, OpenMode.ForRead);
                foreach (ObjectId id in ent.GetPersistentReactorIds())
                {
                    if (id.ObjectClass.Name == "AcDbHatch")
                    {
                        Hatch h = (Hatch)tr.GetObject(id, OpenMode.ForWrite);
                        h.Erase();
                    }
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Aug 2012 08:14:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586892#M53735</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2012-08-19T08:14:06Z</dc:date>
    </item>
    <item>
      <title>Re : Erase Hatch using Polyline ObjectId</title>
      <link>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586910#M53736</link>
      <description>&lt;P&gt;gile,&lt;/P&gt;&lt;P&gt;it's working at all for this drawing, check yourself, please&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800000" face="arial,helvetica,sans-serif"&gt;~'J'~&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Aug 2012 11:41:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586910#M53736</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-08-19T11:41:48Z</dc:date>
    </item>
    <item>
      <title>Re : Erase Hatch using Polyline ObjectId</title>
      <link>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586920#M53737</link>
      <description>&lt;P&gt;As I said, this will only work with associative hatches.&lt;BR /&gt;In the attached drawing, only the left most one in associative (there're 2 duplicated).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Aug 2012 12:05:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586920#M53737</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2012-08-19T12:05:17Z</dc:date>
    </item>
    <item>
      <title>Re : Erase Hatch using Polyline ObjectId</title>
      <link>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586930#M53738</link>
      <description>&lt;P&gt;Hi _gile,&lt;/P&gt;&lt;P&gt;Thanks for explanation, maybe this happens after I've converted the drawing&lt;/P&gt;&lt;P&gt;with TreeView add-in on my A2009 format, so the code is not working on my machine&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Oleg&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Aug 2012 12:57:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586930#M53738</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-08-19T12:57:10Z</dc:date>
    </item>
    <item>
      <title>Re : Erase Hatch using Polyline ObjectId</title>
      <link>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586944#M53739</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found a solution for my problem using&amp;nbsp;SelectCrossingWindow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code which I used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for you help.&lt;/P&gt;&lt;P&gt;Nag&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Polyline pl = (Polyline)ent;
Point3d plCentroid = oStdFunc.GetCentroid(pl);
Point3d p1 = new Point3d(plCentroid.X - 50, plCentroid.Y - 50, 0.0);
Point3d p2 = new Point3d(plCentroid.X + 50, plCentroid.Y + 50, 0.0);
TypedValue[] values = { new TypedValue((int)DxfCode.Start, "HATCH") };
SelectionFilter filter = new SelectionFilter(values);
PromptSelectionResult psr = ed.SelectCrossingWindow(p1, p2, filter);
SelectionSet sSet = psr.Value;
oldHatchId = sSet[0].ObjectId;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Aug 2012 14:06:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586944#M53739</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-19T14:06:25Z</dc:date>
    </item>
    <item>
      <title>Re : Erase Hatch using Polyline ObjectId</title>
      <link>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586962#M53740</link>
      <description>&lt;P&gt;Gla you solved it by yourself&lt;/P&gt;&lt;P&gt;See if this code would be work better:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        [CommandMethod("ehatch")]
        public void eraseHatch()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;

            Point3d p1; Point3d p2; Point3d p3; Point3d p4;
            try
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    //------------------------------------------------------------------
                    // Create filter object, this filter can have any types to select, i.e. lwpolyline
                    SelectionFilter filter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "lwpolyline"), new TypedValue(70, 1) });
                    // Select lines on screen
                    PromptSelectionResult psr = ed.GetSelection(filter);
                    // Check if selection is succeed
                    if (psr.Status != PromptStatus.OK) return;

                    // if OK then iterate trough selected polylines
                    foreach (SelectedObject selobj in psr.Value)
                    {
                        // Cast SelectedObject as DBObject (or as an Entity)
                        DBObject obj = tr.GetObject(selobj.ObjectId, OpenMode.ForRead) as DBObject;

                        if (obj != null)
                        {
                            // Cast DBObject as Polyline
                            Polyline pline = obj as Polyline;
                            p1 = pline.GetPoint3dAt(0);
                            p2 = pline.GetPoint3dAt(1);
                            p3 = p1 + (p2 - p1).DivideBy(8);
                            p4 = p2 + (p1 - p2).DivideBy(8);
                            Point3dCollection pts = new Point3dCollection();
                            pts.Add(p3);
                            pts.Add(p4);

                            // select hatch by fence
                            filter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "hatch") });
                            psr = ed.SelectFence(pts, filter);
                            if (psr.Status != PromptStatus.OK) return;
                            SelectionSet hset = psr.Value;
                            // if OK then iterate trough selected hatches
                            foreach (SelectedObject sobj in hset)
                            {
                                // Cast SelectedObject as DBObject (or as an Entity)
                                DBObject hobj = tr.GetObject(sobj.ObjectId, OpenMode.ForRead) as DBObject;

                                if (hobj != null)
                                {
                                    Hatch inhatch = hobj as Hatch;
                                    inhatch.UpgradeOpen();
                                    inhatch.Associative = false;
                                    inhatch.Erase();
                                    tr.TransactionManager.QueueForGraphicsFlush();
                                }
                            }
                        }
                        doc.TransactionManager.FlushGraphics();

                        tr.Commit();

                    }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage
                    (ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800000" face="arial,helvetica,sans-serif"&gt;~'J'~&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Aug 2012 15:37:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586962#M53740</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-08-19T15:37:58Z</dc:date>
    </item>
    <item>
      <title>Re : Erase Hatch using Polyline ObjectId</title>
      <link>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586982#M53741</link>
      <description>&lt;P&gt;Hallex,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your time and your code. I'll try tomorrow and let you know if this works better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Nag`&lt;/P&gt;</description>
      <pubDate>Sun, 19 Aug 2012 17:15:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/erase-hatch-using-polyline-objectid/m-p/3586982#M53741</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-08-19T17:15:06Z</dc:date>
    </item>
  </channel>
</rss>

