help me to add the next point entity option so i can make a contininuation for the next line with out exiting the command
Command: bdraw
Pick a starting point:
Pick bearing (1/2/3/4):
Type the length: 100
Type the degree: 20
Type the minute: 30
Type the second: 20
This is the lisp
(defun C:BDRAW ()
(setvar "cmdecho" 0)
(initget 1)
(setq PT (getpoint "\nPick a starting point: "))
(initget 1 "1 2 3 4")
(setq BR (getkword "\nPick bearing (1/2/3/4): "))
(setq OPT (strcase BR))
(initget 1)
(setq LEN (getreal "\nType the length: "))
(setq DEG (getstring "\nType the degree: ")
minx (getstring "\nType the minute: ")
SEC (getstring "\nType the second: "))
(if (= DEG "")
(setq DEG "0"))
(if (= minx "")
(setq minx "0"))
(if (= SEC "")
(setq SEC "0"))
(cond ((= "3" OPT)
(setvar "angbase" (cvunit 270 "degree" "radian"))
(setvar "angdir" 1))
((= "2" OPT)
(setvar "angbase" (cvunit 270 "degree" "radian"))
(setvar "angdir" 0))
((= "4" OPT)
(setvar "angbase" (cvunit 90 "degree" "radian"))
(setvar "angdir" 0))
((= "1" OPT)
(setvar "angbase" (cvunit 90 "degree" "radian"))
(setvar "angdir" 1)))
(command "line" PT (strcat "@" (rtos LEN) "<" DEG "d" minx "'" SEC "\"") "")
(setvar "angbase" 0)
(setvar "angdir" 0)
(setvar "cmdecho" 1)
(princ))
(princ "\nType 'BDRAW' to draw lines with bearings")
(princ)
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Maybe something like [untested]:
(defun C:BDRAW ()
(setvar "cmdecho" 0)
(initget 1)
(setq PT (getpoint "\nPick a starting point: "))
(initget "1 2 3 4"); without the 1 argument, to allow Enter
(while
(setq BR (getkword "\nPick bearing (1/2/3/4) <exit>: "))
;; hitting Enter for the <exit> default will return nil and stop the (while) loop
(setq OPT (strcase BR))
(initget 1)
(setq LEN (getreal "\nType the length: "))
(setq DEG (getstring "\nType the degree: ")
minx (getstring "\nType the minute: ")
SEC (getstring "\nType the second: ")
)
(if (= DEG "") (setq DEG "0"))
(if (= minx "") (setq minx "0"))
(if (= SEC "") (setq SEC "0"))
(cond
((= "3" OPT)
(setvar "angbase" (cvunit 270 "degree" "radian"))
(setvar "angdir" 1)
)
((= "2" OPT)
(setvar "angbase" (cvunit 270 "degree" "radian"))
(setvar "angdir" 0)
)
((= "4" OPT)
(setvar "angbase" (cvunit 90 "degree" "radian"))
(setvar "angdir" 0)
)
((= "1" OPT)
(setvar "angbase" (cvunit 90 "degree" "radian"))
(setvar "angdir" 1)
)
)
(command "line" PT (strcat "@" (rtos LEN) "<" DEG "d" minx "'" SEC "\"") "")
(setvar "angbase" 0)
(setvar "angdir" 0)
(setvar "cmdecho" 1)
(initget "1 2 3 4"); again, for (getkword) in next pass through loop
); end while
(princ)
)
(princ "\nType 'BDRAW' to draw lines with bearings")
(princ)
Whoops -- left something out:
....
(setvar "cmdecho" 1)
(setq PT (getvar 'lastpoint)); for next segment to start from
(initget "1 2 3 4"); again, for (getkword) in next pass through loop
); end while
(princ)
....
Nice Kent!
Don Ireland
Engineering Design Technician
Thanks KENT..do you have ebooks for begginers like me i just want to learn more about lisp programming?
Don Ireland
Engineering Design Technician
one last question how about if the command is
command: bdraw
pick a starting point:
Pick bearing (1/2/3/4):
Type the length: 100
Type the degree.minutes: 20.30
Don Ireland
Engineering Design Technician
yes degree and minutes separated by a dot (.)
for example 20.30
20 is the degree
30 is the minutes
like the command in autocad landesktop
call line by direction
dd.mm: 30.20
length: 100
@agent47x wrote:
yes degree and minutes separated by a dot (.)
for example 20.30
20 is the degree
30 is the minutes
like the command in autocad landesktop
call line by direction
dd.mm: 30.20
length: 100
Would you mind entering it in standard AutoCAD Surveyor's Units input format? In that case, it would be 30d20'. Or 30d20'45" if you get down to arc-seconds. But it could be done in the decimal format, with a little converting of the decimal portion to represent sixtieths. If you go down to arc-seconds, e.g. do 30.20.45, it would need to be asked for as a text string, rather than numerically, and that would need to be broken into pieces around the periods, which is easy enough.
Don Ireland
Engineering Design Technician
@agent47x wrote:
yes degree and minutes separated by a dot (.)
for example 20.30
20 is the degree
30 is the minutes
like the command in autocad landesktop
call line by direction
dd.mm: 30.20
length: 100
I made a couple modifications (in red) to allow for the requested format. CAUTION: I didn't include any kind of error checking to ensure that the user has actually entered this format and I don't know what it'll do if this format is NOT used.
;; ;; By Don Ireland ;; ;; Takes two arguments: A String to search for and a string to search in. ;; Usage: (strfind "ST" "TEST") ; This will return 3. ;; ;; Example: (if (> (setq pos (charfind "S" "TEST")) 0)(princ "Found the letter S at position: " . pos)(Princ "One or both search parameters was blank")) ;; ;; Return Values: ;; Any positive integer = the location of the string ;; -1 = character not found within given string. ;; -2 = Search string is empty. (srch) ;; -4 = Test String is empty. (str) ;; -6 = Search String and Test String are both empty. (defun strfind(srch str / pt pt2 cnt) (setq cnt 0 pt 0 pt2 nil) (if (EQ (strlen srch) 0) (setq pt -2)) (if (EQ (strlen str) 0) (setq pt (+ pt (- 0 4)))) (if (EQ pt 0)(setq pt -1)) (while (and (< pt 0) (> (strlen str) 0)(< cnt (strlen str))) (if (eq srch (substr str (setq cnt (1+ cnt)) (strlen srch)))(setq pt cnt)) ) (setq pt2 pt) ) (defun C:BDRAW () (setvar "cmdecho" 0) (initget 1) (setq PT (getpoint "\nPick a starting point: ")) (initget "1 2 3 4"); without the 1 argument, to allow Enter (while (setq BR (getkword "\nPick bearing (1/2/3/4) <exit>: ")) ;; hitting Enter for the <exit> default will return nil and stop the (while) loop (setq OPT (strcase BR)) (initget 1) (setq LEN (getreal "\nType the length: ")) (setq dms(getstring "\nType the angle: ")) (setq pos1(strfind "." dms)) (setq pos2(+ pos1 (strfind "." (substr dms (+ 1 pos1) (- (strlen dms) pos1))))) (setq DEG (substr dms 1 (- pos1 1))) (setq minx (substr dms (+ 1 pos1)(- pos2 pos1 1))) (setq SEC (substr dms (+ 1 pos2) (- (strlen dms) pos2))) ;(setq DEG (getstring "\nType the degree: ") ; minx (getstring "\nType the minute: ") ; SEC (getstring "\nType the second: ") ;) (if (= DEG "") (setq DEG "0")) (if (= minx "") (setq minx "0")) (if (= SEC "") (setq SEC "0")) (cond ((= "3" OPT) (setvar "angbase" (cvunit 270 "degree" "radian")) (setvar "angdir" 1) ) ((= "2" OPT) (setvar "angbase" (cvunit 270 "degree" "radian")) (setvar "angdir" 0) ) ((= "4" OPT) (setvar "angbase" (cvunit 90 "degree" "radian")) (setvar "angdir" 0) ) ((= "1" OPT) (setvar "angbase" (cvunit 90 "degree" "radian")) (setvar "angdir" 1) ) ) (command "line" PT (strcat "@" (rtos LEN) "<" DEG "d" minx "'" SEC "\"") "") (setvar "angbase" 0) (setvar "angdir" 0) (setvar "cmdecho" 1) (initget "1 2 3 4"); again, for (getkword) in next pass through loop ); end while (princ) ) (princ "\nType 'BDRAW' to draw lines with bearings") (princ)
Don Ireland
Engineering Design Technician
Here's another good source for learning the autolisp language:
http://www.lee-mac.com/tutorials.html#vlide
Don Ireland
Engineering Design Technician
Well after posting the previous, I thought about it some more and have added SOME error checking. The following will allow the user to enter DD.MM.SS, DD.MM or DD and still get the appropriate results.
The latest changes are in red.
;;
;; By Don Ireland
;;
;; Takes two arguments: A String to search for and a string to search in.
;; Usage: (strfind "ST" "TEST") ; This will return 3.
;;
;; Example: (if (> (setq pos (charfind "S" "TEST")) 0)(princ "Found the letter S at position: " . pos)(Princ "One or both search parameters was blank"))
;;
;; Return Values:
;; Any positive integer = the location of the string
;; -1 = character not found within given string.
;; -2 = Search string is empty. (srch)
;; -4 = Test String is empty. (str)
;; -6 = Search String and Test String are both empty.
(defun strfind(srch str / pt pt2 cnt)
(setq cnt 0 pt 0 pt2 nil)
(if (EQ (strlen srch) 0) (setq pt -2))
(if (EQ (strlen str) 0) (setq pt (+ pt (- 0 4))))
(if (EQ pt 0)(setq pt -1))
(while (and (< pt 0) (> (strlen str) 0)(< cnt (strlen str)))
(if (eq srch (substr str (setq cnt (1+ cnt)) (strlen srch)))(setq pt cnt))
)
(setq pt2 pt)
)
(defun C:BDRAW ()
(setvar "cmdecho" 0)
(initget 1)
(setq PT (getpoint "\nPick a starting point: "))
(initget "1 2 3 4"); without the 1 argument, to allow Enter
(while
(setq BR (getkword "\nPick bearing (1/2/3/4) <exit>: "))
;; hitting Enter for the <exit> default will return nil and stop the (while) loop
(setq OPT (strcase BR))
(initget 1)
(setq LEN (getreal "\nType the length: "))
(setq dms(getstring "\nType the angle: "))
(setq pos1(strfind "." dms))
(if (< 0 pos1)
(progn
(setq DEG (substr dms 1 (- pos1 1)))
(setq pos2(+ pos1 (strfind "." (substr dms (+ 1 pos1) (- (strlen dms) pos1)))))
(if (< 0 pos2)
(progn
(setq minx (substr dms (+ 1 pos1)(- pos2 pos1 1)))
(setq SEC (substr dms (+ 1 pos2) (- (strlen dms) pos2)))
);DD.MM.SS
(setq minx (substr dms (+ 1 pos1)(- (strlen dms) pos1)) sec 0);DD.MM.00
)
)
(setq deg dms minx 0 sec 0);DD.00.00
)
;(setq DEG (getstring "\nType the degree: ")
; minx (getstring "\nType the minute: ")
; SEC (getstring "\nType the second: ")
;)
(if (= DEG "") (setq DEG "0"))
(if (= minx "") (setq minx "0"))
(if (= SEC "") (setq SEC "0"))
(cond
((= "3" OPT)
(setvar "angbase" (cvunit 270 "degree" "radian"))
(setvar "angdir" 1)
)
((= "2" OPT)
(setvar "angbase" (cvunit 270 "degree" "radian"))
(setvar "angdir" 0)
)
((= "4" OPT)
(setvar "angbase" (cvunit 90 "degree" "radian"))
(setvar "angdir" 0)
)
((= "1" OPT)
(setvar "angbase" (cvunit 90 "degree" "radian"))
(setvar "angdir" 1)
)
)
(command "line" PT (strcat "@" (rtos LEN) "<" DEG "d" minx "'" SEC "\"") "")
(setvar "angbase" 0)
(setvar "angdir" 0)
(setvar "cmdecho" 1)
(initget "1 2 3 4"); again, for (getkword) in next pass through loop
); end while
(princ)
)
(princ "\nType 'BDRAW' to draw lines with bearings")
(princ)
Don Ireland
Engineering Design Technician
This is embarassing but I realized after posting that I had introduced a couple bugs with my last post.
This HAS been tested and WILL accept all three angle entries (DD.MM.SS, DD.MM & DD).
;; ;; By Don Ireland ;; ;; Takes two arguments: A String to search for and a string to search in. ;; Usage: (strfind "ST" "TEST") ; This will return 3. ;; ;; Example: (if (> (setq pos (charfind "S" "TEST")) 0)(princ "Found the letter S at position: " . pos)(Princ "One or both search parameters was blank")) ;; ;; Return Values: ;; Any positive integer = the location of the string ;; -1 = character not found within given string. ;; -2 = Search string is empty. (srch) ;; -4 = Test String is empty. (str) ;; -6 = Search String and Test String are both empty. (defun strfind(srch str / pt pt2 cnt) (setq cnt 0 pt 0 pt2 nil) (if (EQ (strlen srch) 0) (setq pt -2)) (if (EQ (strlen str) 0) (setq pt (+ pt (- 0 4)))) (if (EQ pt 0)(setq pt -1)) (while (and (< pt 0) (> (strlen str) 0)(< cnt (strlen str))) (if (eq srch (substr str (setq cnt (1+ cnt)) (strlen srch)))(setq pt cnt)) ) (setq pt2 pt) ) (defun C:BDRAW (/ dms deg minx sec pos1 pos2 opt br pt) (setvar "cmdecho" 0) (initget 1) (setq PT (getpoint "\nPick a starting point: ")) (initget "1 2 3 4"); without the 1 argument, to allow Enter (while (setq BR (getkword "\nPick bearing (1/2/3/4) <exit>: ")) ;; hitting Enter for the <exit> default will return nil and stop the (while) loop (setq OPT (strcase BR)) (initget 1) (setq LEN (getreal "\nType the length: ")) (setq dms(getstring "\nType the angle: ")) (setq pos1(strfind "." dms)) (if (< 0 pos1) (progn (setq deg nil minx nil sec nil) (setq DEG (substr dms 1 (- pos1 1))) (setq pos2 (strfind "." (substr dms (+ 1 pos1) (- (strlen dms) pos1)))) (if (< 0 pos2) (progn (setq pos2(+ pos1 pos2)) (setq minx (substr dms (+ 1 pos1)(- pos2 pos1 1))) (setq SEC (substr dms (+ 1 pos2) (- (strlen dms) pos2))) );DD.MM.SS (setq minx (substr dms (+ 1 pos1)(- (strlen dms) pos1)) sec "0");DD.MM.00 ) ) (setq deg dms minx "0" sec "0");DD.00.00 ) ;(setq DEG (getstring "\nType the degree: ") ; minx (getstring "\nType the minute: ") ; SEC (getstring "\nType the second: ") ;) (if (= DEG "") (setq DEG "0")) (if (= minx "") (setq minx "0")) (if (= SEC "") (setq SEC "0")) (cond ((= "3" OPT) (setvar "angbase" (cvunit 270 "degree" "radian")) (setvar "angdir" 1) ) ((= "2" OPT) (setvar "angbase" (cvunit 270 "degree" "radian")) (setvar "angdir" 0) ) ((= "4" OPT) (setvar "angbase" (cvunit 90 "degree" "radian")) (setvar "angdir" 0) ) ((= "1" OPT) (setvar "angbase" (cvunit 90 "degree" "radian")) (setvar "angdir" 1) ) ) (command "line" PT (strcat "@" (rtos LEN) "<" DEG "d" minx "'" SEC "\"") "") (setvar "angbase" 0) (setvar "angdir" 0) (setvar "cmdecho" 1) (initget "1 2 3 4"); again, for (getkword) in next pass through loop ); end while (princ) )
Don Ireland
Engineering Design Technician