<?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 How to cut a hole in a hatch in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/how-to-cut-a-hole-in-a-hatch/m-p/4612165#M10836</link>
    <description>&lt;P&gt;I need to cut a hole in the hatch pattern. A hole is a area which is not hatched. I have two closed polylines. I need to hatch the poly1 - poly2 area.&lt;/P&gt;&lt;P&gt;I tried adding both to the ObjectIdCollection, but that throws up an error.&lt;/P&gt;&lt;P&gt;I tried creating Regions and subtracting it. However, we can create Region for the closed polylines, but not the hatch.&lt;/P&gt;&lt;P&gt;Here is the code to create the hatch&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        [CommandMethod("TestHatchHole", CommandFlags.UsePickSet)]
        public static void CreateHatch()
        {

            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            try
            {
                using (Transaction Tx = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
                {

                    ObjectId ModelSpaceId =
                    SymbolUtilityServices.GetBlockModelSpaceId(db);

                    BlockTableRecord btr = Tx.GetObject(ModelSpaceId,
                                      OpenMode.ForWrite) as BlockTableRecord;

                    Point2d pt = new Point2d(0.0, 0.0);
                    Autodesk.AutoCAD.DatabaseServices.Polyline plBox =
                              new Autodesk.AutoCAD.DatabaseServices.Polyline(4);

                    plBox.Normal = Vector3d.ZAxis;
                    plBox.AddVertexAt(0, pt, 0.0, -1.0, -1.0);
                    plBox.AddVertexAt(1,
                                 new Point2d(pt.X + 50, pt.Y), 0.0, -1.0, -1.0);
                    plBox.AddVertexAt(2,
                              new Point2d(pt.X + 50, pt.Y + 50), 0.0, -1.0, -1.0);
                    plBox.AddVertexAt(3,
                                  new Point2d(pt.X, pt.Y + 50), 0.0, -1.0, -1.0);
                    plBox.Closed = true;

                    ObjectId pLineId;
                    pLineId = btr.AppendEntity(plBox);
                    Tx.AddNewlyCreatedDBObject(plBox, true);


                    Point2d pt1 = new Point2d(0.0, 0.0);
                    Autodesk.AutoCAD.DatabaseServices.Polyline plHole =
                              new Autodesk.AutoCAD.DatabaseServices.Polyline(4);

                    plHole.Normal = Vector3d.ZAxis;
                    plHole.AddVertexAt(0, pt1, 0.0, -1.0, -1.0);
                    plHole.AddVertexAt(1,
                                 new Point2d(pt1.X + 5, pt1.Y), 0.0, -1.0, -1.0);
                    plHole.AddVertexAt(2,
                              new Point2d(pt1.X + 5, pt1.Y + 5), 0.0, -1.0, -1.0);
                    plHole.AddVertexAt(3,
                                  new Point2d(pt1.X, pt1.Y + 5), 0.0, -1.0, -1.0);
                    plHole.Closed = true;

                    var plHoleId = btr.AppendEntity(plHole);
                    Tx.AddNewlyCreatedDBObject(plHole, true);




                    ObjectIdCollection ObjIds = new ObjectIdCollection();
                    ObjIds.Add(pLineId);

                    Hatch oHatch = new Hatch();
                    Vector3d normal = new Vector3d(0.0, 0.0, 1.0);
                    oHatch.Normal = normal;
                    oHatch.Elevation = 0.0;
                    oHatch.PatternScale = 2.0;
                    string hatchPattern = "ANSI31";
                    oHatch.SetHatchPattern(HatchPatternType.PreDefined, hatchPattern);
                    oHatch.ColorIndex = 1;

                    btr.AppendEntity(oHatch);
                    Tx.AddNewlyCreatedDBObject(oHatch, true);
                    //this works ok  
                    oHatch.Associative = true;
                    oHatch.AppendLoop((int)HatchLoopTypes.Default, ObjIds);

                    oHatch.EvaluateHatch(true);

                    Tx.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {

            }
            catch (System.Exception ex)
            {

            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Nov 2013 07:17:36 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-11-12T07:17:36Z</dc:date>
    <item>
      <title>How to cut a hole in a hatch</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-cut-a-hole-in-a-hatch/m-p/4612165#M10836</link>
      <description>&lt;P&gt;I need to cut a hole in the hatch pattern. A hole is a area which is not hatched. I have two closed polylines. I need to hatch the poly1 - poly2 area.&lt;/P&gt;&lt;P&gt;I tried adding both to the ObjectIdCollection, but that throws up an error.&lt;/P&gt;&lt;P&gt;I tried creating Regions and subtracting it. However, we can create Region for the closed polylines, but not the hatch.&lt;/P&gt;&lt;P&gt;Here is the code to create the hatch&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        [CommandMethod("TestHatchHole", CommandFlags.UsePickSet)]
        public static void CreateHatch()
        {

            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            try
            {
                using (Transaction Tx = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
                {

                    ObjectId ModelSpaceId =
                    SymbolUtilityServices.GetBlockModelSpaceId(db);

                    BlockTableRecord btr = Tx.GetObject(ModelSpaceId,
                                      OpenMode.ForWrite) as BlockTableRecord;

                    Point2d pt = new Point2d(0.0, 0.0);
                    Autodesk.AutoCAD.DatabaseServices.Polyline plBox =
                              new Autodesk.AutoCAD.DatabaseServices.Polyline(4);

                    plBox.Normal = Vector3d.ZAxis;
                    plBox.AddVertexAt(0, pt, 0.0, -1.0, -1.0);
                    plBox.AddVertexAt(1,
                                 new Point2d(pt.X + 50, pt.Y), 0.0, -1.0, -1.0);
                    plBox.AddVertexAt(2,
                              new Point2d(pt.X + 50, pt.Y + 50), 0.0, -1.0, -1.0);
                    plBox.AddVertexAt(3,
                                  new Point2d(pt.X, pt.Y + 50), 0.0, -1.0, -1.0);
                    plBox.Closed = true;

                    ObjectId pLineId;
                    pLineId = btr.AppendEntity(plBox);
                    Tx.AddNewlyCreatedDBObject(plBox, true);


                    Point2d pt1 = new Point2d(0.0, 0.0);
                    Autodesk.AutoCAD.DatabaseServices.Polyline plHole =
                              new Autodesk.AutoCAD.DatabaseServices.Polyline(4);

                    plHole.Normal = Vector3d.ZAxis;
                    plHole.AddVertexAt(0, pt1, 0.0, -1.0, -1.0);
                    plHole.AddVertexAt(1,
                                 new Point2d(pt1.X + 5, pt1.Y), 0.0, -1.0, -1.0);
                    plHole.AddVertexAt(2,
                              new Point2d(pt1.X + 5, pt1.Y + 5), 0.0, -1.0, -1.0);
                    plHole.AddVertexAt(3,
                                  new Point2d(pt1.X, pt1.Y + 5), 0.0, -1.0, -1.0);
                    plHole.Closed = true;

                    var plHoleId = btr.AppendEntity(plHole);
                    Tx.AddNewlyCreatedDBObject(plHole, true);




                    ObjectIdCollection ObjIds = new ObjectIdCollection();
                    ObjIds.Add(pLineId);

                    Hatch oHatch = new Hatch();
                    Vector3d normal = new Vector3d(0.0, 0.0, 1.0);
                    oHatch.Normal = normal;
                    oHatch.Elevation = 0.0;
                    oHatch.PatternScale = 2.0;
                    string hatchPattern = "ANSI31";
                    oHatch.SetHatchPattern(HatchPatternType.PreDefined, hatchPattern);
                    oHatch.ColorIndex = 1;

                    btr.AppendEntity(oHatch);
                    Tx.AddNewlyCreatedDBObject(oHatch, true);
                    //this works ok  
                    oHatch.Associative = true;
                    oHatch.AppendLoop((int)HatchLoopTypes.Default, ObjIds);

                    oHatch.EvaluateHatch(true);

                    Tx.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {

            }
            catch (System.Exception ex)
            {

            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2013 07:17:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-cut-a-hole-in-a-hatch/m-p/4612165#M10836</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-12T07:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to cut a hole in a hatch</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-cut-a-hole-in-a-hatch/m-p/4613677#M10837</link>
      <description>HI,&lt;BR /&gt;&lt;BR /&gt;Please go through the link, I hope you are looking for something like below:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://adndevblog.typepad.com/autocad/2013/07/create-hatch-objects-using-trace-boundaries-using-net.html" target="_blank"&gt;http://adndevblog.typepad.com/autocad/2013/07/create-hatch-objects-using-trace-boundaries-using-net.html&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Nov 2013 15:59:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-cut-a-hole-in-a-hatch/m-p/4613677#M10837</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-12T15:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to cut a hole in a hatch</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-cut-a-hole-in-a-hatch/m-p/4613783#M10838</link>
      <description>&lt;P&gt;I have write the code in VB for your purpuse.&lt;/P&gt;&lt;PRE&gt; &amp;lt;CommandMethod("HAT")&amp;gt; Public Sub TestHatch()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim ppo As PromptPointOptions = New PromptPointOptions(vbLf &amp;amp; "Select a point for hatch boundary:")
        Dim ppr As PromptPointResult = ed.GetPoint(ppo)
        If ppr.Status &amp;lt;&amp;gt; PromptStatus.OK Then
            Return
        End If
        Dim dbObjColl As DBObjectCollection = ed.TraceBoundary(ppr.Value, True)
        Dim loopObjIdColl As ObjectIdCollection = New ObjectIdCollection()

        Using tx As Transaction = db.TransactionManager.StartTransaction()
            Dim bt As BlockTable = tx.GetObject(db.BlockTableId, OpenMode.ForRead)
            Dim ms As BlockTableRecord = tx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
            For Each pline As Polyline In dbObjColl
                pline.Closed = True
                loopObjIdColl.Add(ms.AppendEntity(pline))
                tx.AddNewlyCreatedDBObject(pline, True)
            Next

            Dim _hatch As Hatch = New Hatch()
            Dim normal As Vector3d = New Vector3d(0, 0, 1)
            _hatch.Normal = normal
            _hatch.Elevation = 0
            _hatch.PatternScale = 2
            _hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31")
            _hatch.ColorIndex = 1
            ms.AppendEntity(_hatch)
            tx.AddNewlyCreatedDBObject(_hatch, True)
            _hatch.Associative = True

            For Each objId As ObjectId In loopObjIdColl
                Dim ids As ObjectIdCollection = New ObjectIdCollection()
                ids.Add(objId)
                _hatch.AppendLoop(HatchLoopTypes.Outermost, ids)
            Next
            _hatch.EvaluateHatch(True)
            tx.Commit()
        End Using

    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2013 16:30:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-cut-a-hole-in-a-hatch/m-p/4613783#M10838</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-12T16:30:05Z</dc:date>
    </item>
  </channel>
</rss>

