Message 1 of 10
Command Options in AutoLISP

Not applicable
12-02-2016
09:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey community, so I'm diving into (getkword) and playing with it in a command that prompts the user for point elevation information and calculates the slope/vertical change/etc between two points.
It's not all complete, but when I try testing it I receive that my (setq *op*) has too few arguments, but when I test each line, I get the right return values.
General process for this command prompts the user for a point and elevation value. Then the user has some options/combinations of specifying percent slope, distance, elevation, or vertical change. It's a work in progress, but these conditionals are just setting variables to be used for the return values and seem to be tripping up somehow.
Any help is appreciated!
(defun c:gtools () (setq clty (getvar 'celtype) ccol (getvar 'cecolor) clay (getvar 'clayer) dims (if (= (getvar 'measurement) 0) "2017" "2017-M" ) dimb (strcat @blk "dim_p_" dims ".dwg") ) (if (not *ffe*) (setq *ffe* 0.00)) ;default FFE (if (not *elv*) (setq *ffe* 0.00)) ;default elevation @ first point (if (not *elv2*) (setq *elv* 0.00)) ;default elevation @ second point (if (not *m*) (setq *m* 2)) ;default percent slope (if (not *run*) (setq *run* 6)) ;default run distance (if (not *vrt*) (setq *vrt* (* *run* (/ *m* 100)))) ;default vertical change (if (not *op*) (setq *op* "eXit")) ;default option value (if (not *mld*) (setq *mld* "None")) ;default leader option (if (not *ans*) (setq *ans* "Yes")) ;default erase last option (if (not *mem*) (setq *mem* "Yes")) ;default memory option (if (tblsearch "style" dims) (command "-dimstyle" "r" dims) (progn (command "-insert" dimb "0,0" "1" "1" "0") (command "erase" "l" "") (command "-dimstyle" "r" dims) ) ) (initget 128 "Options") (setq pt (getpoint (strcat "\nSelect first point or [Options] < >: "))) (cond ((= pt "Options") (initget "eleVation Slope Distance Leader Erase Memory eXit") (setq *op* (cond ((getkword (strcat "\nSet default value for [eleVation/Slope/Distance/Leader/Erase/Memory/eXit] <" *op* ">: "))) (*op*))) )) (cond ((= *op* "eleVation") (initget 128 "Back") (setq *ffe* (cond ((getkword (strcat "\nSet default elevation (FFE) or [Back] <" *ffe* ">: "))) (*ffe*))) ) ((= *op* "Slope") (initget 128 "Back") (setq *m* (cond ((getkword (strcat "\nSet default percent slope or [Back] <" *m* "%>: "))) (*m*))) ) ((= *op* "Distance") (initget 128 "Back") (setq *run* (cond ((getkword (strcat "\nSet default run or [Back] <" *run* ">: "))) (*run*))) ) ((= *op* "Leader") (initget "Leader Spot None Back") (setq *mld* (cond ((getkword (strcat "\nSelect default leader type [Leader/Spot/None/Back] <" *mld* ">: "))) (*mld*))) ) ((= *op* "Erase") (initget "Yes No Back") (setq *ans* (cond ((getkword (strcat "\nErase slope line? [Yes/No/Back] <" *ans* ">: "))) (*ans*))) ) ((= *op* "Memory") (initget "Yes No Back") (setq *mem* (cond ((getkword (strcat "\nRemember erase last? [Yes/No/Back] <" *mem* ">: "))) (*mem*))) ) ((= *op* "eXit") (initget 128 "Options") (setq pt (getpoint "\nSelect first point or [Options] < >: ")) ) ) (cond ((= *ffe* "Back") (initget "eleVation Slope Distance Leader Erase Memory eXit") (setq *op* (cond ((getkword (strcat "\nSet default value for [eleVation/Slope/Distance/Leader/Erase/Memory/eXit] <" *op* ">: ")))) (*op*)) ) ((= *m* "Back") (initget "eleVation Slope Distance Leader Erase Memory eXit") (setq *op* (cond ((getkword (strcat "\nSet default value for [eleVation/Slope/Distance/Leader/Erase/Memory/eXit] <" *op* ">: "))) (*op*))) ) ((= *run* "Back") (initget "eleVation Slope Distance Leader Erase Memory eXit") (setq *op* (cond ((getkword (strcat "\nSet default value for [eleVation/Slope/Distance/Leader/Erase/Memory/eXit] <" *op* ">: "))) (*op*))) ) ((= *mld* "Back") (initget "eleVation Slope Distance Leader Erase Memory eXit") (setq *op* (cond ((getkword (strcat "\nSet default value for [eleVation/Slope/Distance/Leader/Erase/Memory/eXit] <" *op* ">: "))) (*op*))) ) ((= *ans* "Back") (initget "eleVation Slope Distance Leader Erase Memory eXit") (setq *op* (cond ((getkword (strcat "\nSet default value for [eleVation/Slope/Distance/Leader/Erase/Memory/eXit] <" *op* ">: "))) (*op*))) ) ((= *mem* "Back") (initget "eleVation Slope Distance Leader Erase Memory eXit") (setq *op* (cond ((getkword (strcat "\nSet default value for [eleVation/Slope/Distance/Leader/Erase/Memory/eXit] <" *op* ">: "))) (*op*))) ) );;end options ;;begin second point (cond ((numberp pt) (initget 128 "Ffe") (setq *elv* (cond ((getkword (strcat "\nEnter elevation at first point or [Ffe] <" *elv* ">: "))) (*elv*))) (initget 128 "Run Vertical Slope") (setq pt2 (getpoint (strcat "\nSelect second point or enter [Run/Vertical change/Slope] < >: "))) ) ((= pt2 "Run") (initget 128 "Back") (setq *run* (cond ((getkword (strcat "\nEnter run distance or [Back] <" *run* ">: "))) (*run*))) ) ((numberp *run*) (setvar 'celtype "HIDDEN2") (setvar 'cecolor "20") (command "circle" pt *run*) (setq cir (entlast)) (initcommandversion) (command "dimradius" cir) (while (> (getvar 'cmdactive) 0) (command pause) ) (initget 128 "Ffe") (setq *elv2* (cond ((getkword (strcat "\nEnter elevation at second point or [Ffe] <" *elv2* ">: "))) (*elv2*)) *vrt* (- *elv* *elv2*) dimt (strcat *run* " @ " *m* " <" *vrt* ">") entd (subst (cons 1 dimt) (assoc 1 entd) entd) ) (entmod entd) ) ((= *run* "Back") (initget 128 "Run Vertical Slope") (setq pt2 (getpoint (strcat "\nSelect second point or enter [Run/Vertical change/Slope] < >: "))) ) ((= pt2 "Vertical") (initget 128 "Back") (setq *vrt* (cond ((getkword (strcat "\nEnter vertical change or [Back] <" *vrt* ">: "))) (*vrt*))) ) ((= pt2 "Slope") ) ((numberp pt2) (initget 128 "Verical Elevation") (setq *run* (getdist (list pt pt2)) *m* (cond ((getkword (strcat "\nEnter percent slope or [Vertical change/Elevation] <" *m* "%>: "))) (*m*)) ) ) ((= *m* "Vertical") (initget 128 "Back") (setq *vrt* (cond ((getkword (strcat "\nEnter vertical change or [Back] <" *vrt* ">: "))) (*vrt*)) *m* (/ *vrt* *run* ) ) ) ((= *vrt* "Back") (initget 128 "Vertical Elevation") (setq *run* (getdist (list pt pt2)) *m* (cond ((getkword (strcat "\nEnter percent slope or [Vertical change/Elevation] <" *m* "%>: "))) (*m*)) ) ) ((= *m* "Elevation") (initget 128 "Back") (setq *elv2* (cond ((getkword (strcat "\nEnter elevation at second point or [Back] <" *elv2* ">: "))) (*elv2*)) *vrt* (- *elv* *elv2*) ) ) ((= *elv2* "Back") (initget 128 "Vertical Elevation") (setq *m* (cond ((getkword (strcat "\nEnter percent slope or [Vertical change/Elevation] <" *m* "%>: "))) (*m*)) ) ) );;end cond (setvar 'celtype clty) (setvar 'cecolor ccol) (setvar 'clayer clay) );end defun
Thanks,