- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
the next code is working, but i want it to select just a singe object.
and if there any advice to improve my code
thanks in advance
[CommandMethod("CIE1")]
public static void SelectObjectOnScreen()
{
// get the current document and data base
Document acCurrDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurrDB = acCurrDoc.Database;
// Create a TypedValue array to define the filter criteria, To select 2Dpolylines only
TypedValue[] acTypedValueArray = new TypedValue[1];
acTypedValueArray.SetValue(new TypedValue(0 /*(int)DxfCode.Start*/, "LWPOLYLINE"), 0);
// Assign the filter criteria to a SelectionFilter object
SelectionFilter acSelectionFilter = new SelectionFilter(acTypedValueArray);
// to select a single object
PromptSelectionOptions acPoptions = new PromptSelectionOptions
{
SingleOnly = true,
SinglePickInSpace = true
};
// start a transaction
using (Transaction acCurrTrans = acCurrDB.TransactionManager.StartTransaction())
{
// request for object to be selected in the drawing area
PromptSelectionResult acPromptSelectionResult = acCurrDoc.Editor.GetSelection(acPoptions/*, acSelectionFilter*/);
// if the prompt status is OK, onjects were selected
if (acPromptSelectionResult.Status == PromptStatus.OK)
{
SelectionSet acSelecionSet = acPromptSelectionResult.Value;
// Check to make sure a valid SelectedObject object was returned.
if (acSelecionSet != null)
{
// Open the selected object for read
Entity acEntity = (Entity)acCurrTrans.GetObject(acPromptSelectionResult.Value[0].ObjectId,OpenMode.ForWrite);
if (acEntity != null)
{
// To Do ...
acEntity.ColorIndex = 3;
}
}
// Save the new object to the database
acCurrTrans.Commit();
}
// dispose the transaction
}
Solved! Go to Solution.