Load lisp app from c# code and wait until it finish

Load lisp app from c# code and wait until it finish

ashrafa33
Enthusiast Enthusiast
714 Views
3 Replies
Message 1 of 4

Load lisp app from c# code and wait until it finish

ashrafa33
Enthusiast
Enthusiast

i have a lsp app that select lines and get there proerties and save them to file

i want to run this app from c# code

but when i run it from c# code the c# countine working and when it read the txt file it found it empty 

after while the file will have the lines properties from lisp file

0 Likes
715 Views
3 Replies
Replies (3)
Message 2 of 4

ActivistInvestor
Mentor
Mentor

Should others reading your post guess what your code does?

 

Post your code.

 

You have to define a C:XXXX command function in your LISP file that runs the operation, and then call it from the Application.Invoke() method. You also have to call (vl-acad-defun) to register your command function so that it can be called by Invoke().

 

 

0 Likes
Message 3 of 4

ashrafa33
Enthusiast
Enthusiast

Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
try
{
doc.SendStringToExecute("(load \"test.lsp\") ", true, false, false);
doc.SendStringToExecute("test_to_start" + "\n", true, false, false);
doc.LispEnded += new EventHandler(OnLispEnded);

MessageBox.Show("it continue" );
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
MessageBox.Show(ex.ToString() );
}

i tried doc.LispEnded += new EventHandler(OnLispEnded);

but i did not help

(setq JS (SSGET (LIST '(0 . "LINE,ARC,POLYLINE"))))

so it give the Message ("it continue" ) before ssget

0 Likes
Message 4 of 4

ActivistInvestor
Mentor
Mentor

That code will not work (post code using the insert code button on the toolbar).

 

SendStringToExecute() does not execute the string until after the managed code that calls it returns. You can't wait for it.  You can use Application.Invoke() to call the LISP if you define it as a C:XXXX command function and use (vl-acad-defun) to register it.

 

 

 

 

0 Likes