Message 1 of 4
Not applicable
06-27-2021
12:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is it possible to update a combobox.selecteditem during a sendstringtoexecute command?
the code below sets the drawings current layer to a selected entities as desired but then i want to update a combobox to show the current layer. The combobox has the current layer in it as a string. during debigging the getsystemvariable() function returns the correct string however it says the combobox.seleceteditem = null. Im guessing this has something to do with synchronicity but for the life of me cant figure out how to fix it.
[acadRt.CommandMethod("Select_Line_Number")]
public void SelectLineNumber()
{
acadApp.MainWindow.Focus();
// create locally
acadAp.Document document = acadAp.Application.DocumentManager.MdiActiveDocument;
acadDb.Database database = document.Database;
acadEd.Editor editor = acadApp.DocumentManager.MdiActiveDocument.Editor;
// select an object
var prompt = new acadEd.PromptSelectionOptions();
prompt.SingleOnly = true;
prompt.SinglePickInSpace = true;
acadEd.PromptSelectionResult result;
var objects = new acadDb.ObjectIdCollection();
result = editor.GetSelection(prompt);
if (result.Status == acadEd.PromptStatus.OK)
{
using (acadDb.Transaction transaction = database.TransactionManager.StartTransaction())
{
// get the entity and layer from the object id
objects.Add(result.Value[0].ObjectId);
acadDb.Entity ent = transaction.GetObject(objects[0], acadDb.OpenMode.ForRead) as acadDb.Entity;
string lineNumber = ent.Layer;
// set the current layer
acadDb.LayerTable layerTable;
layerTable = transaction.GetObject(database.LayerTableId, acadDb.OpenMode.ForRead) as acadDb.LayerTable;
acadDb.LayerTableRecord layerRecord;
layerRecord = transaction.GetObject(layerTable[lineNumber], acadDb.OpenMode.ForRead) as acadDb.LayerTableRecord;
database.Clayer = layerTable[lineNumber];
this.Focus();
cbLineNumber.SelectedItem = acadApp.GetSystemVariable("clayer").ToString();
transaction.Commit();
}
}
}
Solved! Go to Solution.