Author Topic: Can you call a lisp routine/function from within a lisp?  (Read 3817 times)

0 Members and 1 Guest are viewing this topic.

stsevedallas

  • Guest
Can you call a lisp routine/function from within a lisp?
« on: April 18, 2006, 10:44:59 PM »
Can you call a lisp routine/function from within a lisp?

I have a function that I defined in another routine.
We'll call it "update"...type update at the command line in autocad to execute the routine
I want to use it, then save the drawing.
Autocad does not want to let me do the following.  Why?  How can I correct this?

(defun c:s (/)
(command "update")
(command "qsave")
(princ))

Thanks in advance.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Can you call a lisp routine/function from within a lisp?
« Reply #1 on: April 18, 2006, 10:50:29 PM »
Code: [Select]
(defun c:Woot ( )
    (princ "Woot!")
    (princ)
)

Code: [Select]
(defun c:Test ( )
    (c:Woot)
)

command: Test <enter>

Woot!
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Can you call a lisp routine/function from within a lisp?
« Reply #2 on: April 18, 2006, 11:32:47 PM »
Here is another way to handle your situation.

Code: [Select]
;;  call this from the command line
(defun c:cmdlinesave()
  (lispsave)
  (princ)
  )

;; call this from your lisp
(defun lispsave ()
 (command "update")
 (command "qsave")
 (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
« Last Edit: April 19, 2006, 12:42:46 AM by Slim »
I drink beer and I know things....

stsevedallas

  • Guest
Re: Can you call a lisp routine/function from within a lisp?
« Reply #4 on: April 19, 2006, 09:08:25 AM »
OK...I modified things, so...
Here is the entire lisp routine.
Can someone tell me why this error comes up?
-->Error: no function definition: ARJODATE

Code: [Select]
;;  call this from the command line
(defun c:s ()
  (arjodate)
  (command "qsave")
  (princ)
  )
;; call this from your lisp
;;(defun lispsave ()
;;(command "arjodate")
;;(command "qsave")
;;(princ)
;;)
;;the arjodate function
(defun udate ( / d ct cd lin dp dn txt en e1 e ne oe)
   (setq d (rtos (getvar "cdate") 2 6))  ;get the current date and time
   (setq ct (strcat (substr d 10 2) ":" (substr d 12 2) ":" (substr d 14 2)))
   (setq cd (strcat (substr d 5 2) "/" (substr d 7 2) "/" (substr d 1 4)))
   (setq lin (getvar "LOGINNAME")
         dn (getvar "DWGNAME")
   )
   (setq txt (strcat "LAST UPDATED: "dn " - by: " lin " on " cd " @ " ct))
   (setq en (ssname e1l 0))
   (setq e1 (entnext en))   ;get the attribute
   (setq ne (cons 1 txt))   ;create the new attribute assoc list
   (setq e (entget e1))     ;get the attribute name for the attribute
   (setq oe (assoc 1 e))    ;get the attribute assoc list
   (setq e (subst ne oe e)) ;substitute new list for old list
           (entmod e)       ;modify the attribute
  (entupd e1)               ;update the block
   (princ)
   (princ "\n.......... arjodate block has been updated ..............")
   (princ)
)
;
(defun C:arjodate ( / e1l)
;  (grtext -1 "      LISP ROUTINE BY AJ  ")
  (if (= (tblsearch "BLOCK" "arjodate") nil)
   (progn
    (prompt "\n...... arjodate block NOT FOUND in current dwg database ....")
    (prompt "\nPick block insertion point: ")
    (command "INSERT" "arjodate" "1.25,1,0" "2" "" "")
   )
  )
   (setq e1l (ssget "x" '((0 . "INSERT")(2 . "arjodate"))));FIND THE BLOCK
 (if e1l
   (udate)
    (progn
     (princ ".......... arjodate block needs to be inserted ..............")
     (prompt "\nPick block insertion point: ")
     (command "INSERT" "arjodate" "1.25,1,0" "2" "" "")
     (setq e1l (ssget "L"))
     (udate)
   )
 )
   (princ)
)
;........end of file

<code tags added>
« Last Edit: April 19, 2006, 11:38:08 AM by CAB »

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Re: Can you call a lisp routine/function from within a lisp?
« Reply #5 on: April 19, 2006, 09:35:01 AM »
OK...I modified things, so...
Here is the entire lisp routine.
Can someone tell me why this error comes up?
-->Error: no function definition: ARJODATE

;;  call this from the command line
(defun c:s ()
(c:arjodate)
  (command "qsave")
  (princ)
  )
;; call this from your lisp
;;(defun lispsave ()
;;(command "arjodate")
;;(command "qsave")
;;(princ)
;;)
;;the arjodate function
(defun udate ( / d ct cd lin dp dn txt en e1 e ne oe)
   (setq d (rtos (getvar "cdate") 2 6))  ;get the current date and time
   (setq ct (strcat (substr d 10 2) ":" (substr d 12 2) ":" (substr d 14 2)))
   (setq cd (strcat (substr d 5 2) "/" (substr d 7 2) "/" (substr d 1 4)))
   (setq lin (getvar "LOGINNAME")
         dn (getvar "DWGNAME")
   )
   (setq txt (strcat "LAST UPDATED: "dn " - by: " lin " on " cd " @ " ct))
   (setq en (ssname e1l 0))
   (setq e1 (entnext en))   ;get the attribute
   (setq ne (cons 1 txt))   ;create the new attribute assoc list
   (setq e (entget e1))     ;get the attribute name for the attribute
   (setq oe (assoc 1 e))    ;get the attribute assoc list
   (setq e (subst ne oe e)) ;substitute new list for old list
           (entmod e)       ;modify the attribute
  (entupd e1)               ;update the block
   (princ)
   (princ "\n.......... arjodate block has been updated ..............")
   (princ)
)
;
(defun C:arjodate ( / e1l)
;  (grtext -1 "      LISP ROUTINE BY AJ  ")
  (if (= (tblsearch "BLOCK" "arjodate") nil)
   (progn
    (prompt "\n...... arjodate block NOT FOUND in current dwg database ....")
    (prompt "\nPick block insertion point: ")
    (command "INSERT" "arjodate" "1.25,1,0" "2" "" "")
   )
  )
   (setq e1l (ssget "x" '((0 . "INSERT")(2 . "arjodate"))));FIND THE BLOCK
 (if e1l
   (udate)
    (progn
     (princ ".......... arjodate block needs to be inserted ..............")
     (prompt "\nPick block insertion point: ")
     (command "INSERT" "arjodate" "1.25,1,0" "2" "" "")
     (setq e1l (ssget "L"))
     (udate)
   )
 )
   (princ)
)
;........end of file


Try that...  :-)
I drink beer and I know things....

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Can you call a lisp routine/function from within a lisp?
« Reply #6 on: April 19, 2006, 09:36:03 AM »
Short answer --

Since it's defined thusly --

Code: [Select]
(defun c:Arjodate ( / e1l) ...)
She gotta be called same --

Code: [Select]
(defun c:s ()
    (c:Arjodate)
    (command "qsave")
    (princ)
)

Edit: What Slim said!
« Last Edit: April 19, 2006, 09:39:35 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

stsevedallas

  • Guest
Re: Can you call a lisp routine/function from within a lisp?
« Reply #7 on: April 19, 2006, 11:34:18 AM »
Got it.
Thanks all.