乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 116|回复: 0

[编程交流] 动态块可见性属性

[复制链接]

56

主题

259

帖子

213

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
270
发表于 2022-7-6 21:51:18 | 显示全部楼层 |阅读模式
嗨,我想知道如何使用C访问VisibilityState#
 
这是我在谷歌搜索中找到的代码:
 
  1. [CommandMethod("DBP")]
  2.        static public void DynamicBlockProps()
  3.        {
  4.            Document doc =
  5.              Application.DocumentManager.MdiActiveDocument;
  6.            Database db = doc.Database;
  7.            Editor ed = doc.Editor;
  8.            PromptStringOptions pso =
  9.              new PromptStringOptions(
  10.                "\nEnter dynamic block name or enter to select: "
  11.              );
  12.            pso.AllowSpaces = true;
  13.            PromptResult pr = ed.GetString(pso);
  14.            if (pr.Status != PromptStatus.OK)
  15.                return;
  16.            Transaction tr =
  17.              db.TransactionManager.StartTransaction();
  18.            using (tr)
  19.            {
  20.                BlockReference br = null;
  21.                // If a null string was entered allow entity selection
  22.                if (pr.StringResult == "")
  23.                {
  24.                    // Select a block reference
  25.                    PromptEntityOptions peo =
  26.                      new PromptEntityOptions(
  27.                        "\nSelect dynamic block reference: "
  28.                      );
  29.                    peo.SetRejectMessage("\nEntity is not a block.");
  30.                    peo.AddAllowedClass(typeof(BlockReference), false);
  31.                    PromptEntityResult per =
  32.                      ed.GetEntity(peo);
  33.                    if (per.Status != PromptStatus.OK)
  34.                        return;
  35.                    // Access the selected block reference
  36.                    br =
  37.                      tr.GetObject(
  38.                        per.ObjectId,
  39.                        OpenMode.ForRead
  40.                      ) as BlockReference;
  41.                }
  42.                else
  43.                {
  44.                    // Otherwise we look up the block by name
  45.                    BlockTable bt =
  46.                      tr.GetObject(
  47.                        db.BlockTableId,
  48.                        OpenMode.ForRead) as BlockTable;
  49.                    if (!bt.Has(pr.StringResult))
  50.                    {
  51.                        ed.WriteMessage(
  52.                          "\nBlock "" + pr.StringResult + "" does not exist."
  53.                        );
  54.                        return;
  55.                    }
  56.                    // Create a new block reference referring to the block
  57.                    br =
  58.                      new BlockReference(
  59.                        new Point3d(),
  60.                        bt[pr.StringResult]
  61.                      );
  62.                }
  63.                BlockTableRecord btr =
  64.                  (BlockTableRecord)tr.GetObject(
  65.                    br.DynamicBlockTableRecord,
  66.                    OpenMode.ForRead
  67.                  );
  68.                // Call our function to display the block properties
  69.                DisplayDynBlockProperties(ed, br, btr.Name);
  70.                // Committing is cheaper than aborting
  71.                tr.Commit();
  72.            }
  73.        }
  74.        private static void DisplayDynBlockProperties(
  75.          Editor ed, BlockReference br, string name
  76.        )
  77.        {
  78.            // Only continue is we have a valid dynamic block
  79.            if (br != null && br.IsDynamicBlock)
  80.            {
  81.                ed.WriteMessage(
  82.                  "\nDynamic properties for "{0}"\n",
  83.                  name
  84.                );
  85.                // Get the dynamic block's property collection
  86.                
  87.                DynamicBlockReferencePropertyCollection pc =
  88.                  br.DynamicBlockReferencePropertyCollection;
  89.                
  90.                // Loop through, getting the info for each property
  91.                foreach (DynamicBlockReferenceProperty prop in pc)
  92.                {
  93.                    // Start with the property name, type and description
  94.                    List<string> activeVisibility = new List<string>();
  95.                   
  96.                    if(prop.PropertyName == "Choisir")
  97.                    {                        
  98.                        ed.WriteMessage("\nProperty Type Code : " + prop.PropertyTypeCode.ToString());
  99.                        ed.WriteMessage("\nProperty Value : " + prop.Value.ToString());
  100.                        ed.WriteMessage("\nProperty UnitsType : " + prop.UnitsType.ToString());                        
  101.                    }     
  102.                }
  103.            }
  104.        }

 
问题是可见性状态的位置因不同的块而变化。
 
有人有建议帮我吗?
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 12:46 , Processed in 0.577534 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表