<?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: Hatch does not work in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11951418#M8904</link>
    <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13886117"&gt;@hng_kaijianG7MAN&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, my code is not complete. I do have code for&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;appending to block table record&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;also, I tested with this code from gile.&amp;nbsp; still the same error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just don't understand, why the same code work for some pline but not the other, why the same pline code not working but HATCH command works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the test pline with problem does not have issue like open, self intersect.&amp;nbsp;&lt;/P&gt;&lt;P&gt;here code from gile&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;[CommandMethod("JGC.UI.Test", nameof(JGCTest_Hatch2), CommandFlags.Modal)]
        public static void JGCTest_Hatch2()
        {
            var oid = JTISelect.GetEntityX&amp;lt;Polyline&amp;gt;("\nPick a polyline:", "");
            if (oid.IsNull)
            {
                return;
            }

            HatchPolyLine(oid);
        }

        public static void HatchPolyLine(ObjectId plineId)
        {
            try
            {
                if (plineId.IsNull)
                    throw new ArgumentNullException("plineId");

                if (plineId.ObjectClass != RXObject.GetClass(typeof(Polyline)))
                    throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.IllegalEntityType);

                var ids = new ObjectIdCollection();
                ids.Add(plineId);

                using (var tr = plineId.Database.TransactionManager.StartTransaction())
                {
                    var pline = (Polyline)tr.GetObject(plineId, OpenMode.ForWrite);
                    if (!(pline.Closed || pline.GetPoint2dAt(0).IsEqualTo(pline.GetPoint2dAt(pline.NumberOfVertices - 1))))
                        throw new InvalidOperationException("Opened polyline.");

                    var owner = (BlockTableRecord)tr.GetObject(pline.OwnerId, OpenMode.ForWrite);
                    var hatch = new Hatch();
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                    owner.AppendEntity(hatch);
                    tr.AddNewlyCreatedDBObject(hatch, true);
                    hatch.Associative = true;
                    hatch.AppendLoop(HatchLoopTypes.Default, ids);
                    hatch.EvaluateHatch(true);
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                var ed = Application.DocumentManager.MdiActiveDocument.Editor;
                ed.WriteMessage($"{ex.Message}\n{ex.StackTrace}");
            }
        }&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 May 2023 12:06:54 GMT</pubDate>
    <dc:creator>wesbird</dc:creator>
    <dc:date>2023-05-09T12:06:54Z</dc:date>
    <item>
      <title>Hatch does not work</title>
      <link>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11949536#M8902</link>
      <description>&lt;P&gt;hi:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have code to hatch 100+ LWPOLYLINE, for some reason, some of them not working. I check the code, I got error message of&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;eInvalidInput&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;at line of&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;oHatch.AppendLoop(HatchLoopTypes.Default, ObjIds);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I already tried&amp;nbsp;HatchLoopTypes.External, same result.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;for testing, I create a function: pick the pline, then call the function, got the same error.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if I manually pick the same pline, use AutoCAD HATCH command, it works. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;what's could be wrong?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I really appreciate your help. &lt;/SPAN&gt;&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;&lt;P&gt;&amp;nbsp;&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;&lt;LI-CODE lang="csharp"&gt;private static Entity DrawHatch(Entity ent, Color color)
        {
            string HatchPattern = "SOLID";
            Transparency HatchTransparency = new Transparency(255);
            ObjectIdCollection ObjIds = new ObjectIdCollection();
            ObjIds.Add(ent.ObjectId);

            try
            {
                ent.UpgradeOpen();

                Hatch oHatch = new Hatch();

                oHatch.SetDatabaseDefaults();

                oHatch.SetHatchPattern(HatchPatternType.PreDefined, HatchPattern);

                // color
                oHatch.Color = color;

                // transparency 
                oHatch.Transparency = HatchTransparency;

                // Outermost
                oHatch.AppendLoop(HatchLoopTypes.Default, ObjIds);

                // evaluate hatch 
                oHatch.EvaluateHatch(true);

                return oHatch;
            }
            catch (Exception caught)
            {
                BPLog.Fatal($"ent={ent.Handle}", caught);
                return null;
            }
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 08 May 2023 16:57:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11949536#M8902</guid>
      <dc:creator>wesbird</dc:creator>
      <dc:date>2023-05-08T16:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch does not work</title>
      <link>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11950440#M8903</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/50921"&gt;@wesbird&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi there, you need to append to block table record before editing the properties of the hatch.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please refer:&amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/net/autocad-net-creating-hatch-from-polyline/td-p/8181662" target="_blank"&gt;Solved: AutoCAD .NET - Creating hatch from polyline - Autodesk Community - AutoCAD&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 01:39:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11950440#M8903</guid>
      <dc:creator>hng_kaijianG7MAN</dc:creator>
      <dc:date>2023-05-09T01:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch does not work</title>
      <link>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11951418#M8904</link>
      <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13886117"&gt;@hng_kaijianG7MAN&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, my code is not complete. I do have code for&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;appending to block table record&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;also, I tested with this code from gile.&amp;nbsp; still the same error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just don't understand, why the same code work for some pline but not the other, why the same pline code not working but HATCH command works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the test pline with problem does not have issue like open, self intersect.&amp;nbsp;&lt;/P&gt;&lt;P&gt;here code from gile&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;[CommandMethod("JGC.UI.Test", nameof(JGCTest_Hatch2), CommandFlags.Modal)]
        public static void JGCTest_Hatch2()
        {
            var oid = JTISelect.GetEntityX&amp;lt;Polyline&amp;gt;("\nPick a polyline:", "");
            if (oid.IsNull)
            {
                return;
            }

            HatchPolyLine(oid);
        }

        public static void HatchPolyLine(ObjectId plineId)
        {
            try
            {
                if (plineId.IsNull)
                    throw new ArgumentNullException("plineId");

                if (plineId.ObjectClass != RXObject.GetClass(typeof(Polyline)))
                    throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.IllegalEntityType);

                var ids = new ObjectIdCollection();
                ids.Add(plineId);

                using (var tr = plineId.Database.TransactionManager.StartTransaction())
                {
                    var pline = (Polyline)tr.GetObject(plineId, OpenMode.ForWrite);
                    if (!(pline.Closed || pline.GetPoint2dAt(0).IsEqualTo(pline.GetPoint2dAt(pline.NumberOfVertices - 1))))
                        throw new InvalidOperationException("Opened polyline.");

                    var owner = (BlockTableRecord)tr.GetObject(pline.OwnerId, OpenMode.ForWrite);
                    var hatch = new Hatch();
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                    owner.AppendEntity(hatch);
                    tr.AddNewlyCreatedDBObject(hatch, true);
                    hatch.Associative = true;
                    hatch.AppendLoop(HatchLoopTypes.Default, ids);
                    hatch.EvaluateHatch(true);
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                var ed = Application.DocumentManager.MdiActiveDocument.Editor;
                ed.WriteMessage($"{ex.Message}\n{ex.StackTrace}");
            }
        }&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 12:06:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11951418#M8904</guid>
      <dc:creator>wesbird</dc:creator>
      <dc:date>2023-05-09T12:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch does not work</title>
      <link>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11951461#M8905</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Is the selected pline correctly closed?&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 12:19:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11951461#M8905</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-05-09T12:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch does not work</title>
      <link>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11951507#M8906</link>
      <description>&lt;P&gt;Thank you, gile,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, it's closed. and HATCH command works just fine.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 12:43:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11951507#M8906</guid>
      <dc:creator>wesbird</dc:creator>
      <dc:date>2023-05-11T12:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Hatch does not work</title>
      <link>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11971924#M8907</link>
      <description>&lt;P&gt;Most probably your entity is not closed entity. if you draw circle and fill it with hatch it won't show such error but if you do the same with line, it will cause&amp;nbsp;&lt;SPAN&gt;eInvalidInput error at AppendLoop()&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 05:16:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/hatch-does-not-work/m-p/11971924#M8907</guid>
      <dc:creator>shubhamraut221195</dc:creator>
      <dc:date>2023-05-18T05:16:52Z</dc:date>
    </item>
  </channel>
</rss>

