Dj_T_Rex2002 Posted April 17, 2018 Share Posted April 17, 2018 (edited) Hi all, Ok so I have this small lisp and I'm still learning on how to work with these. I have the following code. It works fine for one time and then I have to retype "RBB1" because if I right click to repeat command, it just prompts me "Enter Degrees" because it calls out the RRP (in the lisp) rather than repeat RRB1. Could someone help me on telling me how to make the function of right click to use RRB1 again? (Defun C:RRB1 ( / DES SCR ) (If (BoundP 'C:RRP) (If (SetQ SCR (STRCAT (GetVar 'TempPrefix) "RRP1TMP.SCR") ;; Temp name to save DES (Open SCR "W") );SetQ (ProgN (Write-Line "RRP 90" DES) (Close DES) (Command "_.SCRIPT" SCR) );ProgN );If (Princ "\NC:RRP Function Not Defined.") );If (Princ) );Defun Tried following the guidelines here http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines and when I click preview it doesn't show me what it'll look like. Just wanna make sure in case it doesn't work when I click the "#" sign. Edited April 17, 2018 by rkmcswain Added [CODE] tags Quote Link to comment Share on other sites More sharing options...
rlx Posted April 17, 2018 Share Posted April 17, 2018 (edited) (defun c:rrb1 ( / des scr ) (if (and rrp (setq scr (strcat (getvar "tempprefix") "rrp1tmp.scr")) (setq des (open scr "w"))) (progn (write-line "(rrp) 90" des)(close des)(command "_.script" scr))(princ "\nRRP not loaded")) (princ) ) (defun rrp () (setq s (getstring "\nEnter angle : ")) (alert s) ) little hint : difference between (defun c:funky ()...) and (defun funky () ...) Edited April 17, 2018 by rlx Quote Link to comment Share on other sites More sharing options...
Dj_T_Rex2002 Posted April 17, 2018 Author Share Posted April 17, 2018 (defun c:rrb1 ( / des scr ) (if (and rrp (setq scr (strcat (getvar "tempprefix") "rrp1tmp.scr")) (setq des (open scr "w"))) (progn (write-line "(rrp) 90" des)(close des)(command "_.script" scr))(princ "\nRRP not loaded")) (princ) ) (defun rrp () (setq s (getstring "\nEnter angle : ")) (alert s) ) little hint : difference between (defun c:funky ()...) and (defun funky () ...) Thanks for the reply, however, after selecting object (just like any other command) it closes. Then I try to right-click to repeat command but it just says repeats command RRP which is the manual one to enter degrees ... I want the lisp to rotate 90 degrees from original insert point and once it rotates it, right-click and repeat the same command without entering the degrees. Quote Link to comment Share on other sites More sharing options...
rlx Posted April 18, 2018 Share Posted April 18, 2018 I don't know what your rrp function looks like , but that's not the point here , the point is , autocad repeats commands , real commands , like line or rotate etc and also function (defuns) defined with C: so if you have two defuns each defined with C: it will repeat the last one called and in your case that would be C:RRP wrote this a while ago (defun c:rot13 ( / rot-list loop ss1 CtrPt inp) (vl-load-com) (setq rotlist (list 45 90 135 180 225 270) loop t) (setvar "CMDECHO" 0) (if (and (setq ss1 (ssget)) (setq CtrPt (getpoint "\nPick the rotation Point:... "))) (progn (princ "\nCycle angle with tab or L-mouse / accept use enter,space or R-mouse / Esc or x for exit") (princ (strcat "\nChoose rotation angle<" (itoa (car rotlist)) "> : ")) (while loop (setq inp (vl-catch-all-apply 'grread (list nil 8 0))) (if (vl-catch-all-error-p inp) (progn (princ "\nRotation function cancelled")(setq loop nil)) (progn (cond ;tab ((or (equal inp '(2 9))(= (car inp) 3)) (setq rotlist (append (cdr rotlist)(list (car rotlist)))) (princ (strcat "\rChoose rotation angle<" (itoa (car rotlist)) "> : "))) ;enter,space,r-mouse ((or (equal inp '(2 13)) (equal inp '(2 32))(= (car inp) 25)) (command "rotate" ss1 "" CtrPt (car rotlist))(setq loop nil)) ;x or X ((member inp '((2 88)(2 120)))(setq loop nil)) ) ) ) ) ) ) (setvar "CMDECHO" 1) (princ) ) Quote Link to comment Share on other sites More sharing options...
Dj_T_Rex2002 Posted April 18, 2018 Author Share Posted April 18, 2018 This is the RRP command... (defun c:RRP (/ rotateval ss len c e f degrees radians) (setq rotateval (atoi (getstring "\nHow many degrees rotation are required: " ) ) ) (setq ss (ssget)) (setq len (sslength ss)) (setq c 0) (repeat len (setq f (entget (ssname ss c))) (setq e (cdr (assoc '50 (entget (ssname ss c))))) (setq degrees (Radian->Degrees e)) (setq degrees (+ degrees rotateval)) (while (>= degrees 360) (setq degrees (- degrees 360)) ) (setq radians (Degrees->Radians degrees)) (setq f (subst (cons 50 radians) (assoc 50 f) f)) (entmod f) (setq c (+ c 1)) ) ) (defun Radian->Degrees (nbrOfRadians) (* 180.0 (/ nbrOfRadians pi)) ) (defun Degrees->Radians (numberOfDegrees) (* pi (/ numberOfDegrees 180.0)) ) Quote Link to comment Share on other sites More sharing options...
rlx Posted April 18, 2018 Share Posted April 18, 2018 (edited) here ya go (defun c:rrb1 (/ scr fp) (if (and rrp (setq scr (strcat (getvar "tempprefix") "rrp1tmp.scr")) (setq fp (open scr "w")) ) (progn (write-line "(rrp)\n90" fp)(close fp)(command "_.script" scr)) (princ "\nRRP not loaded")) (princ) ) (defun RRP (/ rotateval ss ssl i e el ang degrees radians) (setq rotateval (atoi (getstring "\nHow many degrees rotation are required: "))) (if (setq ss (ssget)) (progn (setq ssl (sslength ss) i 0) (repeat ssl (setq e (ssname ss i) el (entget e) ang (cdr (assoc '50 el)) degrees (Radian->Degrees ang) degrees (+ degrees rotateval)) (while (>= degrees 360) (setq degrees (- degrees 360))) (setq radians (Degrees->Radians degrees) el (subst (cons 50 radians) (assoc 50 el) el)) (entmod el)(entupd e) (setq i (1+ i)) ) ) ) ) (defun Radian->Degrees (nbrOfRadians) (* 180.0 (/ nbrOfRadians pi))) (defun Degrees->Radians (numberOfDegrees) (* pi (/ numberOfDegrees 180.0))) and if you really want to have fun : (defun c:rrb1 (/ scr fp) (if (and rrp (setq scr (strcat (getvar "tempprefix") "rrp1tmp.scr")) (setq fp (open scr "w"))) (progn (write-line "(rrp)\n90" fp)(close fp)(command "_.script" scr)) (princ "\nRRP not loaded")) (princ)) (defun RRP (/ rot) (and (setq rot (getreal "\nRotation : ")) (mapcar '(lambda (x) (entmod (setq x (subst (cons 50 (rem (+ (cdr (assoc '50 x)) (* pi (/ rot 180.0))) (* 2 pi))) (assoc 50 x) x)))) (mapcar 'entget (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget))))) ) ) ) Edited April 19, 2018 by rlx Quote Link to comment Share on other sites More sharing options...
Dj_T_Rex2002 Posted April 19, 2018 Author Share Posted April 19, 2018 here ya go (defun c:rrb1 (/ scr fp) (if (and rrp (setq scr (strcat (getvar "tempprefix") "rrp1tmp.scr")) (setq fp (open scr "w")) ) (progn (write-line "(rrp)\n90" fp)(close fp)(command "_.script" scr)) (princ "\nRRP not loaded")) (princ) ) (defun RRP (/ rotateval ss ssl i e el ang degrees radians) (setq rotateval (atoi (getstring "\nHow many degrees rotation are required: "))) (if (setq ss (ssget)) (progn (setq ssl (sslength ss) i 0) (repeat ssl (setq e (ssname ss i) el (entget e) ang (cdr (assoc '50 el)) degrees (Radian->Degrees ang) degrees (+ degrees rotateval)) (while (>= degrees 360) (setq degrees (- degrees 360))) (setq radians (Degrees->Radians degrees) el (subst (cons 50 radians) (assoc 50 el) el)) (entmod el)(entupd e) (setq i (1+ i)) ) ) ) ) (defun Radian->Degrees (nbrOfRadians) (* 180.0 (/ nbrOfRadians pi))) (defun Degrees->Radians (numberOfDegrees) (* pi (/ numberOfDegrees 180.0))) and if you really want to have fun : (defun c:rrb1 (/ scr fp) (if (and rrp (setq scr (strcat (getvar "tempprefix") "rrp1tmp.scr")) (setq fp (open scr "w"))) (progn (write-line "(rrp)\n90" fp)(close fp)(command "_.script" scr)) (princ "\nRRP not loaded")) (princ)) (defun RRP (/ rot) (and (setq rot (getreal "\nRotation : ")) (mapcar '(lambda (x) (entmod (setq x (subst (cons 50 (rem (+ (cdr (assoc '50 x)) (* pi (/ rot 180.0))) (* 2 pi))) (assoc 50 x) x)))) (mapcar 'entget (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget))))) ) ) ) Dude!!! You're the best, thanks so much Quote Link to comment Share on other sites More sharing options...
rlx Posted April 19, 2018 Share Posted April 19, 2018 Dude!!! You're the best, thanks so much you're welcome FWIW (defun c:RRB1 () (and (or myRot (setq MyRot (getreal "\nRotation : "))) (mapcar '(lambda (x) (entmod (subst (cons 50 (rem (+ (cdr (assoc '50 x)) (* pi (/ MyRot 180.0))) (* 2 pi))) (assoc 50 x) x))) (mapcar 'entget (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget))))) ) ) ) If you make a global var 'MyRot' first time you use it this will have no value and (or Myrot (setq MyRot.... )) will set it and continue with the rest of the routine. If you want to change it , just type (setq MyRot nil) and routine will ask again. Or you make a shortcut reset_my_rotation : (defun c:rsmr () (setq MyRot nil)(c:rrb1)) gr. Rlx Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.