.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 4
Mikko
618 Views, 3 Replies

Groups

Anybody got a few lines of code to create a group and add entities to it?

Thanks
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Mikko

Here you go:

public class GroupCreator
{
[CommandMethod("mygroup")]
public void DoIt()
{
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionResult res = ed.GetSelection();
if (res.Status != PromptStatus.OK)
return;
Database db =
Application.DocumentManager.MdiActiveDocument.Database;
using (Transaction t = db.TransactionManager.StartTransaction())
{
DBDictionary groupDict =
(DBDictionary)t.GetObject(db.GroupDictionaryId,OpenMode.ForWrite);
//create group
using (Group gr = new Group("This is Mikko's example
group",true))
{
groupDict.SetAt("Mikko",gr);
t.AddNewlyCreatedDBObject(gr,true);
ObjectId[] ids = res.Value.GetObjectIds();
for (int i=0;i gr.Append(ids);
}
t.Commit();
}
}
}
wrote in message news:4865255@discussion.autodesk.com...
Anybody got a few lines of code to create a group and add entities to it?

Thanks
Message 3 of 4
sivashanmugam
in reply to: Mikko

Thanks a lot I will try it.
Message 4 of 4
sbenedetti
in reply to: Mikko

Given a group is it possible to get all entities in that group via the GetAllEntityIds method of the Group object.

Is it possible the reverse? Given an entity is it possible to know in which group it belongs to?

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