乐筑天下

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

怎么通过选择来过滤动态块的线性参数?

[复制链接]

17

主题

32

帖子

8

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2020-3-1 10:18:00 | 显示全部楼层 |阅读模式
动态块内的线性参数想通过选择过滤后赋值,但是找不到过滤参数,请问动态块的线性参数怎么过滤?AddAllowedClass怎么过滤?
回复

使用道具 举报

11

主题

92

帖子

10

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
135
发表于 2020-3-4 21:19:00 | 显示全部楼层
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.DatabaseServices;
  3. using Autodesk.AutoCAD.EditorInput;
  4. using Autodesk.AutoCAD.Geometry;
  5. using Autodesk.AutoCAD.Runtime;
  6. namespace DYCS_20200302
  7. {
  8.     public class Commands
  9.     {
  10.         [CommandMethod("DBP")]
  11.         static public void DynamicBlockProps()
  12.         {
  13.             Document doc =
  14.               Application.DocumentManager.MdiActiveDocument;
  15.             Database db = doc.Database;
  16.             Editor ed = doc.Editor;
  17.             PromptStringOptions pso =
  18.               new PromptStringOptions(
  19.                 "\nEnter dynamic block name or enter to select: "
  20.               );
  21.             pso.AllowSpaces = true;
  22.             PromptResult pr = ed.GetString(pso);
  23.             if (pr.Status != PromptStatus.OK)
  24.                 return;
  25.             Transaction tr =
  26.               db.TransactionManager.StartTransaction();
  27.             using (tr)
  28.             {
  29.                 BlockReference br = null;
  30.                 // If a null string was entered allow entity selection
  31.                 if (pr.StringResult == "")
  32.                 {
  33.                     // Select a block reference
  34.                     PromptEntityOptions peo =
  35.                       new PromptEntityOptions(
  36.                         "\nSelect dynamic block reference: "
  37.                       );
  38.                     peo.SetRejectMessage("\nEntity is not a block.");
  39.                     peo.AddAllowedClass(typeof(BlockReference), false);
  40.                     PromptEntityResult per =
  41.                       ed.GetEntity(peo);
  42.                     if (per.Status != PromptStatus.OK)
  43.                         return;
  44.                     // Access the selected block reference
  45.                     br =
  46.                       tr.GetObject(
  47.                         per.ObjectId,
  48.                         OpenMode.ForRead
  49.                       ) as BlockReference;
  50.                 }
  51.                 else
  52.                 {
  53.                     // Otherwise we look up the block by name
  54.                     BlockTable bt =
  55.                       tr.GetObject(
  56.                         db.BlockTableId,
  57.                         OpenMode.ForRead) as BlockTable;
  58.                     if (!bt.Has(pr.StringResult))
  59.                     {
  60.                         ed.WriteMessage(
  61.                           "\nBlock "" + pr.StringResult + "" does not exist."
  62.                         );
  63.                         return;
  64.                     }
  65.                     // Create a new block reference referring to the block
  66.                     br =
  67.                       new BlockReference(
  68.                         new Point3d(),
  69.                         bt[pr.StringResult]
  70.                       );
  71.                 }
  72.                 BlockTableRecord btr =
  73.                   (BlockTableRecord)tr.GetObject(
  74.                     br.DynamicBlockTableRecord,
  75.                     OpenMode.ForRead
  76.                   );
  77.                 // Call our function to display the block properties
  78.                 DisplayDynBlockProperties(ed, br, btr.Name);
  79.                 // Committing is cheaper than aborting
  80.                 tr.Commit();
  81.             }
  82.         }
  83.         private static void DisplayDynBlockProperties(
  84.           Editor ed, BlockReference br, string name
  85.         )
  86.         {
  87.             // Only continue is we have a valid dynamic block
  88.             if (br != null && br.IsDynamicBlock)
  89.             {
  90.                 ed.WriteMessage(
  91.                   "\nDynamic properties for "{0}"\n",
  92.                   name
  93.                 );
  94.                 // Get the dynamic block's property collection
  95.                 DynamicBlockReferencePropertyCollection pc =
  96.                   br.DynamicBlockReferencePropertyCollection;
  97.                 // Loop through, getting the info for each property
  98.                 foreach (DynamicBlockReferenceProperty prop in pc)
  99.                 {
  100.                     // Start with the property name, type and description
  101.                     ed.WriteMessage(
  102.                       "\nProperty: "{0}" : {1}",
  103.                       prop.PropertyName,
  104.                       prop.UnitsType
  105.                     );
  106.                     if (prop.Description != "")
  107.                         ed.WriteMessage(
  108.                           "\n  Description: {0}",
  109.                           prop.Description
  110.                         );
  111.                     // Is it read-only?
  112.                     if (prop.ReadOnly)
  113.                         ed.WriteMessage(" (Read Only)");
  114.                     // Get the allowed values, if it's constrained
  115.                     bool first = true;
  116.                     foreach (object value in prop.GetAllowedValues())
  117.                     {
  118.                         ed.WriteMessage(
  119.                           (first ? "\n  Allowed values: [" : ", ")
  120.                         );
  121.                         ed.WriteMessage(""{0}"", value);
  122.                         first = false;
  123.                     }
  124.                     if (!first)
  125.                         ed.WriteMessage("]");
  126.                     // And finally the current value
  127.                     ed.WriteMessage(
  128.                       "\n  Current value: "{0}"\n",
  129.                       prop.Value
  130.                     );
  131.                 }
  132.             }
  133.         }
  134.     }
  135. }
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 02:52 , Processed in 0.437583 second(s), 67 queries .

© 2020-2025 乐筑天下

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