<?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: Looking for help in creating a Grip Overrule for a specific block in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11475293#M11457</link>
    <description>&lt;P&gt;It turns out it also works to check in IsApplicable() if the block is the correct type, which saves you from having to repeat yourself in your overriding multiple methods ie MoveGripPointAt(), GetGripPoints(), etc&lt;/P&gt;</description>
    <pubDate>Tue, 11 Oct 2022 14:59:20 GMT</pubDate>
    <dc:creator>nshupeFMPE3</dc:creator>
    <dc:date>2022-10-11T14:59:20Z</dc:date>
    <item>
      <title>Looking for help in creating a Grip Overrule for a specific block</title>
      <link>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11472949#M11451</link>
      <description>&lt;P&gt;I'm trying to create a grip overrule for a specific type of block and so far I have been running into issues of stack overflowing? I tried to follow &lt;A href="https://gist.github.com/beweir/83882a0bb28b80e97f2178d731671491" target="_blank" rel="noopener"&gt;this&lt;/A&gt; sort of templet while making some changes.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;This is what I have so far&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public override bool IsApplicable(RXObject overruledSubject)
        {
            try
            {
                
                if (overruledSubject.GetType() != typeof(BlockReference))
                    return false;
                BlockReference block = overruledSubject as BlockReference;
                return block.IsInstanceOf("Left stretch");//need to make more robust for any panel type

            }
            catch(Autodesk.AutoCAD.Runtime.Exception e)
            {
                return false;
            }
        }

        public override void GetGripPoints(Entity entity, GripDataCollection grips, double curViewUnitSize, int gripSize, Vector3d curViewDir, GetGripPointsFlags bitFlags)
        {
            try
            {
                base.GetGripPoints(entity, grips, curViewUnitSize, gripSize, curViewDir, bitFlags);
                GripDataCollection borderGrips = ComputeBorderGrips(entity);
                foreach(var t in borderGrips) grips.Add(t);
                
            }
            catch(Exception e)
            {
                base.GetGripPoints(entity, grips, curViewUnitSize, gripSize, curViewDir, bitFlags);
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I seem to get stuck in a loop at line 22 where I call base.GetGripPoints(). It then goes to IsApplicable() and loops until a stackoverflow occurs.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Any help would be greatly appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 14:15:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11472949#M11451</guid>
      <dc:creator>nshupeFMPE3</dc:creator>
      <dc:date>2022-10-10T14:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for help in creating a Grip Overrule for a specific block</title>
      <link>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11473082#M11452</link>
      <description>&lt;P&gt;You might want to show the code detail of the method&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BlockReference.IsInstanceOf(string)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other trick you might want to try is to place the IsInstanceOf(string) method call inside the overridden GetGripPoints(), assume IsInstanceOf() does its work correctly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        public override void GetGripPoints(Entity entity, GripDataCollection grips, double curViewUnitSize, int gripSize, Vector3d curViewDir, GetGripPointsFlags bitFlags)
        {
            try
            {
                var blk=entity as BlockReference;
                if (blk != null &amp;amp;&amp;amp; blk.IsInstanceOf("xxxxx))
                {
                  // Calculate and add your custom grip here
                }
            }
            finally
            {
                base.GetGripPoints(entity, grips, curViewUnitSize, gripSize, curViewDir, bitFlags);
            }
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 15:18:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11473082#M11452</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2022-10-10T15:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for help in creating a Grip Overrule for a specific block</title>
      <link>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11473090#M11453</link>
      <description>&lt;P&gt;I was thinking about moving the IsInstanceOf() call to inside GetGrips() but I figured I would like to rule out blocks as soon as possible if they are not an instance of the desired block.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Here is the code for IsInstanceOf()&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public static bool IsInstanceOf(this BlockReference block, string blockName)
        {
            bool answer = false;

            using(Transaction tr = block.Database.TransactionManager.StartOpenCloseTransaction())
            {
                ObjectId btrId = block.IsDynamicBlock ? block.DynamicBlockTableRecord : block.BlockTableRecord;
                var btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);
                answer = Autodesk.AutoCAD.Internal.Utils.WcMatchEx(btr.Name, blockName, true);
                btr.Dispose();
            }
            return answer;
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 15:21:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11473090#M11453</guid>
      <dc:creator>nshupeFMPE3</dc:creator>
      <dc:date>2022-10-10T15:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for help in creating a Grip Overrule for a specific block</title>
      <link>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11473199#M11454</link>
      <description>&lt;P&gt;I assume you did, but ask anyway: did you call Overrule.SetCustomFilter()?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just for the sake of debugging, can you simply make sure your drawing only has a static block reference and you can hard-code its name in the IsInstabceOf() to prove it absolutely works correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the GripOverrule, since it will only take effect when the overruled entity or entities is/are selected, I think, behind of the scene AutoCAD always call GetGripPoints() first and then, based on the overrule filter configuration, does the filtering work (e.g. call IsApplicable() if SetCustomFilter() was called when the overrule is enabled). So, for GripOverrule, I'd think, we can simply ignore the filtering stuff at Overrule level (e.g. not set up any kind of filter) and do our own filtering directly in the GetGripPoints() method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, at least for the purpose of debugging, you can try to remove filtering from Overrule level and do it directly in the GetGripPoints() as my previous reply suggested. See what happens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 16:23:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11473199#M11454</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2022-10-10T16:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for help in creating a Grip Overrule for a specific block</title>
      <link>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11473255#M11455</link>
      <description>I did do Overrule.SetCustomFilter() you are correct.&lt;BR /&gt;Thank you Norman, I will try your suggestion and report any change.</description>
      <pubDate>Mon, 10 Oct 2022 16:51:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11473255#M11455</guid>
      <dc:creator>nshupeFMPE3</dc:creator>
      <dc:date>2022-10-10T16:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for help in creating a Grip Overrule for a specific block</title>
      <link>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11473775#M11456</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;looks like I made a mistake and was adding the event handler for the overrule over and over again which I think was causing most my problems. I also moved the block InstanceOf() check like we discussed and I am getting what I was looking for!&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 22:36:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11473775#M11456</guid>
      <dc:creator>nshupeFMPE3</dc:creator>
      <dc:date>2022-10-10T22:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for help in creating a Grip Overrule for a specific block</title>
      <link>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11475293#M11457</link>
      <description>&lt;P&gt;It turns out it also works to check in IsApplicable() if the block is the correct type, which saves you from having to repeat yourself in your overriding multiple methods ie MoveGripPointAt(), GetGripPoints(), etc&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 14:59:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/looking-for-help-in-creating-a-grip-overrule-for-a-specific/m-p/11475293#M11457</guid>
      <dc:creator>nshupeFMPE3</dc:creator>
      <dc:date>2022-10-11T14:59:20Z</dc:date>
    </item>
  </channel>
</rss>

