SendCommand execute after Form close.

SendCommand execute after Form close.

Anonymous
Not applicable
1,103 Views
7 Replies
Message 1 of 8

SendCommand execute after Form close.

Anonymous
Not applicable

Hi

 On Command Method in my plugin i load a form using following call.

 

Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form);

 When form loads on a button click event i call  ActiveDocument.Utility.GetPoint  to get a point on my dwg.

After getting ther point in button click event i call ActiveDocument.SendCommand to create new TextStyle.

 

SendCommand dont work until i close my form. after closing form commandline ask for textstyle params.

 

Is there any way i can run SendCommand when my form is on screen.

 

thanks

0 Likes
1,104 Views
7 Replies
Replies (7)
Message 2 of 8

_gile
Consultant
Consultant

Hi,

 

SendCommand (as SendStringToExecute) runs asynchronously.

To synchronously run a command:

- targeting AutoCAD 2015 or later, you can use the Editor.Command method (see here and there) ;

- for pior versions, you'd need to P/Invoke acedCmd or call the non public Editor.Command() method.

 

You can also create a new TextStyleTableRecord and add it to the TextStyleTable programatically (see here).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 8

Anonymous
Not applicable

Hi Gilles

 

Thanks for your reply.

 

i have problem using Editor command method every time i call it throw exception on line

Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.IsApplicationContext

which is always true.

tried with CommandFlags.Session and without it no diffrence.

 

Thanks

0 Likes
Message 4 of 8

Anonymous
Not applicable

Hi,

 

try use this

 

Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog (MyForm);

0 Likes
Message 5 of 8

Anonymous
Not applicable

no diffrence weather its modal or Modeless dialog.

 

 

0 Likes
Message 6 of 8

Anonymous
Not applicable

Ok, can you show your code?

0 Likes
Message 7 of 8

Anonymous
Not applicable

Autocad2014 with .net 4

 

here is my code very simple.

 

public class NavPlugin : IExtensionApplication
    {

        public void Initialize()
        {

        }

        public void Terminate()
        {
            throw new NotImplementedException();
        }


        [CommandMethod("SNDCMD")]
        public static void sendCmd()
        {
            var form = new MyForm();        
            Application.ShowModelessDialog(form);
        }

       
    }

public partial class MyForm : Form
    {
        public MyForm()
        {
            InitializeComponent();
        }

       
        private void BtnSendCmdClick(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
          
            ed.Command("_line", new Point2d(0, 0), new Point2d(500, 500));
            ed.WriteMessage("test.");
          
        }
    }

0 Likes
Message 8 of 8

_gile
Consultant
Consultant

Hi,

 

while using modeless dialog, you have to lock the document before you modify it.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes