<?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 Plug-in Autocad C# How to check a block object is a object of class defined by user in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/plug-in-autocad-c-how-to-check-a-block-object-is-a-object-of/m-p/10302156#M16492</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have some codes to test block objects as below code.&lt;/P&gt;&lt;P&gt;With:&lt;/P&gt;&lt;P&gt;Command "CircleCall" to create circle blocks (from class "BlockCircle")&lt;/P&gt;&lt;P&gt;Command "CircleTest" to test block object which created by "CircleCall" is from class "BlockCircle"&lt;/P&gt;&lt;P&gt;My problem is command "CircleTest" not work as wishes.&lt;/P&gt;&lt;P&gt;Can anyone help me!&lt;/P&gt;&lt;P&gt;Many thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;        [CommandMethod("CircleCall")]
        public void cmd_CircleCall()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;            
            var ed = doc.Editor;

            var ppo = new PromptPointOptions("\nPlease select point");
            var poi = ed.GetPoint(ppo).Value;

            var blockCircle = new BlockCircle();
            blockCircle.BlCircle(poi, 4);
        }

        [CommandMethod("CircleTest")]
        public void cmd_CircleTest()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            using (Transaction trx = db.TransactionManager.StartTransaction())
            {
                PromptEntityOptions peo = new PromptEntityOptions("\nPlease select block object");
                peo.SetRejectMessage("Not a Block");
                peo.AddAllowedClass(typeof(BlockReference), true);
                PromptEntityResult per = ed.GetEntity(peo);

                if (per.Status != PromptStatus.OK)
                {
                    return;
                }

                BlockReference bref = trx.GetObject(per.ObjectId, OpenMode.ForRead) as BlockReference;
                BlockTableRecord btr = (BlockTableRecord)trx.GetObject(bref.BlockTableRecord, OpenMode.ForRead);
                               

                if (bref is BlockCircle)
                    ed.WriteMessage("\nBlock object is Blockcircle");
                else
                    ed.WriteMessage("\nBlock object is not Blockcircle");

                trx.Commit();
            }
        }

public class BlockCircle
        {
            public string Name;
            public Point3d Basepoint;
            public void BlCircle(Point3d p,double radius)
            {
                var db = HostApplicationServices.WorkingDatabase;
                this.Basepoint = p;

                using (var tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable bltb = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                    var modelspace = (BlockTableRecord)tr.GetObject(bltb[BlockTableRecord.ModelSpace], OpenMode.ForRead);
                    var maxIndex = 0;

                    foreach(ObjectId id in modelspace)
                    {
                        if (id.ObjectClass.DxfName == "INSERT")
                        {
                            var blockref = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                            
                            if (blockref.Name.StartsWith ("Circleblock."))
                            {                                
                                int num = blockref.Name.IndexOf(".");
                                var curIndex = int.Parse(blockref.Name.Substring(num+1));
                                if (curIndex &amp;gt; maxIndex)
                                    maxIndex = curIndex;                                
                            }
                        }
                    }

                    var bltbrc = new BlockTableRecord();
                    bltbrc.Name = "Circleblock."+(maxIndex+1).ToString();
                    this.Name = bltbrc.Name;

                    if (!bltb.Has(bltbrc.Name))
                    {
                        bltbrc.Origin = new Point3d(0, 0, 0);

                        using (Circle dt = new Circle())
                        {
                            dt.Center = new Point3d(0, 0, 0);
                            dt.Radius = radius;

                            bltbrc.AppendEntity(dt);
                            tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
                            bltb.Add(bltbrc);
                            tr.AddNewlyCreatedDBObject(bltbrc, true);
                        }
                    }                    

                    MyPlugin k = new MyPlugin();
                    k.InsertBlockwithRotation(p,bltbrc.Name,0);

                    tr.Commit();
                }
            }
        }

public void InsertBlockwithRotation(Point3d insPt, string blockName, double beta){...}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 May 2021 09:31:53 GMT</pubDate>
    <dc:creator>KinAkira</dc:creator>
    <dc:date>2021-05-10T09:31:53Z</dc:date>
    <item>
      <title>Plug-in Autocad C# How to check a block object is a object of class defined by user</title>
      <link>https://forums.autodesk.com/t5/net-forum/plug-in-autocad-c-how-to-check-a-block-object-is-a-object-of/m-p/10302156#M16492</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have some codes to test block objects as below code.&lt;/P&gt;&lt;P&gt;With:&lt;/P&gt;&lt;P&gt;Command "CircleCall" to create circle blocks (from class "BlockCircle")&lt;/P&gt;&lt;P&gt;Command "CircleTest" to test block object which created by "CircleCall" is from class "BlockCircle"&lt;/P&gt;&lt;P&gt;My problem is command "CircleTest" not work as wishes.&lt;/P&gt;&lt;P&gt;Can anyone help me!&lt;/P&gt;&lt;P&gt;Many thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;        [CommandMethod("CircleCall")]
        public void cmd_CircleCall()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;            
            var ed = doc.Editor;

            var ppo = new PromptPointOptions("\nPlease select point");
            var poi = ed.GetPoint(ppo).Value;

            var blockCircle = new BlockCircle();
            blockCircle.BlCircle(poi, 4);
        }

        [CommandMethod("CircleTest")]
        public void cmd_CircleTest()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            using (Transaction trx = db.TransactionManager.StartTransaction())
            {
                PromptEntityOptions peo = new PromptEntityOptions("\nPlease select block object");
                peo.SetRejectMessage("Not a Block");
                peo.AddAllowedClass(typeof(BlockReference), true);
                PromptEntityResult per = ed.GetEntity(peo);

                if (per.Status != PromptStatus.OK)
                {
                    return;
                }

                BlockReference bref = trx.GetObject(per.ObjectId, OpenMode.ForRead) as BlockReference;
                BlockTableRecord btr = (BlockTableRecord)trx.GetObject(bref.BlockTableRecord, OpenMode.ForRead);
                               

                if (bref is BlockCircle)
                    ed.WriteMessage("\nBlock object is Blockcircle");
                else
                    ed.WriteMessage("\nBlock object is not Blockcircle");

                trx.Commit();
            }
        }

