Although it seems correct i am facing problem when i try to use prompt command (txtexplode) in a for cycle. I need to zoom in for each text objects selected then txtexploding them.
private void textSelectExplode()
{
using (DocumentLock acLckDoc = AcadDoc.LockDocument())
{
using (str = AcadDoc.Database.TransactionManager.StartTransaction())
{
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
FilteringObjects my = new FilteringObjects();
acadFilterValues.SetValue(new TypedValue((int)DxfCode.Operator, "<OR"), counter);
counter++;
acadFilterValues.SetValue(new TypedValue((int)DxfCode.Start, "TEXT"), counter);
counter++;
acadFilterValues.SetValue(new TypedValue((int)DxfCode.Start, "MTEXT"), counter);
counter++;
acadFilterValues.SetValue(new TypedValue((int)DxfCode.Operator, "OR>"), counter);
SelectionFilter acadSelFilter = new SelectionFilter(acadFilterValues);
PromptSelectionOptions acadSelectionOptions = new PromptSelectionOptions();
acadSelectionOptions.MessageForAdding = "\n" + "Select Objects";
PromptSelectionResult acadSelSetPrompt = ed.GetSelection(acadSelectionOptions, acadSelFilter);
if (acadSelSetPrompt.Status == PromptStatus.OK)
{
this.Show();
this.TopMost = true;
Extents3d ext;
SelectionSet acadSelectedObjects = acadSelSetPrompt.Value;
foreach (SelectedObject selectedObj in acadSelectedObjects)
{
if (selectedObj != null)
{
switch (selectedObj.ObjectId.ObjectClass.Name)
{
case "AcDbText":
DBText TextObj = str.GetObject(selectedObj.ObjectId, OpenMode.ForWrite) as DBText;
ext = TextObj.GeometricExtents;
ext.TransformBy(ed.CurrentUserCoordinateSystem.Inverse());
//To zoom in AcDbText object
ZoomWin(ed, ext.MinPoint, ext.MaxPoint);
ed.SetImpliedSelection(new ObjectId[] { TextObj.ObjectId });
AcadDoc.SendStringToExecute("TXTEXP", false, false, false);
AcadDoc.SendStringToExecute(" ", false, false, false);
break;
case "AcDbMText":
MText MtextObj = str.GetObject(selectedObj.ObjectId, OpenMode.ForWrite) as MText;
//Smilar process is requared with text here
break;
default:
break;
}
}
}
}
}
str.Commit();
}
}
the "async" execution nature of SendStringToExecute() method, you cannot call it inside a for/while block and expect its execution in each loop. It should be the last line of code in your textSelectExplode() method. Of cause, this would not get your work done.
One of my articles, that specifically deals with calling "TXTEXP" LISP command from ExpressTools suite against a selection of text entities one by one:
https://drive-cad-with-code.blogspot.com/2022/11/loop-operation-with-sendstringtoexecute.html
HTH
Norman Yuan
Can't find what you're looking for? Ask the community or share your knowledge.