Jump to content

Starting Lisp


fuccaro

Recommended Posts

I try to write a program in VBA, but I see now that I could use some routines I wrote previously in AutoLisp.

First question: Is there a way to start a Lisp routine from VBA?

Second: Is there a way to start a Lisp from VBA and after the Lisp finishes, to return to VBA?

Third: How to start a Lisp from VBA and the lisp returns a real number in VBA that is used in calculations.

 

Or maybe I should rewrite all the Lisp code to have everything in VBA?

Link to comment
Share on other sites

That is not a problem for me! I still use AutoCAD 2006 and from what I can see, "they" will not upgrade us during this life time. We use Catia now and AutoCAD is kept just for maintaining the old projects. I write programs just for my own pleasure -and to help myself and my colleagues in the daily routines.

Thank you for answering me!

Link to comment
Share on other sites

To call an AutoLISP routine in VBA will have to use the SendCommand statement (don’t forget to add a final space = ):

 

ThisDrawing.SendCommand "(load " & chr(34) & "MyLispFile" & chr(34) & ")(MyRoutine) "

 

 

Unfortunately there is no way (or at least I wasn’t able to find one) to see from VBA when the AutoLISP interpreter is done, so the VBA code is not waiting for that processing to get done.

I was tempted in the past to use your proposed approach but finally got to translate my AutoLISP to VBA.

 

Regards,

Link to comment
Share on other sites

How to start a Lisp from VBA and the lisp returns a real number in VBA that is used in calculations.

 

The first solution to communicate between AutoLISP and VBA is to use the USER*1-5 system variables:

 

(setvar "USERS1" "Hello World!")
thisDrawing.GetVariable "USERS1"

 

 

Second, may use a temporarily file to communicate between languages.

 

Third, may check the solution proposed here.

 

Regards,

Link to comment
Share on other sites

Many thanks msasu!

I will try it these days. The Userr1 sounds good to me. Also I think to clear the Users1, start the lisp routine and wait in a loop until Users1 changes. After that the vba code may continue to run.

Thanks again!

Link to comment
Share on other sites

You’re welcome!

 

Also I think to clear the Users1, start the lisp routine and wait in a loop until Users1 changes. After that the vba code may continue to run.

 

This sound very promising! I have to make some tests, also. Thank you!

 

Regards,

Link to comment
Share on other sites

  • 1 year later...

Since just found that this may be interesting for other too, I want to confirm that the above proposed validation solution works.

Link to comment
Share on other sites

A project I'm working on starts out with VBA and then launches AutoCAD and runs a LISP program. The easiest way I have found to get data between the two languages is to use temporary text files. I use them profusely and the process works well.

Link to comment
Share on other sites

Is that a VBA (Visual Basic for Applications - that run inside AutoCAD or MS Office) or VB (Visual Basic - stand-alone application) tool?

Link to comment
Share on other sites

It's a VBA program which runs inside of Excel. Many structural calculations take place in this Excel file because that's they way the Engineers who worked here before us did it. The VBA program gathers up the results of these calculations and writes them to a text file. The VBA program then launches AutoCAD and loads a LISP program which then reads this text file in order to create an assembly drawing.

 

I'm also working on VB.NET (stand-alone apps). Right now I'm testing one which reads and writes to an SQL database. It can be launched from a desktop shortcut but I just made a new menu item in AutoCAD which will allow the user to open it while in AutoCAD. I positioned it to open up in the middle of the screen so to the user it looks like it's all running within AutoCAD.

 

I hear you about VBA being done away with. And of course, if you really define done away with, it's life will only end when the last user stops using it. As long as old copies of AutoCAD are around with the VBA editor added on, it will still be of use to those of us who want it. But with all the talk about .NET taking the lead, I'm starting to do more and more development with VB.NET. The IT guys want us to use C#, so I told them with today's converting software, it doesn't matter which language you develop in. And once it's compiled, who cares what language it was written in. Man we've sure come a long way from line numbers and GOTO.

 

100 CLS
110 PRINT "PLEASE WAIT WHILE YOUR FILE IS PREPARED"
120 OPEN "C:\MYFILE.TXT" FOR OUTPUT AS #1
130 FOR i = 1 TO 10
140 READ A$
150 PRINT #1 A$
160 NEXT i
170 CLOSE #1
180 GOTO 1000
190 DATA 1,2,3,4,5,6,7,8,9,10
1000 PRINT "FILE READY"

Link to comment
Share on other sites

If I’m not wrong, that excerpt is Basic; my first encounter with programming was with Turbo Pascal.

 

I asked you about the calling technology since I was curios about the solution you used to notify from AutoCAD editor to caller application (Excel’s VBA in your case) the fact that AutoLISP interpreter is done and other code can be resumed. I used the solution suggested by @fuccaro and was working great, but until that I had to translate some AutoLISP code to VBA.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...