Lisps whichs base is SNAPANG - "Join" them into one lisp

Lisps whichs base is SNAPANG - "Join" them into one lisp

Anonymous
Not applicable
521 Views
1 Reply
Message 1 of 2

Lisps whichs base is SNAPANG - "Join" them into one lisp

Anonymous
Not applicable

Hello everyone,

recently I wrote few lisps connected with SNAPANG command.

they are very useful.

 

Here they are:

 

1. You have a Line AB on the Drawing. Now you have to draw a Line at angle 20 degrees to the Line AB:

a) from the positive angle site (counterclockwise)

b) from the negative angle site (clockwise)

Use this lisp. First, pick two points which lie on the Line AB. Then, type a) 20 or b) -20 and CrossHair will be rotated so you are now able to draw a line at angle (for example 20) to the Line AB: a) from  this site, b) from this other site.

 

*

If you want to rotate Crosshair to draw Line only from the side of positive (negative) angle, use lisp 2.a. (2.b.). And if you want to choose one of these two options in CommandLine, use 2.a+b.

 

 

; Works properly
;NGREF = snap aNGle REFerence
; Set SNAPANG to the value of BaseAng + RotAng
; see also: NGROT
(defun c:NGREF
 (/ RefAngRad RefAng AngAddRad AngAdd FinalAng)
 (setq RefAngRad (getangle "\nTYPE angle value OR PICK two Points to define 'LINE' in regard to which you will rotate CrossHair: "))
 (setq RefAng (* (/ 180 PI) RefAngRad))
 (setq AngAddRad (getangle "\nTYPE value OR PICK two Points to define ANGLE about which you rotate CrossHair in regard to defined 'Line': "))
 (setq AngAdd (* (/ 180 PI) AngAddRad))
 (setq FinalAng (+ RefAng AngAdd))
 (command "_SNAPANG" FinalAng)
)

 

2.a.

; Works properly
;NGREFDWL = aNGle REFerence DamianWrobel final ang = reference angle PLUS angle of rotation
(defun c:NGREFDW+
(/ AngRefRad AngRef AngRotRad AngRot FinalAng)
(setq AngRefRad (getangle "\nSpecify Reference Angle for SNAPANG: "))
;(setq AngRef (angtos AngRefRad 0 4))
(setq AngRef (* (/ 180 PI) AngRefRad))
(setq AngRotRad (getangle "\nSpecify Rotation Angle: "))
;(setq AngRot (angtos AngRotRad 0 4))
(setq AngRot (* (/ 180 PI) AngRotRad))
(setq FinalAng (+ AngRef AngRot)) ; '-' has '-'
(COMMAND "_SNAPANG" FinalAng)
)

 

2.b.

; Works properly
;NGREFDWR = aNGle REFerence DamianWrobel final ang = reference angle MINUS angle of rotation
(defun c:NGREFDW-
(/ AngRefRad AngRef AngRotRad AngRot FinalAng)
(setq AngRefRad (getangle "\nSpecify Reference Angle for SNAPANG: "))
;(setq AngRef (angtos AngRefRad 0 4))
(setq AngRef (* (/ 180 PI) AngRefRad))
(setq AngRotRad (getangle "\nSpecify Rotation Angle: "))
;(setq AngRot (angtos AngRotRad 0 4))
(setq AngRot (* (/ 180 PI) AngRotRad))
(setq FinalAng (- AngRef AngRot)) ; '+' has '+'
(COMMAND "_SNAPANG" FinalAng)
)

 

2.a+b.

; Works properly
(defun c:NGREFDW
(/ AngRefRad AngRef AngRotRad AngRot FinalAng)
(setq AngRefRad (getangle "\nSpecify Reference Angle for SNAPANG (TYPE or PICK): "))
;(setq AngRef (angtos AngRefRad 0 4))
(setq AngRef (* (/ 180 PI) AngRefRad))
(princ "\nYou can type '+' or '-' value to get rotating such as or counter to ANGDIR.")
(setq AngRotRad (getangle "\nSpecify Rotation Angle (TYPE or PICK): "))
;(setq AngRot (angtos AngRotRad 0 4))
(setq AngRot (* (/ 180 PI) AngRotRad))
(setq FinalAng (+ AngRef AngRot))
(COMMAND "_SNAPANG" FinalAng)
)

 

3.

You are drawing a line which Angle property will be 40 (or 180+40=220) with CrossHair setted to the position of SNAPANG=40.

But now you have to draw a line which Angle property will be equal to 70 (or 31). So you need to rotate CrossHair about angle of 30 (or -9) degrees, yes?

So, use this lisp. (If you would use SNAPANG=30, it will not be rotated about angle of 30 degrees, but it would be rotated to the position of 30 degrees)

; NGROT = aNGle ROTate
; Rotates current CrossHair position about a specified Angle (current SNAPANG value + specified Angle)
;see also NGREF

