.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Proble in Prompt Command Usage in a For Cycle

1 REPLY 1
Reply
Message 1 of 2
ekoneo
143 Views, 1 Reply

Proble in Prompt Command Usage in a For Cycle

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();
            }

        }
1 REPLY 1
Message 2 of 2
norman.yuan
in reply to: ekoneo

 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

Drive CAD With Code

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report