.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Searching Groups

9 REPLIES 9
Reply
Message 1 of 10
martinw
809 Views, 9 Replies

Searching Groups

I am writing a function to search through all AutoCAD groups.
I have no idea how to search the group dictionary
Here is the code I have so far:
{code}
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Interop
Module Group01
Public Function GroupNameObjGet(ByVal sHandle As String)
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acGroupDict As DBDictionary
acGroupDict = acTrans.GetObject(acCurDb.GroupDictionaryId, OpenMode.ForRead)
Debug.Print("GroupNameObjGet.Trans")
Dim i As Long = 0
For Each acDbDictEnt As DBDictionaryEntry In acGroupDict
Debug.Print("GroupNameObjGet.Key: " & acDbDictEnt.Key)
'?????

Next
End Using
End Function
{code}

Thanks Edited by: martinw@pacific.net.au on Feb 18, 2010 5:36 AM
9 REPLIES 9
Message 2 of 10
_gile
in reply to: martinw

Hi,

The ACAD_GROUP dictionary is a NamedObjectsDictionary entry.

{code}DBDictionary NOD =
(DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
DBDictionary acGgroup =
(DBDictionary)tr.GetObject(NOD.GetAt("ACAD_GROUP"), OpenMode.ForRead);{code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 10
Martin60
in reply to: martinw

Sorry, I still don't get this.
Does someone have a VB example?
Message 4 of 10
BillZndl
in reply to: martinw

Not VB.net, sorry
but here's how I do it:

{code}
using (Transaction trans = db.TransactionManager.StartTransaction())
{
DBDictionary GrpDic = trans.GetObject(db.GroupDictionaryId, OpenMode.ForRead) as DBDictionary;

foreach (DictionaryEntry DicEnt in GrpDic)
{

ObjectId Did = GrpDic.GetAt(DicEnt.Key.ToString()); //gets objectid from entry.

Group EntGrpDic = (Group)trans.GetObject(Did, OpenMode.ForRead);

string Name = EntGrpDicName; //etc. etc.

}
trans.Commit;
}
{code} Edited by: BillZndl on Feb 23, 2010 5:36 AM
Message 5 of 10
Anonymous
in reply to: martinw

Why do you want to search all groups?

If you know the handle or ObjectId of the object and you
want to find out what groups contain it, you don't have to
search groups to find that.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6339319@discussion.autodesk.com...
I am writing a function to search through all AutoCAD groups.
I have no idea how to search the group dictionary
Here is the code I have so far:
{code}
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Interop
Module Group01
Public Function GroupNameObjGet(ByVal sHandle As String)
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction =
acCurDb.TransactionManager.StartTransaction()
Dim acGroupDict As DBDictionary
acGroupDict = acTrans.GetObject(acCurDb.GroupDictionaryId,
OpenMode.ForRead)
Debug.Print("GroupNameObjGet.Trans")
Dim i As Long = 0
For Each acDbDictEnt As DBDictionaryEntry In acGroupDict
Debug.Print("GroupNameObjGet.Key: " & acDbDictEnt.Key)
'?????

Next
End Using
End Function
{code}

Thanks

Edited by: martinw@pacific.net.au on Feb 18, 2010 5:36 AM
Message 6 of 10
Martin60
in reply to: martinw

I want to know what group the object is in and what other objects are in that group.
Thanks
Message 7 of 10
Martin60
in reply to: martinw

What is a more direct method to finding the group that the object is in?
Message 8 of 10
BillZndl
in reply to: martinw

http://discussion.autodesk.com/forums/thread.jspa?messageID=5709413ṥ

Once you find the group (objectId) you want,
opend the group to read and then:

foreach (ObjectId id in group)

.....
Message 9 of 10
Anonymous
in reply to: martinw

First, keeping in mind that an entity can be a member of more than one group:

{code}

Public Class EntityHelpers

' return the ObjectIds of all groups which
' the given entity is a member of:

Public Shared Function GetGroupIds(ByVal entity As Entity) As
ObjectIdCollection
Dim result As New ObjectIdCollection
Dim reactors As ObjectIdCollection = entity.GetPersistentReactorIds
If Not (reactors Is Nothing) Then
Dim id As ObjectId
For Each id In reactors
If id.ObjectClass.IsDerivedFrom(groupRxClass) Then
result.Add(id)
End If
Next
End If
Return result
End Function

Private Shared groupRxClass As RXClass = RXObject.GetClass(GetType(Group))

End Class


{code}

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6342725@discussion.autodesk.com...
What is a more direct method to finding the group that the object is in?
Message 10 of 10
Anonymous
in reply to: martinw

And here's a C# extension method version:

{code}

public static class EntityExtensionMethods
{
public static IEnumerable GetGroupIds( this Entity entity )
{
ObjectIdCollection ids = entity.GetPersistentReactorIds();
if( ids != null && ids.Count > 0 )
{
RXClass rxclass = RXClass.GetClass(typeof(Group));
return ids.Cast()
.Where( id => id.ObjectClass.IsDerivedFrom( rxclass ) );
}
return Enumerable.Empty();
}
}

{code}

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

"Tony Tanzillo" wrote in message
news:6342902@discussion.autodesk.com...
First, keeping in mind that an entity can be a member of more than one group:

{code}

Public Class EntityHelpers

' return the ObjectIds of all groups which
' the given entity is a member of:

Public Shared Function GetGroupIds(ByVal entity As Entity) As
ObjectIdCollection
Dim result As New ObjectIdCollection
Dim reactors As ObjectIdCollection = entity.GetPersistentReactorIds
If Not (reactors Is Nothing) Then
Dim id As ObjectId
For Each id In reactors
If id.ObjectClass.IsDerivedFrom(groupRxClass) Then
result.Add(id)
End If
Next
End If
Return result
End Function

Private Shared groupRxClass As RXClass = RXObject.GetClass(GetType(Group))

End Class


{code}

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6342725@discussion.autodesk.com...
What is a more direct method to finding the group that the object is in?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost