Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lsp to choose what command

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
306 Views, 12 Replies

lsp to choose what command

i started to write a lsp to choose which command i want to launch

(DEFUN C:12 ()
(SETVAR "CMDECHO" 0)
(INITGET 1 "1 2")
(SETQ CP (GETKWORD "\nDO YOU WISH TO DO (C P) -"))
(IF (= CP "1")
(load "file.lsp")_1_
)
(IF (= CP "2")
(load "file.lsp")_2_
)

but its not working, what am i missing?
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: Anonymous

You are only loading the lisp files not executing the function. Add the name of the commands after the load, and you might want to use cond instead of if. To use a lisp funcion from another lisp you must write it like (c:LispName).

Hope that helps.
Tim
Message 3 of 13
Anonymous
in reply to: Anonymous

go slow im still learning lol

(INITGET 1 "1 2")
(SETQ CP (GETKWORD "\nDO YOU WISH TO DO (1 2) -"))
(IF (= CP "1")
(load "file.lsp")
(c:file)

after i run this, is craps out Message was edited by: andrew_nao
Message 4 of 13
Anonymous
in reply to: Anonymous

(DEFUN C:12 ()
(load "file.lsp")
(SETVAR "CMDECHO" 0)
(INITGET 1 "1 2")
(SETQ CP (GETKWORD "\nDO YOU WISH TO DO (C P) -"))
(IF (= CP "1")
(c:1)
(c:2)
)
)
Message 5 of 13
Anonymous
in reply to: Anonymous

I THINK THE _1_ AND _2_ ARE NOT ALLOWED.
I DID NOT TEST IT OTHERWISE.
ALEX



wrote in message news:4920026@discussion.autodesk.com...
i started to write a lsp to choose which command i want to launch

(DEFUN C:12 ()
(SETVAR "CMDECHO" 0)
(INITGET 1 "1 2")
(SETQ CP (GETKWORD "\nDO YOU WISH TO DO (C P) -"))
(IF (= CP "1")
(load "file.lsp")_1_
)
(IF (= CP "2")
(load "file.lsp")_2_
)

but its not working, what am i missing?
Message 6 of 13
Anonymous
in reply to: Anonymous

got it working thanks all

here is what i did if anyone needs this option in the future

(DEFUN C:cho ()
(SETVAR "CMDECHO" 0)
(INITGET 1 "A B")
(SETQ CP (GETKWORD "\nDO YOU WISH TO DO (A B) -"))
(IF (= CP "A") (PROGN
(load "filename.lsp")
(c:file);
)
)

(IF (= CP "B") (PROGN
(load "filename.lsp")
(c:file)
)
)
) Message was edited by: andrew_nao
Message 7 of 13
Anonymous
in reply to: Anonymous

For what it's worth, you don't need both if statements. One will do.

(DEFUN C:cho ()
(SETVAR "CMDECHO" 0)
(INITGET 1 "A B")
(SETQ CP (GETKWORD "\nDO YOU WISH TO DO (A B) -"))
(IF (= CP "A")
(PROGN
(load "filename.lsp")
(c:file);
)
(PROGN
(load "filename.lsp")
(c:file)
)
)
)

wrote in message news:4920088@discussion.autodesk.com...
got it working thanks all

here is what i did if anyone needs this option in the future

(DEFUN C:cho ()
(SETVAR "CMDECHO" 0)
(INITGET 1 "A B")
(SETQ CP (GETKWORD "\nDO YOU WISH TO DO (A B) -"))
(IF (= CP "A") (PROGN
(load "filename.lsp")
(c:file);
)
)

(IF (= CP "B") (PROGN
(load "filename.lsp")
(c:file)
)
)
)

Message was edited by: andrew_nao
Message 8 of 13
Anonymous
in reply to: Anonymous

You should format that string to match normal AutoCAD strings too:

"\nDo you wish to do? [A/B]: "

This will give you right-click options.

--
R. Robert Bell


"Jim Claypool" wrote in message
news:4920172@discussion.autodesk.com...
For what it's worth, you don't need both if statements. One will do.

(DEFUN C:cho ()
(SETVAR "CMDECHO" 0)
(INITGET 1 "A B")
(SETQ CP (GETKWORD "\nDO YOU WISH TO DO (A B) -"))
(IF (= CP "A")
(PROGN
(load "filename.lsp")
(c:file);
)
(PROGN
(load "filename.lsp")
(c:file)
)
)
)

wrote in message news:4920088@discussion.autodesk.com...
got it working thanks all

here is what i did if anyone needs this option in the future

(DEFUN C:cho ()
(SETVAR "CMDECHO" 0)
(INITGET 1 "A B")
(SETQ CP (GETKWORD "\nDO YOU WISH TO DO (A B) -"))
(IF (= CP "A") (PROGN
(load "filename.lsp")
(c:file);
)
)

(IF (= CP "B") (PROGN
(load "filename.lsp")
(c:file)
)
)
)

Message was edited by: andrew_nao
Message 9 of 13
Anonymous
in reply to: Anonymous

huh? how does right click options work like that?
Message 10 of 13
Anonymous
in reply to: Anonymous

Try it at the command line:

Command: (initget "A B")
nil
Command: (getkword "\nDo you wish to do? [A/B]: ")
Do you wish to do? [A/B]:

Right-click at this point and you will see your options. In 2006 with
DynInp, you wil see the options *without* a right-click!



--
R. Robert Bell


wrote in message news:4920249@discussion.autodesk.com...
huh? how does right click options work like that?
Message 11 of 13
Anonymous
in reply to: Anonymous

wow thats neat stuff is there limits to something like this?
ill have to cycle thru my files and see what else i can use that one

neat one thanks for sharing
Message 12 of 13
Anonymous
in reply to: Anonymous

As Jim said, and as I showed in my earlier post, you don't need two IF's to handle an either/or situation. You are only allowing two possible responses, so you only need one IF test. If it's not one possibility, then it must be the other.

Tim suggested that you might use COND instead of IF, but that would only be necessary if there were more than two possible choices.
Message 13 of 13
Anonymous
in reply to: Anonymous

You should also use angle brackets to specify the default, where
appropriate, e.g.:

(initget "Yes No")
(getkword "\nDelete all files? [No/Yes] : ")


--
R. Robert Bell


wrote in message news:4920277@discussion.autodesk.com...
wow thats neat stuff is there limits to something like this?
ill have to cycle thru my files and see what else i can use that one

neat one thanks for sharing

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost