Author Topic: Is it possible to Write a new LISP routine with LISP?  (Read 2607 times)

0 Members and 1 Guest are viewing this topic.

Rustabout

  • Newt
  • Posts: 135
Is it possible to Write a new LISP routine with LISP?
« on: January 26, 2020, 11:36:57 PM »
I know that you can write to a text file. I never experimented with renaming the file with a different extension though. Has anyone ever tried this?

HasanCAD

  • Swamp Rat
  • Posts: 1421

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: Is it possible to Write a new LISP routine with LISP?
« Reply #2 on: January 27, 2020, 07:51:36 AM »
yes, I have and it was fun (but a very long time ago; sorry I don't have an example to share anymore). If your lisp file never has to change it's quite simple--just do as you say-. But if you need to rewrite the code based on differing condictions you may want to employ the preprocessor I wrote to save you time and effort. You can call that tool from AutoLisp.

Install version 1.7 and if you'd like you can replace the exe with the version found in the 2.0.2 archive.
https://www.theswamp.org/index.php?topic=37700.0
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Rustabout

  • Newt
  • Posts: 135
Re: Is it possible to Write a new LISP routine with LISP?
« Reply #3 on: January 27, 2020, 02:16:20 PM »
Look's like I'm in business, thanks guys!!

My idea was to great a routine incorporating dialog boxes, that would "set-up" basic routines for inserting blocks... Basically the user would simply fill-out dialog box entries to create a custom routine to insert the block on a specific layer, and manipulate any custom properties that block might have (example: a stretch action).

I think I can actually do that! It's much easier to know it's possible before exploring it on my own and reaching a dead end.

Thanks again!

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Is it possible to Write a new LISP routine with LISP?
« Reply #4 on: January 27, 2020, 11:15:47 PM »
AI, Skynet can modify its own source code

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Is it possible to Write a new LISP routine with LISP?
« Reply #5 on: January 30, 2020, 03:02:22 AM »
You can certainly get lisp to write a lisp the only thing though is once you do (load "newlisp") your current lisp is abandoned.

Have a look at my Multi getvals.lsp over at Cadtutor -> Downloads may save you some time writing individual dcls. Only requires 1 line of code to create and  run a dcl.
A man who never made a mistake never made anything

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Is it possible to Write a new LISP routine with LISP?
« Reply #6 on: January 30, 2020, 08:13:37 AM »
...the only thing though is once you do (load "newlisp") your current lisp is abandoned.

How so? The load expression will be evaluated like any other AutoLISP expression, and the program will then continue to evaluate any expressions which follow.

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Is it possible to Write a new LISP routine with LISP?
« Reply #7 on: January 31, 2020, 09:36:50 PM »
Your right Lee should have explained more if the new lisp just runs say no defuns it will stop execution of the 1st lisp. More a daisy chain method rather than going sideways for a moment.

Code: [Select]
; BUTT.lsp
(defun but ()
(alert "but is ok now")
)

running code
 (if (not but)(Load "BUTT.lsp"))
(But)
next step in code

Code: [Select]
; BUTT2.lsp
(alert "but is not now")

running code
(Load "BUTT2.lsp")
execution stops at alert

A man who never made a mistake never made anything