CAD二次开发——GetEntity,获取对象,ID进制转换

 1. 封装一个函数

'获取图纸上 绘图元素
Public Function GetEntity(Prompt As String, ByRef GetP As Variant) As AcadEntity
On Error GoTo Err_DD
acadApp.ActiveDocument.Utility.GetEntity GetEntity, GetP, Prompt
Exit Function
Err_DD:
End Function 

2. 调用这个函数

Dim ent As AcadEntity
Dim inp As Variant

Set ent = GetEntity("请选择内边框", inp)
If ent Is Nothing Then Exit Sub 

对象ID转10进制

bData(3) = CLng("&H" & elem.Handle)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用C#对CAD2019进行二次开发获取块属性,可以使用AutoCAD .NET API。以下是获取块属性的示例代码: ```csharp // 获取当前文档 Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; // 获取当前文档的数据库 Database db = doc.Database; // 获取当前文档的编辑器 Editor ed = doc.Editor; // 提示用户选择块 PromptEntityOptions peo = new PromptEntityOptions("\n请选择块:"); peo.SetRejectMessage("\n只能选择块!"); peo.AddAllowedClass(typeof(BlockReference), true); PromptEntityResult per = ed.GetEntity(peo); if (per.Status == PromptStatus.OK) { // 打开块事务 using (Transaction trans = db.TransactionManager.StartTransaction()) { // 获取对象 BlockReference blkRef = trans.GetObject(per.ObjectId, OpenMode.ForRead) as BlockReference; if (blkRef != null) { // 获取块定义对象 BlockTableRecord btr = trans.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord; if (btr != null) { // 获取块属性定义集合 AttributeDefinitionCollection attDefs = btr.AttributeCollection; foreach (ObjectId attDefId in attDefs) { AttributeDefinition attDef = trans.GetObject(attDefId, OpenMode.ForRead) as AttributeDefinition; if (attDef != null && !attDef.Constant) { // 获取块属性值 AttributeReference attRef = new AttributeReference(); attRef.SetAttributeFromBlock(attDef, blkRef.BlockTransform); ed.WriteMessage($"\n{attDef.Tag}: {attRef.TextString}"); } } } } // 提交块事务 trans.Commit(); } } ``` 以上代码通过选择块,获取块定义对象,遍历块属性定义集合,获取块属性值,并在命令行中输出属性名和属性值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值