600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 使用C#中的AutoCAD .NET API对CAD二次开发 获取块的属性

使用C#中的AutoCAD .NET API对CAD二次开发 获取块的属性

时间:2020-01-11 10:15:40

相关推荐

使用C#中的AutoCAD .NET API对CAD二次开发 获取块的属性

使用C#中的AutoCAD .NET API对CAD二次开发,获取块的属性

/// <summary>/// 获得块对象的所有属性/// </summary>public void GetBlockAllAttr(){Document doc = Application.DocumentManager.MdiActiveDocument;Database db = doc.Database;Editor ed = doc.Editor;// 获取选择对象PromptSelectionResult psr = ed.GetSelection();if (psr.Status != PromptStatus.OK){ed.WriteMessage("没有选择任何块。");return;}SelectionSet sSet = psr.Value;ObjectId[] selectedIds = sSet.GetObjectIds(); // 获取选择集的ObjectiID.ObjectId blockId = selectedIds[0]; // 假设只选择了一个块using (Transaction tr = db.TransactionManager.StartTransaction()){BlockReference br = tr.GetObject(blockId, OpenMode.ForWrite) as BlockReference;foreach (ObjectId item in br.AttributeCollection) // 遍历所有属性{AttributeReference attRef = (AttributeReference)item.GetObject(OpenMode.ForRead);ed.WriteMessage("\n属性名和值:" + attRef.Tag.ToString() + " " + attRef.TextString.ToString());}}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。