Recognizing a Group object trough VBA
I have created a Group object from polyline and circles. I would like to let user select an object and test if his selection is a Group object. I have tried the following:
Dim Obj As AcadEntity
ThisDrawing.Utility.GetEntity Obj, pt, "select entity...."
If TypeOf Obj Is AcadGroup Then
MsgBox "The object is a Group object."
Else
MsgBox "The object is not a Group object."
End If
For some reason 'TypeOf' does not recognize it. I have tested the same code on circle and polyline and it worked as expected.
Please advise, I must be missing something.
I am running Bricscad version 8.
Many thanks
Jiri
Comments
-
I could be wrong, but I don't think this is exposed in VBA... you can do this in lisp by searching the object's DXF entry I.e
(vla-get-Name (vlax-ename->vla-object (cdr (assoc 330 (entget (car (entsel)))))))
0 -
Maybe a little better:
(vla-get-objectname (vlax-ename->vla-object (cdr (assoc 330 (entget (car (entsel))))))) => "AcDbGroup"0 -
Function IsGrouped(ByVal ent As AcadEntity, ByRef group As AcadGroup) As Boolean
Dim result As Boolean = False
For Each Gp As AcadGroup In cadApp.ActiveDocument.Groups
For i As Integer = 0 To Gp.Count - 1
Dim e As AcadEntity = Gp.Item(i)
If e.Handle = ent.Handle Then
result = True
group = Gp
Return result
End If
Next
Next
Return result
End FunctionThis is vb.net code but you get the idea. Maybe inefficient but you can do it...
0 -
Damian, you rock!
0 -
ok, guys
many thanks for quick response. I have not tried your LISP stuff yet but what Damian is suggesting works very well. Many thanks again!
I made small modifications to accomodate to VBA:
Function IsGrouped(ByVal obj As AcadEntity) As Boolean
Dim result As Boolean
Dim i As Integer
Dim Gp As AcadGroup
result = False
For Each Gp In ThisDrawing.Database.Groups
For i = 0 To Gp.count - 1
Dim e As AcadEntity
Set e = Gp.Item(i)
If e.Handle = obj.Handle Then
result = True
IsGrouped = result
End If
Next
Next
IsGrouped = result
End Functionwhere obj is from
ThisDrawing.Utility.GetEntity obj, pt, "select entity...."
Many thanks again
Jiri
0