你好
我在网上查了一些关于这个问题的信息,但我没有找到任何合理的解决方案。请帮忙
问题是:
我有一个动态块(名为Bore_Hole,它附加到post),它几乎没有动态属性,包括移动。移动属性应移动相关的水平线,垂直尺寸应显示从水平线到块顶部的距离。如果我手动插入这个块,一切都很好。当我通过编程更改动态特性时,问题就会出现,线被正确移动,但尺寸保持默认值。
这是我的代码:
- using System;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.EditorInput;
- [assembly: CommandClass(typeof(InsertingBlock.MyCommands))]
- namespace InsertingBlock
- {
- public class MyCommands
- {
- [CommandMethod("iblock")]
- public void MyCommand()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- Transaction tr = db.TransactionManager.StartTransaction();
- string NazwaBloku = "Bore_Hole";
- using (tr)
- {
-
- BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
- BlockTableRecord btr = new BlockTableRecord();
- if (!bt.Has(NazwaBloku))
- {
- ed.WriteMessage("\n Blok o nazwie Bore_HOle nie istnieje");
- }
- else
- {
- bt.UpgradeOpen();
- BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[blockTableRecord.ModelSpace], OpenMode.ForWrite);
- ObjectId blockId = bt[NazwaBloku];
- ed.WriteMessage("\nblockId" + blockId.ToString());
-
- Point3d pt = new Point3d(0, 0, 0);
- BlockReference br = new BlockReference(pt, blockId);
- ms.AppendEntity(br);
- DynamicBlockReferencePropertyCollection pc = br.DynamicBlockReferencePropertyCollection;
- foreach (DynamicBlockReferenceProperty prop in pc)
- {
- if (prop.PropertyName.ToUpper() == "VISIBILITY1")
- {
- ed.WriteMessage("\nIstnieje taka właściwość");
- prop.Value = "2";
- }
- if (prop.PropertyName.ToUpper() == "D1")
- {
- double length = 2.5;
- prop.Value = length;
- }
-
- ed.WriteMessage("\nProperty:"{0}":{1}", prop.PropertyName, prop.UnitsType);
- if (prop.Description != "")
- {
- ed.WriteMessage("\nDescription: {0}", prop.Description);
- }
- if (prop.ReadOnly)
- {
- ed.WriteMessage("read only");
- }
- bool first = true;
- foreach (object value in prop.GetAllowedValues())
- {
- ed.WriteMessage(first ? "\n Allowed values: [" : ", ");
- ed.WriteMessage(""{0}"", value);
- first = false;
- }
- if (!first) ed.WriteMessage("]");
- ed.WriteMessage("\n Current value: "{0}"\n", prop.Value);
- }
- tr.AddNewlyCreatedDBObject(br, true);
- }
- tr.Commit();
- }
- }
- }
- }
我使用的是VS 2008和autocad2010。
钻孔块。图纸
|