; Works properly
(defun c:NGROTDW
  (/ CurAngRad CurAng RotAngRad RotAng FinalAng)
  (setq CurAngRad (getvar "SNAPANG"))
  (setq CurAng (* (/ 180 PI) CurAngRad))
  (princ "\n(Type value with '+'for rotating such like ANGDIR says; or '-' for counter rotating)")
  (setq RotAngRad (getangle "\nSpecify Rotation Angle (TYPE or PICK): "))
;(setq RotAng (angtos AngRotRad 0 4))
(setq RotAng (* (/ 180 PI) RotAngRad))
(setq FinalAng (+ CurAng RotAng))
(COMMAND "_SNAPANG" FinalAng)
)

 

4.

You draw a line at angle for example 15 degrees to line AB from the left side, but now you want to draw a line at the same angle to the same line AB, but from the other side of line AB?

If yes, use this lisp for "SnapAng Mirror":

; Works properly
(defun c:NGMIRR
  (/ RefAngRad RefAng CurAngRad CurAng Diff FinalAng) ; Diff = Difference
  (setq RefAngRad (getangle "\nSpecify Reference Angle (TYPE or PICK): "))
  (setq RefAng (* (/ 180 PI) RefAngRad))
  (setq CurAngRad (getvar "SNAPANG"))
  (setq CurAng (* (/ 180 PI) CurAngRad))
  (setq Diff (abs(- CurAng RefAng)) )
  (
    if (> CurAng RefAng)
	(setq FinalAng (- CurAng (* 2 Diff)) )
	(setq FinalAng (+ CurAng (* 2 Diff)) )
  )
  (COMMAND "_SNAPANG" FinalAng)
)

 

 

But I want to modify them, to "join" them into one lisp.

All my questions are in this lisp code below:

 

(defun c:NGREFDWMEGA
(/ AngRefRad AngRef AngRotRad AngRot PM FinalAng)
;(setq AngRefRad (getangle "\nSpecify Reference Angle for SNAPANG (TYPE or PICK) or (Special case: type '0') (Enter for current SNAPANG value): "))
;;;;;;;
; 1.
;The problem is, what expession to use to be able to choose either picking points, or entering real numbers, or keywords.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 1st way
; There should be also 'getkword' to get 'Z', 'C' or Enter.
(setq AngRefRad (getangle "\nSpecify Reference Angle for SNAPANG (TYPE or PICK) or [Zero/Current] <Current>: "))
; it is extraordinary case. You can type a keyword ('C' or 'Z') or Enter or a real number. Should I use 'if' or 'cond'
; na forumsautodesk.com
;(if
;    
;	(numberp AngRefRad)
;   (; I don't know what to type here)
;	
;	(
;	 cond
;	  (
;	   ; (eq ... (I didn't use 'getkword') "Z")
;	    (setq AngRefRad "0")
;	  )	 
;	  (
;	   ; (eq ... (I didn't use 'getkword') "C")
;	    (setq AngRefRad (getvar "SNAPANG"))
;	  )
;	  (
;	   ; (eq ... (I didn't use 'getkword') "" ; "" for "Enter")
;	    (setq AngRefRad (getvar "SNAPANG"))
;	  )
;	)
;  
;)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 2nd way
;(initget 1 "Z" "C" "" ;|any_integer (How to define it?)|; )
; setq ang_ref_rad (getkword "\nSpecify Reference Angle for SNAPANG (TYPE or PICK) or [Zero/Current] <Current>: ")) ; Will I be not able to define Reference Angle by Picking two Points?
;(
;  cond
;    (
;     (numberp ang_ref_rad)
;     ( setq AngRefRad ang_ref_rad)
;    )
;
;    (
;     (eq ang_ref_rad "Z")
;     (setq AngRefRad "0")
;    )
;
;    (
;     (eq ang_ref_rad "C")
;     (setq AngRefRad (getvar "SNAPANG"))
;    )
;
;    (
;     (eq ang_ref_rad "")
;     (setq AngRefRad (getvar "SNAPANG"))
;    )
;)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;(setq AngRef (angtos AngRefRad 0 4))
(setq AngRef (* (/ 180 PI) AngRefRad))
;2. add MIRROR option (see lisp 4. NGMIRR)
(setq AngRotRad (getangle "\nSpecify Rotation Angle (TYPE a POSITIVE or zero value or PICK) or [Mirror]: "))
;(setq AngRot (angtos AngRotRad 0 4))
; 3. while AngRotRad is not positive or zero, prompt "Enter a positive number or zero: "
(setq AngRot (* (/ 180 PI) AngRotRad))
(initget 1 "P M")
(setq PM (getkword "\nCrossHair's new Position will be = Reference Angle '+' or '-' Rotation Angle? [Plus/ Minus]: ")) ; there could be also [Add/Substract] or [+/-] instead of [P/M]
(cond 
  (
   (eq PM "P")
   (setq FinalAng (+ AngRef AngRot))
  )
  
  (
  (eq PM "M")
  (setq FinalAng (- AngRef AngRot))
  )
); cond
(COMMAND "_SNAPANG" FinalAng)
); defun

 

 

 

Could you please give me response to these questions?

0 Likes
522 Views
1 Reply
Reply (1)
Message 2 of 2

stevor
Collaborator
Collaborator
Without interpreting all that, let me suggest: 1. the GRREAD function can take input from the keyboard and pointer devices, although it takes more code; google it. 2. a more productive 'Subject ' line might be your: "choose either picking points, or entering real numbers, or keywords"
S
0 Likes