Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HELP ME PLEASE

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
agent47x
449 Views, 14 Replies

HELP ME PLEASE

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)

 

 

 

 

 

 

14 REPLIES 14
Message 2 of 15
Kent1Cooper
in reply to: agent47x

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)

Kent Cooper, AIA
Message 3 of 15
Kent1Cooper
in reply to: Kent1Cooper

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)

....

Kent Cooper, AIA
Message 4 of 15
doni49
in reply to: Kent1Cooper

Nice Kent!



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 5 of 15
agent47x
in reply to: Kent1Cooper

Thanks KENT..do you have ebooks for begginers like me i just want to learn more about lisp programming?

Message 6 of 15
doni49
in reply to: agent47x

Check out AFRALISP.com.
Don Ireland


Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 7 of 15
agent47x
in reply to: agent47x

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

 

 

 

Message 8 of 15
doni49
in reply to: agent47x

The D-M-S are all separate lines.
Don Ireland


Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 9 of 15
agent47x
in reply to: doni49

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

Message 10 of 15
Kent1Cooper
in reply to: agent47x


@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.

Kent Cooper, AIA
Message 11 of 15
doni49
in reply to: agent47x

I understood what you were asking for when I made my reply. I was telling you how the routine is currently set up to work.

Each item is entered on a separate line

Degree
Minutr
Second
Don Ireland


Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 12 of 15
doni49
in reply to: agent47x


@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




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 13 of 15
doni49
in reply to: doni49

Here's another good source for learning the autolisp language:

 

http://www.lee-mac.com/tutorials.html#vlide



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 14 of 15
doni49
in reply to: doni49

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




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 15 of 15
doni49
in reply to: doni49

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




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

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

Post to forums  

Autodesk Design & Make Report

”Boost