<?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: How to hatch newly created objects in block using C# in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/12554496#M21244</link>
    <description>&lt;P&gt;hi&lt;BR /&gt;that's not work for me!&lt;/P&gt;&lt;P&gt;i want to create block with hatch, i can create entities but when i want to hatch the created entity error happens in this line:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;hatch.AppendLoop(HatchLoopTypes.Default, ids);&lt;/LI-CODE&gt;&lt;P&gt;the error message is "eInvalidInput"&lt;/P&gt;</description>
    <pubDate>Mon, 12 Feb 2024 07:38:29 GMT</pubDate>
    <dc:creator>ehsan_bahrani</dc:creator>
    <dc:date>2024-02-12T07:38:29Z</dc:date>
    <item>
      <title>How to hatch newly created objects in block using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9032765#M21237</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I am new in .net customization of Autocad and I'm apologize if there is some similar post like mine, but so far I didn't found any solution for the problem. Here is the situation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create block using c# , inside the block I create few Entities (closed polyline with circle inside) and I want to hatch the circle. For hatching I use trace boundary, but there I met my first problem - the Entity is not in database, so returned object ID collection is 0. I try different ways to get traced obj. ID's, but without success. I try to zoom to object ID, which i get before committing the transaction and trace it after zooming, but I get same result. Does anyone can help me with this? Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2019 14:57:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9032765#M21237</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-09-18T14:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to hatch newly created objects in block using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9037437#M21238</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming you want to hatch a known entity (the circle) you do not need to use the TraceBoundary, you directly use the circle ObjectId to define the Hatch loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        private static ObjectId CreateBlockWithHatch(Database db, string blockName)
        {
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord block;
                if (bt.Has(blockName)) return bt[blockName];

                tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
                block = new BlockTableRecord();
                block.Name = blockName;
                var blockId = bt.Add(block);
                tr.AddNewlyCreatedDBObject(block, true);

                var pline = new Polyline(4) { Closed = true, Layer = "0" };
                pline.Layer = "0";
                pline.AddVertexAt(0, new Point2d(-12.0, -12.0), 0.0, 0.0, 0.0);
                pline.AddVertexAt(0, new Point2d(12.0, -12.0), 0.0, 0.0, 0.0);
                pline.AddVertexAt(0, new Point2d(12.0, 12.0), 0.0, 0.0, 0.0);
                pline.AddVertexAt(0, new Point2d(-12.0, 12.0), 0.0, 0.0, 0.0);
                block.AppendEntity(pline);
                tr.AddNewlyCreatedDBObject(pline, true);

                var circle = new Circle() { Center = Point3d.Origin, Radius = 8.0, Layer = "0" };
                block.AppendEntity(circle);
                tr.AddNewlyCreatedDBObject(circle, true);
                var ids = new ObjectIdCollection(new[] { circle.ObjectId });

                var hatch = new Hatch() { Layer = "0", PatternScale = 0.5, ColorIndex = 1 };
                hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
                block.AppendEntity(hatch);
                tr.AddNewlyCreatedDBObject(hatch, true);
                hatch.Associative = true;
                hatch.AppendLoop(HatchLoopTypes.Default, ids);
                hatch.EvaluateHatch(true);

                tr.Commit();
                return blockId;
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Sep 2019 14:27:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9037437#M21238</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-09-20T14:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to hatch newly created objects in block using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9037919#M21239</link>
      <description>&lt;P&gt;Thanks for your answer _gilie,&lt;/P&gt;&lt;P&gt;but that's not exactly the case, which I met. That will work, because in the code above we know object ID(i mean we can get it), but If we didn't&amp;nbsp; know which object are in use for hatch definition , we won't be able to get them ID's, so I found that the method, which should work for me, will be TraceBoundaty , and it will, but the problem, is to get those object ID's to use them.&amp;nbsp; In&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; hatch.AppendLoop(HatchLoopTypes.Default, ids);&lt;/PRE&gt;&lt;P&gt;where in your code you use&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var ids = new ObjectIdCollection(new[] { circle.ObjectId });&lt;/PRE&gt;&lt;P&gt;to get circle ID. Let say it otherwise I want to select an objects from the drawing and a point inside the objects to hatch. Then the program should create a block using the selected entities from the user and also the hatch based on the selected point , this is why I need to use TraceBoudary&amp;nbsp; . Where am I go wrong here, i am thinking that i miss something about editor details, any ideas how to solve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2019 19:12:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9037919#M21239</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-09-20T19:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to hatch newly created objects in block using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9038031#M21240</link>
      <description>&lt;P&gt;This is not what you said in the original post:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous&amp;nbsp;wrote:&lt;BR /&gt;I am trying to create block using c# , inside the block I create few Entities (closed polyline with circle inside) and I want to hatch the circle.&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2019 20:33:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9038031#M21240</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-09-20T20:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to hatch newly created objects in block using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9038368#M21241</link>
      <description>&lt;P&gt;Apologize, my mistake. I forgot that, if I need some information in programming I should be precise to receive best fit solution. Can you give some advice where to look for potential solution, that's became very hard task. Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2019 07:41:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9038368#M21241</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-09-21T07:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to hatch newly created objects in block using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9038729#M21242</link>
      <description>&lt;P&gt;Regardless what your use case is, be it hatching newly created entity in block, or whatever, the actual issue is that if you want to create a hatch, you CAN ONLY append HtachLoops with one or more entities (typically curves) that is database-residing, as ObjectIdCollection.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use Editor.TraceBoundary() method to detect a boundary, this method, if successful, return a one or more DBObjects (Entities) in DBObjectCollection. They ARE NOT db-residing objects, thus their ObjectId is ObjectId.Null. It is up to the calling process to decide what to do with the returned non-db-residing objects. You can add then into the database first, and then use them to create HatchLopp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you have some entities created already (a circle, in your case), but for some very odd reasons you know know it is there created by your code, and you know you want to use it to hatch it, but you have no way to get its ObjectId, therefore you have to use TraceBoundary() to find out the possible loop as boundary.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do have a known point and want to find if it is inside a single closed curve (so you can use that closed curve to hatch), it might be much easier to test each curve in the drawing to see if the point is inside. If the curve is circle, it is even simple: you simply loop through all circles to see if the distance form the point to circle's center is equal or less than the radius.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for whatever reasons if you must or can only use TraceBoundary() to find the boundary, but only want to do hatch with existing entity, then you need to compare the returned non-db-residing entities with existing entities in drawing geometrically to find the exact corresponding existing entities for creating hatch (and you will dispose all the DBObjects returned by TraceBoundary() after the comparison is done). IMO, it only makes sense to use TraceBoundary() to get outmost loop for hatch WHEN the area to be hatched is formed by multiple entities.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your particular case, if the test point used in TraceBoundary() is inside a circle, the returned DBCollection would only have one DBObject, which should be a circle with exact same center/radius as the existing circle. So, you can use the non-db-residing circle's center/radius to search the drawing for the "real circle", and then do the hatch.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The real issue here is, you must know that 1). TraceBoundary() returns a set of non-database-residing objects, and you decide how to use them (adding to DB, or using their geometric info then disposing them); 2). curve(s) for hatchloop must be db-residing objects.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2019 16:18:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9038729#M21242</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2019-09-21T16:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to hatch newly created objects in block using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9039433#M21243</link>
      <description>&lt;P&gt;&lt;SPAN class="login-bold"&gt;norman.yuan, thanks for your reply about my case. It doesn't truly solve the problem, but at least it gives me a view about how trace boundary works, to be honest if it wasn't your explanation I couldn't be able to solve it. I had to inverse my method, first to create block and also objects in database, then to trace boundary around the given point, then create hatch with ObjectIDCollection , returned from trace boundary. Trough each method I collect ObjectId s or each newly created object, which are stored in additional ObjectIdCollection.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="login-bold"&gt;Finally I add objectID.clone() to the created block and delete the original object from database, there is only one thing left to do - I need to regenerate the editor and its done &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Sep 2019 16:33:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/9039433#M21243</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-09-22T16:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to hatch newly created objects in block using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/12554496#M21244</link>
      <description>&lt;P&gt;hi&lt;BR /&gt;that's not work for me!&lt;/P&gt;&lt;P&gt;i want to create block with hatch, i can create entities but when i want to hatch the created entity error happens in this line:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;hatch.AppendLoop(HatchLoopTypes.Default, ids);&lt;/LI-CODE&gt;&lt;P&gt;the error message is "eInvalidInput"&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 07:38:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/12554496#M21244</guid>
      <dc:creator>ehsan_bahrani</dc:creator>
      <dc:date>2024-02-12T07:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to hatch newly created objects in block using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/12554509#M21245</link>
      <description>i found the reason&amp;amp; i have to use 'AddNewlyCreatedDBObject' first and then do hatch stuff.</description>
      <pubDate>Mon, 12 Feb 2024 07:48:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-hatch-newly-created-objects-in-block-using-c/m-p/12554509#M21245</guid>
      <dc:creator>ehsan_bahrani</dc:creator>
      <dc:date>2024-02-12T07:48:03Z</dc:date>
    </item>
  </channel>
</rss>

