lisp question

ok, i'm feeling like a noobie.

once upon a time i had written a lisp program i called ten-key, that let me switch views and ucs's using the ten-key pad.

for example 5 is the plan view, 1 is an iso/angled view and so on.

i've rewritten it the best i can remember from scratch(no longer have a copy of the original).

i load it with on_start.lsp (used icad.lsp/acad.lsp in past)

i went into the settings and checked to load on_start.lsp

no errors at start up, but when i hit a key and enter it just returns "nil"

 

copy/pasted on_start.lsp

;this file will run once when the program starts.

(defun s:startup ()
(alert “Initializing on_start.lsp”)

(setvar “textsize” 0.125)
(setvar “dimtxt” 0.125)
(princ)
)


; Zooms

(defun C:+ () (command “zoom” “w”))

(defun C:- () (command “zoom” “p”))

(defun C:00 () (command “zoom” “e”))


; UCSs
(defun C:* () (command “ucs” “v”))

(defun C:/ () (command “ucs” “e”))

(defun C:** () (command “ucs” “w”))


;plan view
(defun C:5 () (command “vpoint” “plan”))

;front view
(defun C:2 () (command “vpoint” “0,-1,0”))

;l/h view
(defun C:4 () (command “vpoint” “-1,0,0”))

;r/h view
(defun C:6 () (command “vpoint” “1,0,0”))

;back view
(defun C:8 () (command “vpoint” “0,1,0”))

;iso left
(defun C:1 () (command “vpoint” “-1,-1,1”))

at the commandline i get:

: 5
nil
: 1
nil
: 2
nil
: 4
nil
: 6
nil
: 8
nil
: 3

Unable to recognize command "3". Please try again.
: 00
nil

i through in 3 just because i knew it wasn't defined yet.

what am i missing?

 

Comments

  • Hi Keith,

    To get this working you need to provide the VPOINT command with a direction vector in the form (X Y Z) to do this you use the quote key to pass the command a literal list e.g. '(X Y Z). If you try the following you should find it works

     

    ;TEN-KEY.LSP
    ; note (prin1) makes a quiet exit, wont see the nil

    ; Zooms
    (defun C:+ () (command "zoom" "w") (prin1))
    (defun C:- () (command "zoom" "p")(prin1))
    (defun C:00 () (command "zoom" "e")(prin1))

    ; UCSs
    (defun C:* () (command "UCS" "V")(prin1))
    (defun C:/ () (command "UCS" "E")(prin1))
    (defun C:** () (command "UCS" "W")(prin1))

    ;plan view
    (defun C:5 () (command "PLAN" "")(prin1))
    ;front view
    (defun C:2 () (command "VPOINT" '(0.0 -1.0 0.0))(prin1))
    ;l/h view
    (defun C:4 () (command "VPOINT" '(-1.0 0.0 0.0))(prin1))
    ;r/h view
    (defun C:6 () (command "VPOINT" '(1.0 0.0 0.0))(prin1))
    ;back view
    (defun C:8 () (command "VPOINT" '(0.0 1.0 0.0))(prin1))
    ;iso left
    (defun C:1 () (command "VPOINT" '(-1.0 -1.0 1.0))(prin1))

     

    I would recommend that you use on_doc_load.lsp instead of on_start.lsp. on_doc_load.lsp gets loaded each time you open a drawing, which is what you need to get your routines loaded. On_start.lsp only loads at startup (unless you configure otherwise). Also I would place your Ten-Key.lsp in its own file and use the Load function to load it in on_doc_load.lsp to make it look like this:

    ; on_doc_load.lsp
    ; this file will run when a drawing is loaded.
    (defun S::startup ()
    (princ "\nInitializing on_doc_load.lsp")
    (setvar "textsize" 0.125)
    (setvar "dimtxt" 0.125)
    (load "Ten-Key") ; load my quick keys
    (prin1)
    )

    I wouldn't generally advice that you define commands like the ones that you have used in Ten-Key. While they work they may cause some unexpected results with other commands. I suggest you look at the following alternatives:

    • Explore the default key press assignments. For instance double click the middle button on the mouse, or wheel does a ZOOM EXTENTS. Holding this button down an you can PAN instead. Check out Bricscad for AutoCAD users for full key listings.
    • Explore the CUI. You could create a partial menu file in which you can assign custom macros to keys.
    • You could use a gaming keyboard to create macros for use in Bricscad. The advantage of this is that you are guaranteed these keys haven't already been assigned to some other function. Details on how this works is on my website.

     

    Regards,

    Jason Bourhill

    CAD Concepts

  • Hi Keith,

    forgot to say you appear to be using “” speech marks instead of "" speech marks (it may actually be how the forum formats text). This may interfere with commands being interpreted correctly. e.g.:

    (command "zoom" "e") ; will work

    (command “zoom” “e”); may not

    Regards,

    Jason Bourhill

    CAD Concepts

  • that worked, thanks

This discussion has been closed.