乐筑天下

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

[编程交流] 动态块和相关w

[复制链接]

2

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 22:41:50 | 显示全部楼层 |阅读模式
你好
 
我在网上查了一些关于这个问题的信息,但我没有找到任何合理的解决方案。请帮忙
问题是:
 
我有一个动态块(名为Bore_Hole,它附加到post),它几乎没有动态属性,包括移动。移动属性应移动相关的水平线,垂直尺寸应显示从水平线到块顶部的距离。如果我手动插入这个块,一切都很好。当我通过编程更改动态特性时,问题就会出现,线被正确移动,但尺寸保持默认值。
 
这是我的代码:
 
  1. using System;
  2. using Autodesk.AutoCAD.Runtime;
  3. using Autodesk.AutoCAD.ApplicationServices;
  4. using Autodesk.AutoCAD.DatabaseServices;
  5. using Autodesk.AutoCAD.Geometry;
  6. using Autodesk.AutoCAD.EditorInput;
  7. [assembly: CommandClass(typeof(InsertingBlock.MyCommands))]
  8. namespace InsertingBlock
  9. {
  10.    public class MyCommands
  11.    {
  12.        [CommandMethod("iblock")]
  13.        public void MyCommand()
  14.        {
  15.            Document doc = Application.DocumentManager.MdiActiveDocument;
  16.            Database db = doc.Database;
  17.            Editor ed = doc.Editor;
  18.            Transaction tr = db.TransactionManager.StartTransaction();
  19.            string NazwaBloku = "Bore_Hole";
  20.            using (tr)
  21.            {
  22.                
  23.                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  24.                BlockTableRecord btr = new BlockTableRecord();
  25.                if (!bt.Has(NazwaBloku))
  26.                {
  27.                    ed.WriteMessage("\n Blok o nazwie Bore_HOle nie istnieje");
  28.                }
  29.                else
  30.                {
  31.                    bt.UpgradeOpen();
  32.                    BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[blockTableRecord.ModelSpace], OpenMode.ForWrite);
  33.                    ObjectId blockId = bt[NazwaBloku];
  34.                    ed.WriteMessage("\nblockId" + blockId.ToString());
  35.                   
  36.                    Point3d pt = new Point3d(0, 0, 0);
  37.                    BlockReference br = new BlockReference(pt, blockId);
  38.                    ms.AppendEntity(br);
  39.                    DynamicBlockReferencePropertyCollection pc = br.DynamicBlockReferencePropertyCollection;
  40.                    foreach (DynamicBlockReferenceProperty prop in pc)
  41.                    {
  42.                        if (prop.PropertyName.ToUpper() == "VISIBILITY1")
  43.                        {
  44.                            ed.WriteMessage("\nIstnieje taka właściwość");
  45.                            prop.Value = "2";
  46.                        }
  47.                        if (prop.PropertyName.ToUpper() == "D1")
  48.                        {
  49.                            double length = 2.5;
  50.                            prop.Value = length;
  51.                        }
  52.                        
  53.                        ed.WriteMessage("\nProperty:"{0}":{1}", prop.PropertyName, prop.UnitsType);
  54.                        if (prop.Description != "")
  55.                        {
  56.                            ed.WriteMessage("\nDescription: {0}", prop.Description);
  57.                        }
  58.                        if (prop.ReadOnly)
  59.                        {
  60.                            ed.WriteMessage("read only");
  61.                        }
  62.                        bool first = true;
  63.                        foreach (object value in prop.GetAllowedValues())
  64.                        {
  65.                            ed.WriteMessage(first ? "\n  Allowed values: [" : ", ");
  66.                            ed.WriteMessage(""{0}"", value);
  67.                            first = false;
  68.                        }
  69.                        if (!first) ed.WriteMessage("]");
  70.                        ed.WriteMessage("\n  Current value: "{0}"\n", prop.Value);
  71.                    }
  72.                    tr.AddNewlyCreatedDBObject(br, true);
  73.                }
  74.                tr.Commit();
  75.            }
  76.        }  
  77.    }
  78. }

 
我使用的是VS 2008和autocad2010。
钻孔块。图纸
234153qlz6gfyy66igrrel.jpg
234155hr4j8cdxvfev6ojf.jpg
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 11:35 , Processed in 0.866778 second(s), 57 queries .

© 2020-2025 乐筑天下

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