Mountain_XD Posted November 21, 2024 Posted November 21, 2024 How can I arrange rectangles with a distance that the user enters at the command line? Arrange Rectangles.dwg Quote
Saxlle Posted November 21, 2024 Posted November 21, 2024 Hi @Mountain_XD, Try this: (prompt "\To run a LISP type: DISP") (defun c:DISP ( / dist base_dist ss len i ename) (setq dist (getreal "\nEnter the value for equal displacement:")) (setq base_dist dist) (princ) (prompt "\nSelect entities for displacement:") (setq ss (ssget)) (setq len (sslength ss) i 0 ) (while (< i len) (setq ename (ssname ss i)) (command "._move" ename "" "d" dist) (setq dist (+ dist base_dist)) (setq i (1+ i)) ) (prompt "\The displacement were done.") (princ) ) When entering a value for "equal displacement" it can be negative or positive value (eg. "-10" will displacement selected entities to the left side, "+10" to the right side). First, select the "green" rectangles to displacement, then run LISP again and select everything inside the "green" rectangle. Best regards. Quote
Mountain_XD Posted November 21, 2024 Author Posted November 21, 2024 Thank you so much Saxlle The first problem is that the first rectangle doesn't move. The second, is there any way to make the objects inside that rectangle move at the same time? Quote
Saxlle Posted November 21, 2024 Posted November 21, 2024 (edited) Try this modification, you just need to select all the rectangles and do NOT select anything inside them: (defun c:DISP ( / dist base_dist ss len i ename coords ssn ssn_len) (setq dist (getreal "\nEnter the value for equal displacement:")) (setq base_dist dist) (princ) (prompt "\nSelect RECTANGLES entities for displacement:") (setq ss (ssget)) (setq len (sslength ss) i 0 ) (while (< i len) (setq ename (ssname ss i)) (setq coords (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ename)))) (setq ssn (ssget "WP" coords)) (command "._move" ename "" "d" dist) (setq ssn_len (sslength ssn)) (repeat ssn_len (command "._move" (ssname ssn (setq ssn_len (1- ssn_len))) "" "d" dist) ) (setq dist (+ dist base_dist)) (setq i (1+ i)) ) (prompt "\The displacement were done.") (princ) ) 1 hour ago, Mountain_XD said: The second, is there any way to make the objects inside that rectangle move at the same time? The above update code will solve that. 1 hour ago, Mountain_XD said: The first problem is that the first rectangle doesn't move I don't see why do you need to displacement first rectangle? But, i tried with first rectangle and it works for me. Edited November 21, 2024 by Saxlle Edited a code for multiple entities displacement inside of rectangle Quote
Mountain_XD Posted November 22, 2024 Author Posted November 22, 2024 Hi Saxlle, you can check new file DWG. Thank you so much Arrange Rectangles_01.dwg Quote
Saxlle Posted November 22, 2024 Posted November 22, 2024 Hi @Mountain_XD Last modification: ; ******************************************************************************************************* ; Functions : DISP ; Description : Equal displacement of the RECTANGLES and everything inside them ; Author : SAXLLE ; Date : November 21, 2024 ; Update 1.0 : Added value to Y and Z to create list with variable dist -- > (list dist 0.0 0.0) ; Update date : November 22, 2024 ; ******************************************************************************************************* (prompt "\To run a LISP type: DISP") (defun c:DISP ( / dist base_dist ss len i ename coords ssn ssn_len) (setq dist (getreal "\nEnter the value for equal displacement:")) (setq base_dist dist) (princ) (prompt "\nSelect RECTANGLES entities for displacement:") (setq ss (ssget)) (setq len (sslength ss) i 0 ) (while (< i len) (setq ename (ssname ss i)) (setq coords (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ename)))) (setq ssn (ssget "WP" coords)) (command "._move" ename "" "d" (list dist 0.0 0.0)) (setq ssn_len (sslength ssn)) (repeat ssn_len (command "._move" (ssname ssn (setq ssn_len (1- ssn_len))) "" "d" (list dist 0.0 0.0)) ) (setq dist (+ dist base_dist)) (setq i (1+ i)) ) (prompt "\The displacement were done.") (princ) ) I checked the dwg, ran the latest updated lisp and everything works fine. Try it and see if it works for you? Also, see the attached video. Best regards. DISP.mp4 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.