public class BlockCircle
        {
            public string Name;
            public Point3d Basepoint;
            public void BlCircle(Point3d p,double radius)
            {
                var db = HostApplicationServices.WorkingDatabase;
                this.Basepoint = p;

                using (var tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable bltb = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                    var modelspace = (BlockTableRecord)tr.GetObject(bltb[BlockTableRecord.ModelSpace], OpenMode.ForRead);
                    var maxIndex = 0;

                    foreach(ObjectId id in modelspace)
                    {
                        if (id.ObjectClass.DxfName == "INSERT")
                        {
                            var blockref = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
                            
                            if (blockref.Name.StartsWith ("Circleblock."))
                            {                                
                                int num = blockref.Name.IndexOf(".");
                                var curIndex = int.Parse(blockref.Name.Substring(num+1));
                                if (curIndex &amp;gt; maxIndex)
                                    maxIndex = curIndex;                                
                            }
                        }
                    }

                    var bltbrc = new BlockTableRecord();
                    bltbrc.Name = "Circleblock."+(maxIndex+1).ToString();
                    this.Name = bltbrc.Name;

                    if (!bltb.Has(bltbrc.Name))
                    {
                        bltbrc.Origin = new Point3d(0, 0, 0);

                        using (Circle dt = new Circle())
                        {
                            dt.Center = new Point3d(0, 0, 0);
                            dt.Radius = radius;

                            bltbrc.AppendEntity(dt);
                            tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
                            bltb.Add(bltbrc);
                            tr.AddNewlyCreatedDBObject(bltbrc, true);
                        }
                    }                    

                    MyPlugin k = new MyPlugin();
                    k.InsertBlockwithRotation(p,bltbrc.Name,0);

                    tr.Commit();
                }
            }
        }

public void InsertBlockwithRotation(Point3d insPt, string blockName, double beta){...}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 09:31:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plug-in-autocad-c-how-to-check-a-block-object-is-a-object-of/m-p/10302156#M16492</guid>
      <dc:creator>KinAkira</dc:creator>
      <dc:date>2021-05-10T09:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: Plug-in Autocad C# How to check a block object is a object of class defined by user</title>
      <link>https://forums.autodesk.com/t5/net-forum/plug-in-autocad-c-how-to-check-a-block-object-is-a-object-of/m-p/10302345#M16493</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-general"&gt;&lt;CODE&gt;bref is BlockCircle&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will always return false because the type of bref is BlockReference and there's no class or type relationship between BlockReference and BlockCircle. &lt;BR /&gt;Only you plugin knows what is the BlockCircle type.&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 11:17:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plug-in-autocad-c-how-to-check-a-block-object-is-a-object-of/m-p/10302345#M16493</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-05-10T11:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: Plug-in Autocad C# How to check a block object is a object of class defined by user</title>
      <link>https://forums.autodesk.com/t5/net-forum/plug-in-autocad-c-how-to-check-a-block-object-is-a-object-of/m-p/10302501#M16494</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thanks for your help,&lt;/P&gt;&lt;P&gt;Do you have anyway to resolve my problem ? Like "class line", when we have a entity and check type of it is line, we can access to its properties (ex: line.startpoint, line.endpoint,..). But my object class have to like block type (or group)&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 12:21:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plug-in-autocad-c-how-to-check-a-block-object-is-a-object-of/m-p/10302501#M16494</guid>
      <dc:creator>KinAkira</dc:creator>
      <dc:date>2021-05-10T12:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Plug-in Autocad C# How to check a block object is a object of class defined by user</title>
      <link>https://forums.autodesk.com/t5/net-forum/plug-in-autocad-c-how-to-check-a-block-object-is-a-object-of/m-p/10302986#M16495</link>
      <description>&lt;P&gt;I do not really understand what you want to achieve but you can have a constructor of the BlockCircle class which takes a block reference as argument or a a static method which also takes&amp;nbsp; a block reference as argument and retruns a BlockCircle instance.&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 15:39:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plug-in-autocad-c-how-to-check-a-block-object-is-a-object-of/m-p/10302986#M16495</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2021-05-10T15:39:30Z</dc:date>
    </item>
  </channel>
</rss>

