Dynamic block count - Using Visibility

Dynamic block count - Using Visibility

Anonymous
Not applicable
455 Views
0 Replies
Message 1 of 1

Dynamic block count - Using Visibility

Anonymous
Not applicable

Hello,

 

I'm trying count my dynamic block's using C# and .net but so far I can't seem to figure how to do it.

 

With this code :

 

 [CommandMethod("DBP")]
        static public void DynamicBlockProps()
        {
            Document doc =
              Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            PromptStringOptions pso =
              new PromptStringOptions(
                "\nEnter dynamic block name or enter to select: "
              );

            pso.AllowSpaces = true;
            PromptResult pr = ed.GetString(pso);

            if (pr.Status != PromptStatus.OK)
                return;

            Transaction tr =
              db.TransactionManager.StartTransaction();
            using (tr)
            {
                BlockReference br = null;

                // If a null string was entered allow entity selection

                if (pr.StringResult == "")
                {
                    // Select a block reference

                    PromptEntityOptions peo =
                      new PromptEntityOptions(
                        "\nSelect dynamic block reference: "
                      );

                    peo.SetRejectMessage("\nEntity is not a block.");
                    peo.AddAllowedClass(typeof(BlockReference), false);

                    PromptEntityResult per =
                      ed.GetEntity(peo);

                    if (per.Status != PromptStatus.OK)
                        return;

                    // Access the selected block reference

                    br =
                      tr.GetObject(
                        per.ObjectId,
                        OpenMode.ForRead
                      ) as BlockReference;
                }
                else
                {
                    // Otherwise we look up the block by name

                    BlockTable bt =
                      tr.GetObject(
                        db.BlockTableId,
                        OpenMode.ForRead) as BlockTable;

                    if (!bt.Has(pr.StringResult))
                    {
                        ed.WriteMessage(
                          "\nBlock \"" + pr.StringResult + "\" does not exist."
                        );
                        return;
                    }

                    // Create a new block reference referring to the block

                    br =
                      new BlockReference(
                        new Point3d(),
                        bt[pr.StringResult]
                      );
                }

                BlockTableRecord btr =
                  (BlockTableRecord)tr.GetObject(
                    br.DynamicBlockTableRecord,
                    OpenMode.ForRead
                  );

                // Call our function to display the block properties

                DisplayDynBlockProperties(ed, br, btr.Name);

                // Committing is cheaper than aborting

                tr.Commit();
            }
        }

        private static void DisplayDynBlockProperties(
          Editor ed, BlockReference br, string name
        )
        {
            // Only continue is we have a valid dynamic block

            if (br != null && br.IsDynamicBlock)
            {
                ed.WriteMessage(
                  "\nDynamic properties for \"{0}\"\n",
                  name
                );

                // Get the dynamic block's property collection
                


                DynamicBlockReferencePropertyCollection pc =
                  br.DynamicBlockReferencePropertyCollection;

                

                // Loop through, getting the info for each property

                foreach (DynamicBlockReferenceProperty prop in pc)
                {
                    // Start with the property name, type and description
                    List<string> activeVisibility = new List<string>();
                    
                    if(prop.PropertyName == "Choisir")
                    {                        
                        ed.WriteMessage("\nProperty Type Code : " + prop.PropertyTypeCode.ToString());
                        ed.WriteMessage("\nProperty Value : " + prop.Value.ToString());
                        ed.WriteMessage("\nProperty UnitsType : " + prop.UnitsType.ToString());                        
                    }     
                }
            }
        }

The code was found on DevBlog.

 

I can get to the properties, but the position of properties change from block to block.

 

What I would like it either get the Visibilty or the right lookup.

 

 

Anyone have suggestions for me?

 

regards, Frank

0 Likes
456 Views
0 Replies
Replies (0)