- UID
- 675164
- 积分
- 224
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2013-4-19
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
How to access AutoCAD Group subsystem via .NET
Issue
I want to extract the ObjectIds that make up a particular Group, how can it be done?
Solution
Here's some sample code written in VB.NET to show how to do what you want.
' Define command 'getGroupIds' - by Fenton Webb, DevTech, Autodesk 12/09/2006
<CommandMethod("getGroupIds")> _
Public Sub getGroupIds()
' input the group name we want to list
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim groupName As PromptResult = ed.GetString("Enter Group name to list : ")
' get the working database
Dim db As Database = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase
' start a transaction
Dim trans As Transaction = db.TransactionManager.StartTransaction()
' now try the read
Try
' get the named objects dictionary
Dim nod As DBDictionary = trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead)
' now get the ACAD_GROUP dictionary entry, this contains all of the Groups defined in the drawing
Dim acadGroup As DBDictionary = trans.GetObject(nod("ACAD_GROUP"), OpenMode.ForRead)
' next, find the group name that was entered above
Dim groupRequired As Group = trans.GetObject(acadGroup(groupName.StringResult), OpenMode.ForRead)
' we now have the group required, lets find out what's inside
Dim entityIds As ObjectId() = groupRequired.GetAllEntityIds()
Dim id As ObjectId
For Each id In entityIds
' open the entity for read
Dim ent As Entity = trans.GetObject(id, OpenMode.ForRead)
' create the highlight path
Dim path As FullSubentityPath = New FullSubentityPath(New ObjectId(0) {id}, New SubentityId(SubentityType.Null, 0))
' now highlight it
ent.Highlight(path, True)
Next
trans.Commit()
Catch ex As Exception
MsgBox(ex.Message)
trans.Dispose()
Finally
End Try
End Sub
|
|