itacad Posted December 12, 2018 Posted December 12, 2018 Hello...I often move objects along the axes. The peculiarity of these movements is that they always have the same step (distance) to be repeated several times. I was looking for a lisp that starting from selected objects and given a direction, moved the objects of one "step" (fixed distance) for each "click" in the indicated direction. In your forum I found this discussion, but I don't know how to correct it to choose the direction and to carry out the repetition of the command. Someone can help me? Thank you in advance Quote
ronjonp Posted December 12, 2018 Posted December 12, 2018 (edited) Something like this? (defun c:up50 (/ s) (if (setq s (ssget ":L")) (while (getpoint "\nPick a point to nudge: ") (command "_.move" s "" '(0. 0. 0.) '(0. 50. 0.)) ) ) (princ) ) Edited December 13, 2018 by ronjonp Quote
ronjonp Posted December 13, 2018 Posted December 13, 2018 (edited) Actually .. maybe this: (defun c:foo (/ d i g s) ;; RJP » 2018-12-13 (cond ((and (setq d (getdist "\nEnter nudge distance: ")) (setq s (ssget ":L"))) (setq s (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))) (while (and (setq g (grread 2 1)) (not (member (cadr g) '(13 32)))) (princ "\r4A-LEFT 6D-RIGHT 2S-DOWN 8W-UP [ENTER/SPACEBAR to Exit]") (cond ((= 2 (car g)) (setq g (strcase (chr (cadr g)))) (if (setq i (cond ((wcmatch g "2,S") (list 0. (- d) 0.)) ((wcmatch g "4,A") (list (- d) 0. 0.)) ((wcmatch g "6,D") (list d 0. 0.)) ((wcmatch g "8,W") (list 0. d 0.)) ) ) (foreach x s (vlax-invoke x 'move '(0. 0. 0.) i)) ) ) ) ) ) ) (princ) ) Edited December 13, 2018 by ronjonp OCD made me remove command calls :P Quote
itacad Posted December 13, 2018 Author Posted December 13, 2018 oh great! Thank you very much! it is exactly what I need! I will call this command movenudge! with the aim of being able to read the difference but also because it is a special case that I need, can you write the code without entering the push distance? it is a costant = 0.9 so in that case I would save the passage to enter the distance...so in that case I would save the passage to enter the distance Thank you again Quote
ronjonp Posted December 13, 2018 Posted December 13, 2018 16 minutes ago, itacad said: oh great! Thank you very much! it is exactly what I need! I will call this command movenudge! with the aim of being able to read the difference but also because it is a special case that I need, can you write the code without entering the push distance? it is a costant = 0.9 so in that case I would save the passage to enter the distance...so in that case I would save the passage to enter the distance Thank you again To make the distance preset change this: (setq d (getdist "\nEnter nudge distance: ")) To this: (setq d 0.9) Quote
itacad Posted December 13, 2018 Author Posted December 13, 2018 ok! thank you! I learned something! Quote
ronjonp Posted December 13, 2018 Posted December 13, 2018 10 minutes ago, itacad said: ok! thank you! I learned something! Glad to help! Quote
yxl030 Posted November 25, 2020 Posted November 25, 2020 (edited) Thanks! This is the LISP I want to use.But after select object, it display ;error: no function definition: nil Why? On 12/13/2018 at 10:55 PM, ronjonp said: Actually .. maybe this: (defun c:foo (/ d i g s) ;; RJP » 2018-12-13 (cond ((and (setq d (getdist "\nEnter nudge distance: ")) (setq s (ssget ":L"))) (setq s (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))) (while (and (setq g (grread 2 1)) (not (member (cadr g) '(13 32)))) (princ "\r4A-LEFT 6D-RIGHT 2S-DOWN 8W-UP [ENTER/SPACEBAR to Exit]") (cond ((= 2 (car g)) (setq g (strcase (chr (cadr g)))) (if (setq i (cond ((wcmatch g "2,S") (list 0. (- d) 0.)) ((wcmatch g "4,A") (list (- d) 0. 0.)) ((wcmatch g "6,D") (list d 0. 0.)) ((wcmatch g "8,W") (list 0. d 0.)) ) ) (foreach x s (vlax-invoke x 'move '(0. 0. 0.) i)) ) ) ) ) ) ) (princ) ) Edited November 25, 2020 by yxl030 Quote
dlanorh Posted November 25, 2020 Posted November 25, 2020 Try changing the start of the lisp to : (defun c:foo (/ d i g s) (vl-load-com) ;; RJP >> 2018-12-13 1 Quote
yxl030 Posted November 25, 2020 Posted November 25, 2020 dlanorh, thanks! It's working. 9 minutes ago, dlanorh said: Try changing the start of the lisp to : (defun c:foo (/ d i g s) (vl-load-com) ;; RJP >> 2018-12-13 Quote
dlanorh Posted November 25, 2020 Posted November 25, 2020 2 hours ago, yxl030 said: dlanorh, thanks! It's working. Great, Glad I could help. 1 Quote
BIGAL Posted November 26, 2020 Posted November 26, 2020 A very old like 30 years ago made some defuns CHX CHY CHZ did what they imply. Makes it easy to remember what to do. Quote
ronjonp Posted November 26, 2020 Posted November 26, 2020 2 hours ago, BIGAL said: A very old like 30 years ago made some defuns CHX CHY CHZ did what they imply. Makes it easy to remember what to do. Please provide a link to these invaluable 'defuns'. Not sure what 'Makes it easy to remember what to do' means? I'm sorry If I'm coming off brash but this post confuses the hell out of me. 2 Quote
BIGAL Posted November 27, 2020 Posted November 27, 2020 Type chx as name implies "change in X direction" it would ask for a distance then pick objects, -ve is ok its old code 1990 needs to be redone made a bit smarter that is why I did not post its loaded on startup. It does not do multiple selections rather pick pick. (defun C:CHX ( / oldsnap k x newx) (SETVAR "CMDECHO" 0) (setq oldsnap (getvar "osmode")) (setvar 'osmode 512) (princ "\nMoves object in X direction") (setq x (getstring "\n What is amount of change: ")) (setq newx (strcat x ",0")) (while (setq newobj (entsel "\nPoint to object: Enter to exit ")) (command "move" newobj "" "0,0" newx) ) (setvar 'osmode oldsnap) (princ) ) 1 Quote
yxl030 Posted December 1, 2020 Posted December 1, 2020 The Lisp now runs like this: select --> [4A/6D/2S/8W]to move ---> [4A/6D/2S/8W]to move ---> ... ---> [ENTER/SPACEBAR to] exit. How to change to like this : Select ---> move ---> select another ---> move another ---> ..... ---> [ENTER/SPACEBAR to] exit. On 12/13/2018 at 10:55 PM, ronjonp said: Actually .. maybe this: (defun c:foo (/ d i g s) ;; RJP » 2018-12-13 (cond ((and (setq d (getdist "\nEnter nudge distance: ")) (setq s (ssget ":L"))) (setq s (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))) (while (and (setq g (grread 2 1)) (not (member (cadr g) '(13 32)))) (princ "\r4A-LEFT 6D-RIGHT 2S-DOWN 8W-UP [ENTER/SPACEBAR to Exit]") (cond ((= 2 (car g)) (setq g (strcase (chr (cadr g)))) (if (setq i (cond ((wcmatch g "2,S") (list 0. (- d) 0.)) ((wcmatch g "4,A") (list (- d) 0. 0.)) ((wcmatch g "6,D") (list d 0. 0.)) ((wcmatch g "8,W") (list 0. d 0.)) ) ) (foreach x s (vlax-invoke x 'move '(0. 0. 0.) i)) ) ) ) ) ) ) (princ) ) Quote
BIGAL Posted December 1, 2020 Posted December 1, 2020 Did you look at my CHX you can have CHY CHZ also it accepts positive and -ve numbers so CHX -20 will go left 20 will go right and its pick pick method Quote
yxl030 Posted December 2, 2020 Posted December 2, 2020 That would require running the lisp multiple times,and entering different values。 Ronjonp‘s Lisp ,entering the same number can move an object in four directions。More suitable for my use,But it's too difficult for me。 6 hours ago, BIGAL said: Did you look at my CHX you can have CHY CHZ also it accepts positive and -ve numbers so CHX -20 will go left 20 will go right and its pick pick method Quote
ronjonp Posted December 2, 2020 Posted December 2, 2020 Try this: (defun c:foo (/ d i g s) ;; RJP » 2020-12-01 (if (setq d (getdist "\nEnter nudge distance: ")) (while (setq s (ssget ":L")) (setq s (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))) (while (and (setq g (grread 2 1)) (not (member (cadr g) '(13 32)))) (princ "\r4A-LEFT 6D-RIGHT 2S-DOWN 8W-UP [ENTER/SPACEBAR to Exit]") (cond ((= 2 (car g)) (setq g (strcase (chr (cadr g)))) (if (setq i (cond ((wcmatch g "2,S") (list 0. (- d) 0.)) ((wcmatch g "4,A") (list (- d) 0. 0.)) ((wcmatch g "6,D") (list d 0. 0.)) ((wcmatch g "8,W") (list 0. d 0.)) ) ) (foreach x s (vlax-invoke x 'move '(0. 0. 0.) i)) ) ) ) ) ) ) (princ) ) Quote
yxl030 Posted December 2, 2020 Posted December 2, 2020 ronjonp,Thank you for your reply so quickly. That's pretty much it. Can you make the program like this: [press the 4a/5s/6d/8w] after the object is moved, allowed to select a new object immediately ? Now that this one is waiting for the arrow key again, it's easy to make an error by moving the object again. Quote
yxl030 Posted December 2, 2020 Posted December 2, 2020 By the way, I often divide a picture drawn together into 3 or 4 pictures. Your program is very helpful to me. Quote
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.