Code Red > .NET

SendStringToExecute not running without document being select manually

(1/4) > >>

servids:
I have the following code which iterates a listview containing file names and tries to send a command using "SendStringToExecute" to each file. The problem is that the command doesn't seem to run unless I leave the drawings open and use the mouse to go back and select each window.
After I select each window the command goes through like normal. This is a problem because I want my command to save each drawing and close it, it is a real pain to have to leave all of the drawings open just so that I can cycle trough them manually. Ive tried setting the commandsflag to session and tried changing all of the parameters to "SendStringToExecute". I've tried setting the windows focus, minimizing it, and even sleeping for a couple of seconds on the active window but nothing seems to help. Does anyone have any ideas?


--- Code: ---Form1.ActiveForm.Visible = false;
            for (int i = 0; i < listView1.Items.Count; i++)
            {
               
                if (listView1.Items[i].Selected == true)
                {
                    string mystring = listView1.Items[i].SubItems[0].Text;
                    Document mydoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(mystring, false);
                    mydoc.LockDocument();
           
                    Point3d mypoint = mydoc.Database.Insbase;
                    string scale_point;
                    scale_point = mypoint.ToString().TrimEnd(')');
                    scale_point = scale_point.TrimStart('(');

                    mydoc.SendStringToExecute("scale all  " + scale_point + " 1/96 ", true, false, true);
       
                    SetFocus(mydoc.Window.Handle);
                    Thread.Sleep(1000);

                    mydoc.CloseAndSave(mystring);
                    mydoc.Dispose();
                }
            }
--- End code ---

Nathan Taylor:
As with SendCommand in VBA SendStringToExecute should be used as a last resort.

Cycle through all entities and use the TransformBy method of the entity.

Glenn R:
That's because SendStringToExecute is asynchronous, which for all intents and purposes, will execute when the program is done, hence it's used as a last resort, as Nathan mentioned (read the last line in a program).

David Hall:
Not to encourage the use of it, but in VBA I found a way to beat it by making small functions that did nothing but the send command, thus when that function was called and ended the sendcommand was sent before scope returned to the calling function.  Or was I just lucky?

Glenn R:
Mr. Duh, come on down!!! It's your lucky night!!!  :evil:

Navigation

[0] Message Index

[#] Next page

Go to full version