[Help] Getangle with negative
Hi all.Please help me one simple problem. I use getangle (or getorient) to get an angle (angbase and angdir changed to suite already), and then check it value to decide direction to rotate. How could i make it return negative also ?Ex :
(getangle) =>type-20 => return :-0.349066 , not 5.93412 ?
I don't want use getstring, then check "-" or sth similar, since it no support pick two point
Please help me, i can't control my brain now
Thanks for reading in cases like that and degrees input cannot be help, i normally use getreal/dtr
(setq ang(if (minusp (setq i (getreal "\nEnter Angle: ")))(* pi (/ (+ 360 i) 180.00)) (* pi (/ i 180.0))) )
But it doesnt help with your question though
This perhaps?
(defun c:test (/ ang) (setq ang (getreal "\nEnter Angle::")) (if (= ang nil) (setq ang (getangle "Pick points for Angle: ")) (if (minusp ang) (* pi (/ (+ 360 ang) 180.00)) (* pi (/ ang 180.0)) ) )) My version:
(defun LM:2piAngle ( a ) (if (minusp (setq a (rem (+ pi pi a) (+ pi pi)))) (LM:2piAngle a) a ))
_$ (LM:2piAngle -0.349066)5.93412
Or, for angles (-2pi
(defun LM:2piAngle ( a ) (rem (+ pi pi a) (+ pi pi))) Thanks very much to Lee and pBe for helping. Sorry for my English, i feel there is a misunderstanding. I just want when i input an negative (ex -20), it will return -0.349066 , not 5.93412 like getangle did. SO i will try to modify a little two defun above ^^ I only want to ask can it be done by getang or getorient ^^
Why do you need it to specifically return the negative angle? Both angles are identical. Ah, actualy i'm trying to decide direction to array polar (base on qjchen idea).
Please see my post and red code of qjchen to understand my explaination. Srr for my poor E
With negative number, i want it go clockwise.But problem is ang allway return positive number, so i ask can it be solved by getangle anymore(lazy)? or i've change the way of get angle, or change two red code line ^^
Preview :
Open Source :
;Many thank to qjchen again(vl-load-com)(defun c:par( / ang angnow gr oang p0 px px1 ss ss1 cc oldAng ans)(grtext -1 "Dynamic PArray @Ketxu")(setq m:err *error* *error* err)(command "undo" "be")(setq oldAng (getvar "angbase"))(if (and (setq ss (ST:SS->List-Vla (ssget)) p0 (getpoint "\nT\U+00E2m quay : :") px (getpoint p0 "\n\U+0110\U+01B0\U+1EDDng c\U+01A1 s\U+1EDF ::") ))(progn (grdrawp0 px 1) (setvar "angbase" (angle p0 px)) (setq cc (_circle p0 (distance p0 px)) ang (getangle p0 "\nG\U+00F3c Array :") s (/ (getvar "viewsize") (cadr (getvar "SCREENSIZE"))) ) (cond ((ST:Check-Exist '("AcDbText" "AcDbMText") (mapcar 'vla-get-objectname ss)) (setq ans (strcase(getstring "Copy t\U+0103ng Text ? < K > :"))) (cond ((not (or (= ans "K")(= ans ""))) (or #num (setq #num 1)) (setq #num (cond ((getint (strcat "\nGia s\U+1ED1 < " (rtos #num 2 0) " > :")))(#num)) inc T) ) ) ) )(prompt "\nPick \U+0111i\U+1EC3m cu\U+1ED1i c\U+00F9ng :")(while (= (car (setq gr (grread nil 5 0))) 5) (if ss1 (mapcar 'vla-delete ss1)) (redraw) (setq angnow (angle p0 (cadr gr)) g (trans (cadr gr) 1 3) ) (grvecs (LM:GrText (rtos (/ (* angnow 180) pi) 2 0) 3) ((lambda ( r x y )(list (list r0. 0. x ) (list 0. r0. y ) (list 0. 0. r0.) (list 0. 0. 0. 1.)))s(+ (carg) (* 15 s))(- (cadr g) (* 31 s)) ) ) (if (and (< ang 0)(> angnow 0)) (setq angnow (- angnow (* 2 pi))))(if (and (> ang 0)(< angnow 0)) (setq angnow (+ (* 2 pi) angnow))) (setq ss1 (_copyCC ss (fix (/ angnow ang)) p0 ang inc #num)) (grdraw:arc p0 (/ (getvar "viewsize") 4.0) (angle p0 px) angnow))(entdel cc)(setvar "angbase" oldAng)))(command "undo" "en")(princ));;; =======================================================================;;;; by qjchen, copy ss according to the direction and vector ;;;; =======================================================================;(defun _copyCC (sslst n cen ang inc num / i obj1 ss xobj lst number) (foreach xobj sslst (setqi 1)(cond ((and (wcmatch (vla-get-objectname xobj) "AcDbText,AcDbMText") inc num) (cond ((= 'REAL (type (setq number (last (setq lst (ST:String-GetNumber (vla-get-textstring xobj))))))) (setqisReal T)) (T (setqisReal nil)) )(setq isText T)) ;Text Object(T setq isText nil)) (repeat n (setq obj1 (vla-copy xobj)) (Vla-rotate obj1 (vlax-3d-point cen) (* ang i)) (if(and isText (wcmatch (vla-get-objectname xobj) "AcDbText,AcDbMText") inc num)(vla-put-textstring obj1 (strcat (car lst) (rtos (setq number (+ num number)) 2(if isReal 1 0))(cadr lst)))) (setq i (1+ i) ss (cons obj1 ss)) ) ) ss);;; =======================================================================;;;; @Ketxu Make Circle Temp ;;;; =======================================================================;(defun _circle (p0 r / ent)(redraw (setq ent(entmakex (list (cons 0 "CIRCLE")(cons 10 (trans p0 1 0))(cons 40 r)))) 3) ent)(defun RtD (rad) ; converts radian to degree(/ (* rad 180) pi));defun;;; =======================================================================;;;; Check List Item Exist in Other List @Ketxu ;;;; =======================================================================;(defun ST:Check-Exist(lst1 lst2)(and (vl-remove nil (mapcar '(lambda(x)(vl-position x lst2)) lst1))));;; =======================================================================;;;; Selection to listVLA @Ketxu ;;;; =======================================================================;(defun ST:SS->List-Vla (ss / n e l) (setq n (sslength ss)) (while (setq e (ssname ss (setq n (1- n)))) (setq l (cons (vlax-ename->vla-object e) l)) ))(defun ST:Ss-Delete (ss / i) (mapcar 'vla-delete (ST:SS->List-Vla ss)));;; =======================================================================;;;; grdraw circle arc ;;;; =======================================================================;(defun grdraw:arc(cen r ang angadd / angdiv n)(grdraw cen (polar cen ang r) 3 1)(grdraw cen (polar cen (+ ang angadd) r) 3 1)(setq n 100 angdiv (/ angadd n))(repeat n(grdraw (polar cen ang r)(polar cen (setq ang (+ ang angdiv)) r) 1 1)))(defun ST:String-GetNumber (str / i j dau cuoi tmp tmp1 tmp2 num)(setq lst (vl-string->list str) i -1 j (strlen str))(list(setq tmp1 (vl-list->string (reverse (while (not (or (= i j))) (setq dau (cons tmp dau))))))(setq tmp2(vl-list->string (while (not (or ( I see - In that case you may need to use a getreal prompt, however you then cannot use the base point to visually pick the angle. So perhaps the compromise may be to use a separate getkword prompt for Clockwise/Anticlockwise.
Nice use of GrText Oh, i see. Now i change the method to input Angle ^^
GrText is nice by itself ^^ Thanks you for this function..
Ah, once more thing, How could i insert other symbol to it list by myself? ^^
You are right Lee!
It's not straightforward unfortunately
页:
[1]
2