Author Topic: How to Include Previous Angle Entry at Re-Start [Global Var]  (Read 402 times)

0 Members and 1 Guest are viewing this topic.

ScottMC

  • Newt
  • Posts: 93
  • ...if we don't ask, we won't receive..
How to Include Previous Angle Entry at Re-Start [Global Var]
« on: September 30, 2021, 08:50:45 PM »
Here's where I'd like to go.. This is helping me to convert/replace a point with a line. Originally had it using only a 45° 1" to do the job but would like other angles too and for the angle to be available for use again on repeat/restart. Thanks y'all..

Code - Auto/Visual Lisp: [Select]
  1. (defun c:p45 ( / a pt1 pt0 pbg ang ang1 len ed)
  2.       ;;
  3.       ;;   original source:
  4.       ;; http://forums.augi.com/showthread.php?91585-Draw-a-line-starting-from-the-midpoint-of-itself
  5.       ;;
  6.       (princ "\n  Re+Place Object\(s\) with 1.0\" Line at Angle of Choice..")
  7.       (setvar "cmdecho" 0)
  8.       (setvar "pdmode" 35)
  9.       (setq ang1 (getangle "\nEnter/Pick Angle to Use: <45>"))
  10.       (if                                                   ;check for angle other than nil
  11.         (= ang1 nil)                                     ; if angle not nil..                                
  12.          (setq ang (angtof "45"))               ; use 45° if Enter is pressed
  13.          (setq ang ang1)                             ; else use entered # <<<<<<<<<<<< ???
  14.       )                                             ; end if
  15.       (while
  16.         (setq pt1 (getpoint "\nPick Basepoint of Object to Replace: ")) ; 'points' are picked
  17.          (setq len 0.5)                               ;setq half-length  
  18.          (setq pt0 (polar pt1 ang len))               ;Calculate other endpoint
  19.          (setq pt1 (polar pt1 ang (* -2 len)))      ; move location/base to place at mid/pick
  20.          (setq ed (list '(0 . "LINE")                      ; make line
  21.                             (cons 10 pt0)
  22.                             (cons 11 (polar pt1 ang len))
  23.                         ) ;_ end of list
  24.          ) ;_ end of setq
  25.          ;;
  26.          (entmake ed)                                 ;insert the line
  27.       )                           ;_ end of while
  28.       (princ " Erase Anything?")
  29.       (vl-cmdf "erase" pause)
  30.        (setvar "cmdecho" 1)
  31.        (setvar "pdmode" 3)
  32.     (princ)
  33. ) ;_ end of defun


EDIT (John): Added code tags.
« Last Edit: October 08, 2021, 10:55:55 AM by John Kaul (Se7en) »

stevar

  • Mosquito
  • Posts: 1
Re: How to Include Previous Angle Entry at Re-Start [Global Var]
« Reply #1 on: October 07, 2021, 06:12:36 PM »
Code - Auto/Visual Lisp: [Select]
  1. (setq A1 (if A1 A1 (/ pi 4))
  2. (if (setq ANS (getangle "\n Enter/Pick Angle: <" (angtos A1) ">: "))
  3.    (setq A1 (angtof ANS) ) )


And to TheSwamp, what the? is all the extra questions?
Trying to lose users?



EDIT (John): Added code tags.
« Last Edit: October 08, 2021, 10:56:20 AM by John Kaul (Se7en) »

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9729
Re: How to Include Previous Angle Entry at Re-Start [Global Var]
« Reply #2 on: October 08, 2021, 10:55:24 AM »
Not trying to keep members away. Those questions are to keep the spam bots away and they stop after you make a few posts (I forget what I had it set to, but after you make 3 or 5 posts it will stop asking you questions).
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

ScottMC

  • Newt
  • Posts: 93
  • ...if we don't ask, we won't receive..
Re: How to Include Previous Angle Entry at Re-Start [Global Var]
« Reply #3 on: October 08, 2021, 01:46:26 PM »
Any idea on the pgm above - point to line to get it to remember the last angle for reuse?

BIGAL

  • Swamp Rat
  • Posts: 849
  • 30 + years of using Autocad
Re: How to Include Previous Angle Entry at Re-Start [Global Var]
« Reply #4 on: October 08, 2021, 07:48:42 PM »
 2 ways can save angle in the USER vars, or can use a (setenv "angle" ang) which saves it to the registry on your PC. Can be any name.
A man who never made a mistake never made anything

ScottMC

  • Newt
  • Posts: 93
  • ...if we don't ask, we won't receive..
Re: How to Include Previous Angle Entry at Re-Start [Global Var]
« Reply #5 on: October 08, 2021, 09:20:02 PM »
The excitement keeps me from getting the If's from working together. Must be a variable name oops yet 'malformed..syntax error... etc has me stumped.

Code: [Select]
(defun c:p45 () (/ a1 a pt1 pt0 pbg ang1 len ed)
  ;;
  ;; http://forums.augi.com/showthread.php?91585-Draw-a-line-starting-from-the-midpoint-of-itself
  ;;
  (princ
    "\n  Re+Place Object\(s\) with 1.0\" Line at Angle of Choice.."
  ) ;_ end of princ
  (setvar "cmdecho" 0)
  (setq A1 (if A1
             A1
             (/ pi 4)
           ) ;_ end of if
        (if (setq ang1 (getangle "\n Enter/Pick Angle to Use: <"
                                                  ; acquire angle
                                (angtos A1)
                                " >"
                      ) ;_ end of getangle
            ) ;_ end of setq
          (setq A1 (angtof ang1))
        ) ;_ end of if
   )                                         ; (if                                                   ;check for angle other than nil
                                                  ; (= ang1 nil)                                     ; if angle not nil..                                 
                                                  ; (setq ang (angtof "45"))               ; use 45° if Enter is pressed
                                                  ; (setq ang ang1)                             ; else use entered # >>
                                                  ; )                                             ; end if
         (while
           (setq pt1 (getpoint "\nPick Basepoint of Object(s) to Replace: "))
                                                  ; 'points' are picked
            (setq len 0.5)                        ;setq half-length
            (setq pt0 (polar pt1 ang1 len))        ;Calculate other endpoint
            (setq pt1 (polar pt1 ang1 (* -2 len))) ; move location/base to place at mid/pick
            (setq ed (list '(0 . "LINE")          ; make line
                           (cons 10 pt0)
                           (cons 11 (polar pt1 ang1 len))
                     ) ;_ end of list
            ) ;_ end of setq
            ;;
            (entmake ed)                          ;insert the line
         ) ;_ end of while
        (princ)
         (princ " Erase Anything?")
        (vl-cmdf "erase" pause)
         (setvar "cmdecho" 1)
        (princ)
  ) ;_ end of defun
;) ;_ end of defun
;|«Visual LISP© Format Options»
(72 2 50 2 T "end of " 60 9 0 1 0 nil T nil T)
;*** DO NOT add text below the comment! ***|;


