I want to creat a group for the object be selected. but the following code doesn't work, what's the problem?
Is there anyone can help me? very thanks
[CommandMethod("gr")]
public static void SelectObjectsOnscreen()
{
//Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
//Instance a group object
Group myGroup = new Group("xxxx", true);
//Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
//Request for objects to be selected in the drawing area
PromptSelectionResult acSSPrompt = acDoc.Editor.GetSelection();
//If the prompt status is OK, objects were selected
if (acSSPrompt.Status == PromptStatus.OK)
{
SelectionSet acSSet = acSSPrompt.Value;
//Step through the objects in the selection set
foreach (SelectedObject acSSObj in acSSet)
{
//Check to make sure a valid SelectedObject object was returned
if (acSSObj != null)
{
//Open the selected object for write
Entity acEnt = acTrans.GetObject(acSSObj.ObjectId,
OpenMode.ForWrite) as Entity;
if (acEnt != null)
{
Application.ShowAlertDialog(acEnt.ObjectId.ToString());
//Use the Append method
myGroup.Append(acEnt.ObjectId);
}
}
}
//Save the new object to the database
acTrans.Commit();
}
// Dispose of the transaction
}
}
Solved! Go to Solution.
Solved by mzakiralam. Go to Solution.
Hi,
I think there are couple of issues in your code. I have skimmed through you code and it seems to me that you did not declare the group dictionary. Second, you did not add the new group to group dictionary. Please revise your code. you can find something useful in below link.