<?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: My Polyline Hatch code has terrible error and does not work. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11371121#M11956</link>
    <description>&lt;P&gt;and very generous !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 20 Aug 2022 22:52:24 GMT</pubDate>
    <dc:creator>kerry_w_brown</dc:creator>
    <dc:date>2022-08-20T22:52:24Z</dc:date>
    <item>
      <title>My Polyline Hatch code has terrible error and does not work.</title>
      <link>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11370318#M11951</link>
      <description>&lt;P&gt;Hello all the thankful persons.&lt;/P&gt;&lt;P&gt;Now I am making polyline hatch application but it does not work and error.&lt;/P&gt;&lt;P&gt;I am stunned because of this problem.&lt;/P&gt;&lt;P&gt;Followings are my error image and code.&lt;/P&gt;&lt;P&gt;I hope someone can help me. Thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="errorimage.jpg" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1106029i10DBD9073EEB0DC3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="errorimage.jpg" alt="errorimage.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;LI-CODE lang="general"&gt;public static void Hatch()
        {
            var documentManager = Application.DocumentManager;
            var currentDocument = documentManager.MdiActiveDocument;
            var db = currentDocument.Database;
            var ed = currentDocument.Editor;
            using (var tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                var blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                foreach (ObjectId btrId in blockTable)
                {
                    var btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForWrite);
                    var PlineCls = RXObject.GetClass(typeof(Polyline));
                    if (btr.IsLayout)
                    {
                        
                        foreach (ObjectId id in btr)
                        {
                            if (id.ObjectClass == PlineCls)
                            {
                                var pline = (Polyline)tr.GetObject(id, OpenMode.ForRead);
                                string curlay = pline.Layer;
                                if (IsreqHatch(curlay) == true)
                                {
                                    ObjectIdCollection acObjIdColl = new ObjectIdCollection();
                                    acObjIdColl.Add(pline.ObjectId);
                                    Hatch acHatch = new Hatch();
                                    btr.AppendEntity(acHatch);
                                    tr.AddNewlyCreatedDBObject(acHatch, true);
                                    acHatch.SetDatabaseDefaults();
                                    acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
                                    acHatch.Associative = true;
                                    acHatch.HatchStyle = HatchStyle.Ignore;

                                    acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
                                    acHatch.EvaluateHatch(true);
                                }
                            }
                        }                        
                    }
                }
                tr.Commit();
            }
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 20 Aug 2022 06:21:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11370318#M11951</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-20T06:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: My Polyline Hatch code has terrible error and does not work.</title>
      <link>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11370542#M11952</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You have to set the hatch pattern before adding it to the Database.&lt;/P&gt;
&lt;P&gt;One more time, build a little method to hatch a single polyline so that you can test-it and debug it by selection a single polyline with a simple test command instead of running your method which iterates through each entity of each layout.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        private static void HacthPolyline(Polyline pline, BlockTableRecord btr, Transaction tr)
        {
            var ids = new ObjectIdCollection();
            ids.Add(pline.Id);
            var hatch = new Hatch { Layer = pline.Layer };
            hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
            btr.AppendEntity(hatch);
            tr.AddNewlyCreatedDBObject(hatch, true);
            hatch.Associative = true;
            hatch.AppendLoop(HatchLoopTypes.Default, ids);
            hatch.EvaluateHatch(true);
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And, when you're satified with this method, you can integrate it into your main method:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        public static void Hatch()
        {
            var documentManager = Application.DocumentManager;
            var currentDocument = documentManager.MdiActiveDocument;
            var db = currentDocument.Database;
            using (var tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                var blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                var PlineCls = RXObject.GetClass(typeof(Polyline));
                foreach (ObjectId btrId in blockTable)
                {
                    var btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForWrite);
                    if (btr.IsLayout)
                    {
                        foreach (ObjectId id in btr)
                        {
                            if (id.ObjectClass == PlineCls)
                            {
                                var pline = (Polyline)tr.GetObject(id, OpenMode.ForRead);
                                if (IsreqHatch(pline.Layer))
                                    HacthPolyline(pline, btr, tr);
                            }
                        }
                    }
                }
                tr.Commit();
            }
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 20 Aug 2022 12:01:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11370542#M11952</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-08-20T12:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: My Polyline Hatch code has terrible error and does not work.</title>
      <link>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11370572#M11953</link>
      <description>well done. Thanks, gile. but is it possible to manage spacing?</description>
      <pubDate>Sat, 20 Aug 2022 12:24:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11370572#M11953</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-20T12:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: My Polyline Hatch code has terrible error and does not work.</title>
      <link>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11370582#M11954</link>
      <description>&lt;P&gt;You can set the Hatch poperties when you create the new instance:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;var hatch = new Hatch { Layer = pline.Layer, PatternScale = 2.0 };&lt;/LI-CODE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;var hatch = new Hatch();
hatch.Layer = pline.Layer;
hatch.PatternScale = 2.0;&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 20 Aug 2022 12:38:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11370582#M11954</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-08-20T12:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: My Polyline Hatch code has terrible error and does not work.</title>
      <link>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11370618#M11955</link>
      <description>You are very very talented person.</description>
      <pubDate>Sat, 20 Aug 2022 13:29:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11370618#M11955</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-20T13:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: My Polyline Hatch code has terrible error and does not work.</title>
      <link>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11371121#M11956</link>
      <description>&lt;P&gt;and very generous !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2022 22:52:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11371121#M11956</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2022-08-20T22:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: My Polyline Hatch code has terrible error and does not work.</title>
      <link>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11377583#M11957</link>
      <description>&lt;P&gt;Hi, _gile. I am currently getting this error.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="goldhorsemillion_0-1661392737227.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1107374iAE4E25A322D2DE1D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="goldhorsemillion_0-1661392737227.png" alt="goldhorsemillion_0-1661392737227.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;could you tell me why this error occurs?&lt;/P&gt;&lt;P&gt;I hope your answer.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 09:27:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11377583#M11957</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-24T09:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: My Polyline Hatch code has terrible error and does not work.</title>
      <link>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11378587#M11958</link>
      <description>&lt;P&gt;What if you try to hatch this polyline with the native command ?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 15:27:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/my-polyline-hatch-code-has-terrible-error-and-does-not-work/m-p/11378587#M11958</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-08-24T15:27:22Z</dc:date>
    </item>
  </channel>
</rss>