; error: too few arguments in SETQ: (SETQ A1 (IF A1 A1 ( ... )) (IF ( ... ) ( ... )))
« Last Edit: October 08, 2021, 09:44:39 PM by ScottMC »

BIGAL

  • Swamp Rat
  • Posts: 849
  • 30 + years of using Autocad
Re: How to Include Previous Angle Entry at Re-Start [Global Var]
« Reply #6 on: October 09, 2021, 08:21:28 PM »
Do you mean this

(if (= A1 nil)(setq a1 (/ pi 4.0)))
A man who never made a mistake never made anything

ScottMC

  • Newt
  • Posts: 93
  • ...if we don't ask, we won't receive..
Re: How to Include Previous Angle Entry at Re-Start [Global Var]
« Reply #7 on: October 09, 2021, 11:13:18 PM »
Looking better.. Do try/test/clean as y'all know what to look for. Thanks much again!

Code: [Select]
(defun c:p45 ( / ang1 pt1 pt0 len ed)
      ;;
      ;; http://forums.augi.com/showthread.php?91585-Draw-a-line-starting-from-the-midpoint-of-itself
      ;;
      (setvar 'cmdecho 0)
      (princ "\n  Re+Place Object\(s\) with 1.0\" Line at Angle of Choice..")

      (if (= *PA-1 nil)(setq *PA-1 (/ pi 4.0))) ;; initial var fill if nil..
 
      (if (setq ang1 (getangle (strcat "\n Enter/Pick Angle to Use: <"(angtos *PA-1)"> "))) ;; acquire angle  (angtos A1) " >"
        *PA-1 (setq ang1 *PA-1) )

      (while
        (setq pt1 (getpoint "\nPick Basepoint of Object(s) to Replace: ")) ; 'points' are picked
         (setq len 0.5)                               ;setq half-length 
         (setq pt0 (polar pt1 ang1 len))               ;Calculate other endpoint
         (setq pt1 (polar pt1 ang1 (* -2 len)))      ; move location/base to place at mid/pick
         (setq ed (list '(0 . "LINE")                      ; make line
                            (cons 10 pt1)
                            (cons 11 (polar pt0 ang1 len)) ; changed to put start-point at left
                        ) ;_ end of list
         ) ;_ end of setq
         ;;
         (entmake ed)                                 ;insert the line
      ) ;_ end of while
 
      (princ " Erase Anything?")
      (vl-cmdf "erase" pause)
 
       (setq *PA-1 ang1) ;; last change to save angle for repeat
  ;; hope that global is safe
       (setvar 'cmdecho 1)
    (princ)
) ;_ end of defun
« Last Edit: October 10, 2021, 09:10:17 AM by ScottMC »

ScottMC

  • Newt
  • Posts: 93
  • ...if we don't ask, we won't receive..
Re: How to Include Previous Angle Entry at Re-Start [Global Var]
« Reply #8 on: October 10, 2021, 06:52:51 PM »
Slightly off project but still fits the title.. How can 'LASTANGLE' be used in coord command-line entry? @10<(lastangle).. <Not

BIGAL

  • Swamp Rat
  • Posts: 849
  • 30 + years of using Autocad
Re: How to Include Previous Angle Entry at Re-Start [Global Var]
« Reply #9 on: October 10, 2021, 08:44:01 PM »
If your using lisp why would you not use (polar pt ang dist) to work out next point then a line is pt1 - pt2

If you must then look into vl-cmdf and vla-sendcommand where you make a string of @dist<(lastangle)
A man who never made a mistake never made anything