Ivan.Markov.206575
2009-07-22, 08:52 PM
Hi everyone,
If you have ever tried to create a modal form and then send commands to the autocad command line and not succeeded, this is the way to do it:
Form myform=new Form();
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(myform);
//After the last line is executed the autocad command line is disabled, until
//the form is closed. The way to keep the form open and still invoke commands is:
Editor current=Autodesk.AutoCAD.ApplicationServices
.Application.DocumentManager.MdiActiveDocument.Editor;
EditorUserInteraction interaction=current.StartUserInteraction(myform);
//after the last command is executed the form is hidden and
//commands can be send to the command line
//send commands MdiActiveDocument.SendStringToExecute(params)
//when you are done
interaction.End();//that restores your modal form, and the command line is blocked again
I really wish I had figured this one out long time ago. It would have saved me a lot of wasted time. Hoping someone else would find this useful.
P.S. This code is valid for AutoCAD 2009. I am not sure if it applies for older versions of AutoCAD.
If you have ever tried to create a modal form and then send commands to the autocad command line and not succeeded, this is the way to do it:
Form myform=new Form();
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(myform);
//After the last line is executed the autocad command line is disabled, until
//the form is closed. The way to keep the form open and still invoke commands is:
Editor current=Autodesk.AutoCAD.ApplicationServices
.Application.DocumentManager.MdiActiveDocument.Editor;
EditorUserInteraction interaction=current.StartUserInteraction(myform);
//after the last command is executed the form is hidden and
//commands can be send to the command line
//send commands MdiActiveDocument.SendStringToExecute(params)
//when you are done
interaction.End();//that restores your modal form, and the command line is blocked again
I really wish I had figured this one out long time ago. It would have saved me a lot of wasted time. Hoping someone else would find this useful.
P.S. This code is valid for AutoCAD 2009. I am not sure if it applies for older versions of AutoCAD.