confutatis Posted July 13, 2021 Posted July 13, 2021 (defun c:MoveXY (/ ss i e xnew ynew r e) (vl-load-com) (if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1)))) (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (cond (and (setq xnew (assoc "X" (mapcar '(lambda (j) (list (vla-get-tagstring j) (distof (vla-get-textstring j)))) (vlax-invoke e 'Getattributes) ) ) ) (setq ynew (assoc "Y" (mapcar '(lambda (j) (list (vla-get-tagstring j) (distof (vla-get-textstring j)))) (vlax-invoke e 'Getattributes) ) ) ) (vla-put-insertionpoint e (vlax-3d-point (list (cadr xnew) (cadr ynew)))) ) ) ) ) (princ) ) That should do it. You should just replace the two tagstrings "X" and "Y", since I don't know what your tags are for these two attributes. 1 Quote
Orbitek Posted July 13, 2021 Posted July 13, 2021 Thanks for the effort and time. It works like clockwork! Have a nice day Quote
Orbitek Posted July 13, 2021 Posted July 13, 2021 After more testing, the result is sometimes nil in situations where I select blocks that have one or both XY attributes empty. To be clear. Some of the blocks relatively often have empty attributes and in that case if I select both blocks that have correctly filled XY attributes and those blocks that have empty XY attributes then the program does not execute correctly or nil. Is it possible to fine tune that too ?! thank you Quote
confutatis Posted July 13, 2021 Posted July 13, 2021 (defun c:MoveXY (/ ss i e xnew ynew) (vl-load-com) (if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1)))) (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (cond (and (setq xnew (assoc "X" (mapcar '(lambda (j) (list (vla-get-tagstring j) (distof (vla-get-textstring j)))) (vlax-invoke e 'Getattributes) ) ) ) (setq ynew (assoc "Y" (mapcar '(lambda (j) (list (vla-get-tagstring j) (distof (vla-get-textstring j)))) (vlax-invoke e 'Getattributes) ) ) ) (if (and (cadr xnew) (cadr ynew)) (vla-put-insertionpoint e (vlax-3d-point (list (cadr xnew) (cadr ynew)))) ) ) ) ) ) (princ) ) I have inserted the condition that the block only moves if the x and y coordinates exist. (if (and (cadr xnew) (cadr ynew)) (vla-put-insertionpoint e (vlax-3d-point (list (cadr xnew) (cadr ynew)))) ) 1 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.