TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: stsevedallas 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.
-
(defun c:Woot ( )
(princ "Woot!")
(princ)
)
(defun c:Test ( )
(c:Woot)
)
command: Test <enter>
Woot!
-
Here is another way to handle your situation.
;; call this from the command line
(defun c:cmdlinesave()
(lispsave)
(princ)
)
;; call this from your lisp
(defun lispsave ()
(command "update")
(command "qsave")
(princ)
)
-
Woot!
Woot! (http://www.theswamp.org/lilly_pond/index.php?dir=slim/&file=Woot_Emoticon.gif)
-
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 ()
(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>
-
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... :-)
-
Short answer --
Since it's defined thusly --
(defun c:Arjodate ( / e1l) ...)
She gotta be called same --
(defun c:s ()
(c:Arjodate)
(command "qsave")
(princ)
)
Edit: What Slim said!
-
Got it.
Thanks all.