TheSwamp
CAD Forums => CAD General => Topic started by: AVCAD on November 12, 2004, 01:58:54 PM
-
I am working on a simple lisp routine to draw a line. NOthing special. I just want it to ask if the line is for Audio or Video.
Depending on the Input A or V it would draw a line on a differant layer.
Here is my Code so far. TO me it looks like it should work but after I put the Input it the comman just stops..Anyhelp would be great.
(defun C:wire ()
(setq P (getSTRING "(A)udio or (V)ideo: ")))
(IF P (= A (command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "" "LINE" "")))
(IF P (= V (command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "" "LINE" "")))
-
Try this
(defun C:wire ()
(setq P (getSTRING "(A)udio or (V)ideo: "))
(IF (= P "A")(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "" "LINE" ""))
(IF (= P "V")(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "" "LINE" ""))
)
-
this just gives me a NIL
it still doesnt finish the command
-
which is what is should ... but you will have the settings you specify, but keep in mind it is only checking for a capital letter.
-
Couldn't you make specific commands for each type of line you're using?? say something like this:
(defun C:AL ()
(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "" "LINE" "")
)
and then:
(defun C:VL ()
(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "V-WIRING" "C" "RED" "" "" "" "LINE" "")
)
This way, you type either AL or VL and you're on the correct layer and everything. Then, we can step a little farther and do something along these lines:
(defun C:VL ()
(setq cl (getvar "clayer") ;current layer
cc (getvar "cecolor") ;current color
)
(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "V-WIRING" "C" "RED" "" "" "" "LINE" "")
(if (/= cl)(command "LAYER" "S" cl ""))
(if (/= cc)(command "COLOR" cc))
(princ)
)
where in this one will remember the layer you were on before you started the VL command and switch back to it when you complete the command. The same thing can be done for the ortho and snap settings if you want.
This is the neat thing about Lisp.. You can ask 10 different programmers and they'll come up with 12 different ways (We ALL know Keith and CAD will both submit at least 2 different ways :D )
Hope this gives you inspiration.
-
OK..COOL. I guess I was on the right track.
I got it to work with either lowercase and upper.
Command:
WIRE (A)udio or (V)ideo: A
Unknown command "WIRE". Press F1 for help.
Unknown command "WIRE". Press F1 for help.
nil
Specify first point:
Specify next point or [Undo]:
Specify next point or [Undo]:
How do i get rid of the Unknown command "WIRE". Press F1 for help.
Unknown command "WIRE". Press F1 for help.
nil
on the command line when this is ran??
Here is teh code I am using again.
(defun C:wire ()
(setq P (getSTRING "(A)udio or (V)ideo: "))
(IF (= P "A")(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "" "LINE" ))
(IF (= P "V")(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "" "LINE" ))
(IF (= P "a")(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "" "LINE" ))
(IF (= P "v")(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "" "LINE" ))
(IF (= P "audio")(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "" "LINE" ))
(IF (= P "video")(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "" "LINE" ))
(IF (= P "AUDIO")(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "" "LINE" ))
(IF (= P "VIDEO")(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "" "LINE" ))
)
Thanks for the help.
-
In response to PDL's Post..
I thought about having a seperate command but...this iwll be used my multiple people and I would rather have one command that asks what line they want. This way there is less of a chance for them to screw up and use the wrong line.
But it is an Idea with the saving the previous layer and such..I will look in to incorporating it. Although I am not taht great at wrinting my own lisp files I am very much a Novice at it.
I usually read over and over and over again others lisps and try to figure oiut what the hell is going on in it and then I try to incorporate it. I figure If I can get it to work I must understand it.
Thanks for Help!
-
All you really need to do is a little cut and pasting.. The two lines after the defun line are the ones that remember the settings, the two at the end are the ones that restore the settings. The Osnap and the snap setting you had are similar but different.. (Ahh, a Yogi Berraism..)
-
that is because of an extra blank entry in the command sequence. Likely behind the ortho command
-
How about something like this?
(defun C:wire ()
(initget "Audio Video"); gets a or v
(setq P (getkword "(A)udio or (V)ideo: <A>"))
;; returns "Audio" or "Video" or nil
;; default to Audio
(command "ORTHO" "ON" "" "SNAP" ".25")
(if (= p "Video")
(command "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "")
(command "-LAYER" "M" "A-WIRING" "C" "RED" "" "")
)
(command "LINE" )
)
-
You could also do this:
(defun wire (typ)
(command "ORTHO" "ON" "" "SNAP" ".25")
(if (= typ "Video")
(command "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "")
(command "-LAYER" "M" "A-WIRING" "C" "RED" "" "")
)
(command "LINE" )
)
(defun C:wireA ()
(wire "Audio")
)
(defun C:wireV ()
(wire "Video")
)
-
What am I doing wrong here? I saw the code examples and wanted to combine 3 lisps that I use. It doesn't use the options though.
(defun c:bb () ;used for inserting bubbler laterals
(setvar 'plinegen 1)
(initget "Tree Shrub Bub") ; gets a or v
(setq P (getSTRING "(T)ree or (S)hrub or (B)ub Lateral: <T>"))
(if (= p "Tree")
(setvar 'plinewid (* (getvar "dimscale") 0.05))
(command ".-layer" "make" "0280-tree-lateral"
"l" "hidden2" "" "color"
"4" "" "" "pline"
)
)
(if (= p "Shrub")
(setvar 'plinewid (* (getvar "dimscale") 0.0125))
(command ".-layer" "make" "0280-shrub-lateral"
"color" "6" ""
"" "pline"
)
)
(if (= p "Bub")
(setvar 'plinewid (* (getvar "dimscale") 0.0))
(command ".-layer" "make" "0280-bub-lateral"
"l" "hidden2" "" "color"
"5" "" "" "pline"
)
)
)
Thanks,
Ron
-
i was playing around with these lisps trying to apply them to my discipline. i was thinking i could also make a button something like this but is there anyway to pause for user input? here' my attempts:
Button:
(setq var (getvar "clayer"));(command "-layer" "n" "0-GLASS" "c" "CYAN" "0-GLASS" ) ;setvar clayer "0-GLASS";orthomode;1;snap;.25;line;\;_LayerP
(defun recc (typ)
(command "ORTHO""ON" "" "SNAP" ".25")
(if (= typ "Glass")
(command "-LAYER" "M" "0-GLASS" "C" "Cyan" "" "" "" )
(command "-LAYER" "M" "0-STAINLESS STEEL" "C" "Yellow" "" "" "")
)
(command "Rectangle" )
)
(defun C:SS ()
(recc "Stainless Steel")
)
(defun C:G ()
(recc "Glass")
)
(defun C:LL ()
(initget "Glass Stainless Steel"); gets G or S
(setq P (getSTRING "(G)lass or (S)tainless Steel: <G>"))
;; returns "Glass" or "Stainless Steel" or nil
;; default to Glass
(command "ORTHO" "ON" "" "SNAP" ".25")
(if (= p "Stainless Steel")
(command "-LAYER" "M" "0-GLASS" "C" "CYAN" "" "" "" )
(command "-LAYER" "M" "0-STAINLESS STEEL" "C" "YELLOW" "" "" "")
)
(command "LINE" )
)
-
by the way here's the behavior or misbehavior i get: it is changing to stainless steel layer no matter what. also i'm getting the unknown command. pretty cool toy though interesting
Command: ll
(G)lass or (S)tainless Steel: <G>
ORTHO Enter mode [ON/OFF] <ON>: ON
Command: LL Unknown command "LL". Press F1 for help.
Command: SNAP
Specify snap spacing or [ON/OFF/Aspect/Rotate/Style/Type] <0'-0 1/4">: .25
Command: -LAYER
Current layer: "0-GLASS"
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
M
Enter name for new layer (becomes the current layer) <0-GLASS>: 0-STAINLESS
STEEL Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
C
Enter color name or number (1-255): YELLOW
Enter name list of layer(s) for color 2 (yellow) <0-STAINLESS STEEL>: Enter an
option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
Command: LL Unknown command "LL". Press F1 for help.
Command: LINE Specify first point: nil
Specify first point:
-
(defun recc (typ)
(command "ORTHO""ON" "" "SNAP" ".25")
(if (= typ "Glass")
(command "-LAYER" "M" "0-GLASS" "C" "Cyan" "" "" "" )
(command "-LAYER" "M" "0-STAINLESS STEEL" "C" "Yellow" "" "" "")
)
(command "Rectangle" )
)
(defun C:SS ()
(recc "Stainless Steel")
)
(defun C:G ()
(recc "Glass")
)
(defun C:LL ()
(initget "Glass Stainless Steel"); gets G or S
(setq P (getSTRING "(G)lass or (S)tainless Steel: <G>"))
;; returns "Glass" or "Stainless Steel" or nil
;; default to Glass
(command "ORTHO" "ON" "" "SNAP" ".25")
(if (= p "Stainless Steel")
(command "-LAYER" "M" "0-GLASS" "C" "CYAN" "" "" "" )
(command "-LAYER" "M" "0-STAINLESS STEEL" "C" "YELLOW" "" "" "")
)
(command "LINE" )
)
Too many "" following the layer command.
-
WOOHOOO!! IT WORKS...
Here is the Code if anyone is intrested.
;Creates a line on a specified layer for Audio/Video Signal Flows
;Layer's are chosen by either typing "A, Audio, V, Video" in either upper or Lowercase
;in the command line when prompted.
;
;Tested in AutoCAD 2004 - Added to Button for ease of use.
;Button code:
;^C^C(LOAD "G:/CHI-CUSTOMCAD/LISP/WIRING");WIRE;
;
;www.theswamp.org
;
;Written by Philip DeCanio, for Shen Milsom & Wilke - 11-12-2004
(defun C:wire ()
(setq P (getstring "(A)udio or (V)ideo: "))
(command "ORTHO" "ON" "SNAP" ".25")
(IF (= P "A")(command "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "LINE"))
(IF (= P "V")(command "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "LINE"))
(IF (= P "a")(command "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "LINE"))
(IF (= P "v")(command "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "LINE"))
(IF (= P "audio")(command "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "LINE"))
(IF (= P "video")(command "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "LINE"))
(IF (= P "AUDIO")(command "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "LINE"))
(IF (= P "VIDEO")(command "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "LINE"))
(princ)
)
Thanks for the help everyone.
-
Avcad-
Look into the function "getkword" - it would reduce the code required by quite a bit.
Ronjop - I think "getkword" instead of "getstring" would solve your problem as well.
-
What am I doing wrong here? I saw the code examples and wanted to combine 3 lisps that I use. It doesn't use the options though.
Hi
Below snippet is from the AutoLISP Reference Help File -
<snip>
initget Function
The getstring function is the only user-input function that does not honor keywords.
</snip>
Therefore below is my humble re-working -
(defun c:bb (/ P) ;Used for inserting bubbler laterals
(setvar 'plinegen 1)
(initget 1 "Tree Shrub Bub") ;Gets T or S or B
(setq P (getkword
"\nEnter an option (T)ree or (S)hrub or (B)ub Lateral: "
)
)
(if (= P "Tree")
(progn
(setvar 'plinewid (* (getvar "dimscale") 0.05))
(command "_.-Layer" "_Make" "0280-tree-lateral"
"_L" "hidden2" "" "_Color"
"4" "" ""
)
(command "_.PLine")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
)
)
(if (= P "Shrub")
(progn
(setvar 'plinewid (* (getvar "dimscale") 0.0125))
(command "_.-Layer" "_Make" "0280-shrub-lateral"
"_Color" "6" ""
""
)
(command "_.PLine")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
)
)
(if (= P "Bub")
(progn
(setvar 'plinewid (* (getvar "dimscale") 0.0))
(command "_.-Layer" "_Make" "0280-bub-lateral"
"_L" "hidden2" "" "_Color"
"5" "" ""
)
(command "_.PLine")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
)
)
(princ)
)
Have a good one, Mike
-
Thanks guys. Works like a charm now. :)
-
I tried using the getkword function, but for some reason it I was having trouble with it so I started over and used getstring.
-
I tried using the getkword function, but for some reason it I was having trouble with it so I started over and used getstring.
Try the first code i posted, I changed it to use getkword.
-
i modified mike's but can't figure out why the stainless steel portion isn't working, any help would be great
(defun c:LLL (/ P) ;USED FOR DRAWING LINES ON CERTAIN LAYERS
(initget 1 "Glass Stainless steel Aluminum") ;Gets G or S or A
(setq P (getkword
"\nEnter an option (G)lass (S)tainless steel (A)luminum: "
)
)
(if (= P "Glass")
(progn
(command "_.-Layer" "_Make" "0-GLASS"
"_L" "CONTINUOUS" "" "_Color"
"Cyan" "" ""
)
(command "Line")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
)
)
(if (= P "Stainless steel")
(progn
(command "_.-Layer" "_Make" "0-STAINLESS STEEL"
"_L" "Continuous" "" "_Color"
"Yellow" "" ""
)
(command "Line")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
)
)
(if (= P "Aluminum")
(progn
(command "_.-Layer" "_Make" "0-ALUMINUM"
"_L" "Continuous" "" "_Color"
"Green" "" ""
)
(command "Line")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
)
)
(princ)
)
-
Keyword Specifications
The string argument is interpreted according to the following rules:
Each keyword is separated from the following keyword by one or more spaces. For example, "Width Height Depth" defines three keywords.
No Spaces allowed
-
Mike,
That is a good one. Your code is perfectly fine and very readable.
But if you don't mind here is another way to do it.
Because you use INITGET 1 the routine will not continue unless the user enters a
keyword. So with that guarantee you can use a cond stmt to test the keyword and
unlike the multiple if statements it will stop testing as soon as it finds a match.
This is just another approach. The pline code is the same for each condition so it
can be moved to a point after the condition statement and you will not need to
duplicate the code.
If you could not guarantee the keyword you could use a True condition to catch
anything that fell through. Like this
(cond
((= p "Tree")
Do Tree stuff)
((= p "Shrub")
Do Shrub stuff)
(T
(alert "Nothing to do."))
)
But you would have to use the pline code conditionally now. Like this:
(if (memeber p '("Tree" "Shrub"))
(progn
(command "_.PLine")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
)
)
Here is the code done with cond statement
(defun c:bb (/ p) ;Used for inserting bubbler laterals
(setvar 'plinegen 1)
(initget 1 "Tree Shrub Bub") ;Gets T or S or B
(setq p (getkword
"\nEnter an option (T)ree or (S)hrub or (B)ub Lateral: "
)
)
(cond
((= p "Tree")
(setvar 'plinewid (* (getvar "dimscale") 0.05))
(command "_.-Layer" "_Make" "0280-tree-lateral" "_L" "hidden2" "" "_Color" "4" "" "")
)
((= p "Shrub")
(setvar 'plinewid (* (getvar "dimscale") 0.0125))
(command "_.-Layer" "_Make" "0280-shrub-lateral" "_Color" "6" "" "")
)
((= p "Bub")
(setvar 'plinewid (* (getvar "dimscale") 0.0))
(command "_.-Layer" "_Make" "0280-bub-lateral" "_L" "hidden2" "" "_Color" "5" "" "")
)
)
(command "_.PLine")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
(princ)
)
-
cab i suspected that was it so i took the spaces out so it read as "Stainlesssteel" but still couldn't get it to work. what spaces are you referring to?
-
I also added:
(if (tblsearch "layer" "0280-tree-lateral")
(command "-layer" "thaw" "0280-tree-lateral" "on" "0280-tree-lateral" "")
)
To thaw and turn on the layer. If the layer existed and was frozen the lisp would break since frozen layers cannot be made current.
Dan,
When I run your lisp I get a syntax error for some reason.....can't figure it out.
(defun c:drip (/ P) ;Used for inserting bubbler laterals
(setvar 'plinegen 1)
(initget 1 "Tree Shrub Bub Header Cv") ;Gets T or S or B or H or C
(setq P (getkword
"\nEnter an option (T)ree, (S)hrub, (B)ub, (H)eader, or (C)v Lateral: "
)
)
(if (= P "Tree")
(progn
(if (tblsearch "layer" "0280-tree-lateral")
(command "-layer" "thaw" "0280-tree-lateral" "on" "0280-tree-lateral" "")
)
(setvar 'plinewid (* (getvar "dimscale") 0.05))
(command "_.-Layer" "_Make" "0280-tree-lateral"
"_L" "hidden2" "" "_Color"
"4" "" ""
)
(command "_.PLine")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
)
)
(if (= P "Shrub")
(progn
(if (tblsearch "layer" "0280-shrub-lateral")
(command "-layer" "thaw" "0280-shrub-lateral" "on" "0280-shrub-lateral" "")
)
(setvar 'plinewid (* (getvar "dimscale") 0.0125))
(command "_.-Layer" "_Make" "0280-shrub-lateral"
"_Color" "6" ""
""
)
(command "_.PLine")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
)
)
(if (= P "Bub")
(progn
(if (tblsearch "layer" "0280-bub-lateral")
(command "-layer" "thaw" "0280-bub-lateral" "on" "0280-bub-lateral" "")
)
(setvar 'plinewid (* (getvar "dimscale") 0.0))
(command "_.-Layer" "_Make" "0280-bub-lateral"
"_L" "hidden2" "" "_Color"
"5" "" ""
)
(command "_.PLine")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
)
)
(if (= P "Header")
(progn
(if (tblsearch "layer" "0280-netafim_header")
(command "-layer" "thaw" "0280-netafim_header" "on" "0280-netafim_header" "")
)
(setvar 'plinewid (* (getvar "dimscale") 0.05))
(command "_.-Layer" "_Make" "0280-netafim_header"
"_L" "continuous" "" "_Color"
"white" "" ""
)
(command "_.PLine")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
)
)
(if (= P "Cv")
(progn
(if (tblsearch "layer" "0280-netafim_cv")
(command "-layer" "thaw" "0280-netafim_cv" "on" "0280-netafim_cv" "")
)
(setvar 'plinewid (* (getvar "dimscale") 0.025))
(command "_.-Layer" "_Make" "0280-netafim_cv"
"_L" "hidden2" "" "_Color"
"yellow" "" ""
)
(command "_.PLine")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
)
)
(princ)
)
Thanks for the help.
-
cab i suspected that was it so i took the spaces out so it read as "Stainlesssteel" but still couldn't get it to work. what spaces are you referring to?
The one in the initget and the test
(defun c:lll (/ p) ;USED FOR DRAWING LINES ON CERTAIN LAYERS
(initget 1 "Glass Stainlesssteel Aluminum") ;Gets G or S or A
(setq p (getkword
"\nEnter an option (G)lass (S)tainless steel (A)luminum: "
)
)
(cond
((= p "Glass")
(progn
(command "_.-Layer" "_Make" "0-GLASS" "_L" "CONTINUOUS" "" "_Color" "Cyan" "" "")
)
)
((= p "Stainlesssteel")
(progn
(command "_.-Layer" "_Make" "0-STAINLESS STEEL" "_L" "Continuous" "" "_Color" "Yellow" "" "")
)
)
((= p "Aluminum")
(progn
(command "_.-Layer" "_Make" "0-ALUMINUM" "_L" "Continuous" "" "_Color" "Green" "" "")
)
)
)
(command "Line")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
(princ)
)
-
hmmm no message here maybe i'll modify this one and get back to ya
-
cool that one works cab tanks
-
Ron
Here is another method.
(defun c:bb (/ p dimx lyr) ;Used for inserting bubbler laterals
(setvar 'plinegen 1)
(initget 1 "Tree Shrub Bub") ;Gets T or S or B
(setq p (getkword
"\nEnter an option (T)ree or (S)hrub or (B)ub Lateral: "
)
)
(cond
((= p "Tree")
(setq dimx 0.05)
(setq lyr (list "0280-tree-lateral" "_L" "hidden2" "" "_Color" "4" "" ""))
)
((= p "Shrub")
(setq dimx 0.0125)
(setq lyr (list "0280-shrub-lateral" "_Color" "6" "" ""))
)
((= p "Bub")
(setq dimx 1.0)
(setq lyr (list "0280-bub-lateral" "_L" "hidden2" "" "_Color" "5" "" ""))
)
)
(if (tblsearch "layer" (car lyr))
(command "-layer" "T" (car lyr) "ON" (car lyr) "")
(command "_.-layer" "_make" (foreach x lyr (command x)))
)
(setvar 'plinewid (* (getvar "dimscale") dimx))
(command "_.PLine")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
(princ)
)
-
cab i was trying to modify this so i could then specify which command to run, line pline or rectangle. i'm getting malformed list so am i even close to formatting this right or no? here's what i got:
(defun c:lll (/ p) ;USED FOR DRAWING LINE ON SPECIFIED LAYER
(initget 1 "Glass Stainlesssteel Aluminum") ;Gets G or S or A
(setq p (getkword
"\nEnter an option (G)lass (S)tainless steel (A)luminum: "
)
)
(cond
((= p "Glass")
(progn
(command "_.-Layer" "_Make" "0-GLASS" "_L" "CONTINUOUS" "" "_Color" "Cyan" "" "")
)
)
((= p "Stainlesssteel")
(progn
(command "_.-Layer" "_Make" "0-STAINLESS STEEL" "_L" "Continuous" "" "_Color" "Yellow" "" "")
)
)
((= p "Aluminum")
(progn
(command "_.-Layer" "_Make" "0-ALUMINUM" "_L" "Continuous" "" "_Color" "Green" "" "")
)
)
)
(initget 1 "Line Pline Rectangle") ;Gets L or P or R
(setq p (getkword
"\nEnter an option (L)ine (P)line (R)ectangle: "
)
)
(cond
((= p "Line")
(progn
(command "Line")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
(cond
((= p "Pline")
(progn
(command "Pline")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
((= p "Rectangle")
(progn
(command "Rectangle")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
(princ)
)
-
Here is another method.
Thanks CAB! :D
-
Actually you don't need this
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
If the command is the last thing the LISP does, you can return control to the ACAD command.
Like this:
(defun c:lll (/ p) ;USED FOR DRAWING LINE ON SPECIFIED LAYER
(initget 1 "Glass Stainlesssteel Aluminum") ;Gets G or S or A
(setq p (getkword
"\nEnter an option (G)lass (S)tainless steel (A)luminum: "
)
)
(cond
((= p "Glass")
(progn
(command "_.-Layer" "_Make" "0-GLASS" "_L" "CONTINUOUS" "" "_Color" "Cyan" "" "")
)
)
((= p "Stainlesssteel")
(progn
(command "_.-Layer" "_Make" "0-STAINLESS STEEL" "_L" "Continuous" "" "_Color" "Yellow" "" "")
)
)
((= p "Aluminum")
(progn
(command "_.-Layer" "_Make" "0-ALUMINUM" "_L" "Continuous" "" "_Color" "Green" "" "")
)
)
)
(initget 1 "Line Pline Rectangle") ;Gets L or P or R
(setq p (getkword
"\nEnter an option (L)ine (P)line (R)ectangle: "
)
)
(cond
((= p "Line") (command "Line"))
((= p "Pline") (command "Pline"))
((= p "Rectangle") (command "Rectangle"))
)
)
-
cab here's what i've done with the lisp. i had some toolbars for different hatches for different materials. so i've modified those and just made glass steel and aluminum toolbars which also include buttons for drawing each type line pline and rectangle pretty sweet thanks man
http://www.theswamp.org/screens/dan/NEW%20TOOLS.doc
-
can't see them very well but i think u get the idea :wink:
-
Good for you, dan
Keep it up..
-
Mike,
That is a good one. Your code is perfectly fine and very readable.
But if you don't mind here is another way to do it.
Because you use INITGET 1 the routine will not continue unless the user enters a keyword. So with that guarantee you can use a cond stmt to test the keyword and unlike the multiple if statements it will stop testing as soon as it finds a match.
This is just another approach. The pline code is the same for each condition so it can be moved to a point after the condition statement and you will not need to duplicate the code.
If you could not guarantee the keyword you could use a True condition to catch anything that fell through.
Hi CAB
I don't mind in the slightest, after all I'm no LISP Programmer.... totally agree the use of the "cond" sub is much cleaner and works much better in this situation.
Cheers, Mike