leonucadomi Posted August 4, 2022 Posted August 4, 2022 hello people: can you help me with a routine to move objects but only move in coordinate "x" or "y" or "z" something like moving with filters but in routine thanks Any help is welcome Quote
BIGAL Posted August 4, 2022 Posted August 4, 2022 You can write little lisp for move X Y Z etc. Load on say startup. (defun C:CHX ( / ht sn) (SETVAR "CMDECHO" 0) (setq sn (getvar "osmode")) (command "osnap" "near") (princ "\nalters object in X direction") (setq ht (getstring "\n What is amount of change: ")) (setq newht (strcat ht ",0,0")) (while (setq newobj (entsel "\nPoint to object: ")) (command "move" newobj "" "0,0,0" newht) ) (setvar 'osmode sn) (princ) ) I will let you work out Y & Z Quote
Jonathan Handojo Posted August 5, 2022 Posted August 5, 2022 (edited) I normally use this at work... When prompting points in AutoCAD, AutoCAD supports ".X", ".Y" and ".Z" filters that allows you to click a point that fixes the X, Y or Z depending on what's picked. What you're looking for is MX and MY (Move along X) and (Move along Y), but I had other command like COPY, STRETCH and LINE: (defun c:lx nil (CommandDirection (list "_LINE" pause) ".Y")) (defun c:ly nil (CommandDirection (list "_LINE" pause) ".X")) (defun c:cx (/ ss) (if (setq ss (ssget "_:L")) (CommandDirection (list "_COPY" ss "" pause) ".Y"))) (defun c:cy (/ ss) (if (setq ss (ssget "_:L")) (CommandDirection (list "_COPY" ss "" pause) ".X"))) (defun c:mx (/ ss) (if (setq ss (ssget "_:L")) (CommandDirection (list "_MOVE" ss "" pause) ".Y"))) (defun c:my (/ ss) (if (setq ss (ssget "_:L")) (CommandDirection (list "_MOVE" ss "" pause) ".X"))) (defun c:sx (/ ss) (if (setq ss (ssget "_:L")) (CommandDirection (list "_STRETCH" ss "" pause) ".Y"))) (defun c:sy (/ ss) (if (setq ss (ssget "_:L")) (CommandDirection (list "_STRETCH" ss "" pause) ".X"))) ;; Command Direction - Jonathan Handojo ;; Creates a command that constraints point prompts to X, Y or Z axis. ;; cmd - a list of strings to pass into the AutoCAD command function. ;; => The last string in the list must be a point selection. ;; dir - a string of either ".X", ".Y" or ".Z" (defun CommandDirection (cmd dir) (apply 'command cmd) (while (not (zerop (getvar "cmdactive"))) (command dir "@0,0,0" pause) ) ) Edited August 5, 2022 by Jonathan Handojo 1 Quote
leonucadomi Posted August 5, 2022 Author Posted August 5, 2022 I use this one that I made but sometimes it works and sometimes it moves the object to another side I don't know what is wrong (defun c:-7 (/ pt1 pt2 pt3 P1Y P1Z P2X) (princ "\nMove in X") (setvar "cmdecho" 0) (command "_osmode" "16383") (setq ss (ssget)) (setq pt1 (getpoint "\nSelecciona punto de origen: ")) (setq pt2 (getpoint "\nSelecciona punto de destino: ")) (setq P1Y (cadr pt1)) (setq P1Z (caddr pt1)) (setq P2X (car pt2)) (setq pt3 (list P2X P1Y P1Z)) (progn (command "_osmode" "0") (command "_move" ss "" pt1 pt3 "") (command "_osmode" "16383") (setvar "cmdecho" 1) ) (princ "\nObjeto desplazado...") (princ) );fin defun Quote
Jonathan Handojo Posted August 5, 2022 Posted August 5, 2022 (edited) 6 hours ago, leonucadomi said: I use this one that I made but sometimes it works and sometimes it moves the object to another side I don't know what is wrong (defun c:-7 (/ pt1 pt2 pt3 P1Y P1Z P2X) (princ "\nMove in X") (setvar "cmdecho" 0) (command "_osmode" "16383") (setq ss (ssget)) (setq pt1 (getpoint "\nSelecciona punto de origen: ")) (setq pt2 (getpoint "\nSelecciona punto de destino: ")) (setq P1Y (cadr pt1)) (setq P1Z (caddr pt1)) (setq P2X (car pt2)) (setq pt3 (list P2X P1Y P1Z)) (progn (command "_osmode" "0") (command "_move" ss "" pt1 pt3 "") (command "_osmode" "16383") (setvar "cmdecho" 1) ) (princ "\nObjeto desplazado...") (princ) );fin defun I really don't see anything wrong with the code you've put up. It seems to work perfectly fine on my end. My guess is that you're probably working with xrefs and then your snap point when prompting just goes to the insertion point of the xref? It seems to be a very common problem for me as well. But otherwise, you may need to describe what you mean by "another side". If anything, you can simplify it to something like this: (defun c:-7 ( / ) (command "_move" (ssget) "" pause ".Y" "_non" "@0,0,0" pause) ) Edited August 5, 2022 by Jonathan Handojo Quote
leonucadomi Posted August 5, 2022 Author Posted August 5, 2022 WHAT I SAY IS THAT SOMETIMES IT WORKS AND OTHERS IT DOESN'T. ESPECIALLY WHEN I HAVE THE PERSPECTIVE VIEW AS IF YOU DO NOT RESPECT THE SNAP Quote
leonucadomi Posted August 5, 2022 Author Posted August 5, 2022 (defun c:-7 ( / ) (command "_move" (ssget) "" pause ".Y" "_non" "@0,0,0" pause) ) DOES NOT WORK MOVE BY MODIFYING X , Y AND Z Quote
Jonathan Handojo Posted August 5, 2022 Posted August 5, 2022 Ah, I was under the assumption that you work in 2D. If you're working in 3D, then change ".Y" to ".YZ" to move along X, ".XZ" to move along Y, and ".XY" to move along Z. Quote
BIGAL Posted August 5, 2022 Posted August 5, 2022 Almost forgot for X & Y Move select objects pick a point press F8 drag mouse in direction required type in the offset all done Quote
Jonathan Handojo Posted August 5, 2022 Posted August 5, 2022 Nice one @BIGAL, I also nearly forgot that one. Quote
BIGAL Posted August 5, 2022 Posted August 5, 2022 Yeah we get carried away some times with code solutions. 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.