LISP routine to change X scale of blocks from 1 to -1

LISP routine to change X scale of blocks from 1 to -1

dcalhounGT6GH
Contributor Contributor
1,380 Views
6 Replies
Message 1 of 7

LISP routine to change X scale of blocks from 1 to -1

dcalhounGT6GH
Contributor
Contributor

I'm trying to select all blocks in my drawing with "MIR" in the block name, then change the X Scale of all of those blocks from 1 to -1, then explode those same blocks.


If there is a better way to mirror those same blocks about their individual insertion points in the X-axis, that will work too. I'm just wanting to keep all blocks in their original place, as they need to land in pre-existing viewports that will have been set up.


So far I have this, but it mirrors all of my blocks over the same point. Any help would be greatly appreciated!


;MIRRORS ALL BLOCKS WITH "MIR" PREFIX IN NAME
(defun c:M-ONLY (/ SS1)
(setq SS1 (ssget "X" (list '(0 . "INSERT") (cons 2 "*MIR*"))))
(command "_.MIRROR" ss1 "" "_non" (trans (cdr (assoc 10 (entget (ssname ss1 0)))) 0 1) "_non" "@0,1" "_Yes")))
(princ)
)

0 Likes
Accepted solutions (2)
1,381 Views
6 Replies
Replies (6)
Message 2 of 7

SeeMSixty7
Advisor
Advisor

You don't have to use AutoLISP to do this. Simply use QSELECT and then from the properties pallet change the X-SCale to -1.0

 

If you are just wanting to do with LISP as a learning exercise then let us know.

 

Good luck

0 Likes
Message 3 of 7

dcalhounGT6GH
Contributor
Contributor

Thanks for the quick reply! I know how to do this manually, but will be doing this in hundreds of drawings and possibly thousands of times, as needed, so if there is any way to change the X Scale parameter via the command line, in a LISP routine, etc., that would be best.

Message 4 of 7

ronjonp
Mentor
Mentor
Accepted solution

@dcalhounGT6GH 

Give this a whirl:

(defun c:m-only	(/ o s)
  (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "*MIR*"))))
    (foreach e (mapcar 'cadr (ssnamex s))
      (if (vlax-write-enabled-p (setq o (vlax-ename->vla-object e)))
	(vla-put-xscalefactor o -1)
      )
    )
  )
  (princ)
)
Message 5 of 7

CodeDing
Advisor
Advisor

Poop, I'm slow. But I guess I accounted for dynamic scale factors affecting the blocks, so that has to count for something lol.

 

My version:

(defun c:TEST ( / ss cnt len e)
  (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "*MIR*"))))
    (progn
      (setq cnt (sslength ss) len cnt)
      (repeat cnt
        (setq e (ssname ss (setq cnt (1- cnt))))
        (setpropertyvalue e "ScaleFactors/X" (* -1 (getpropertyvalue e "ScaleFactors/X")))
      );repeat
      (prompt (strcat "\nComplete. Successfully mirrored " (itoa len) " blocks."))
    );progn
  ;else
    (prompt "\nNo blocks found that require mirroring. No actions performed.")
  );if
  (princ)
);defun

 

Best,

~DD

Message 6 of 7

dcalhounGT6GH
Contributor
Contributor
That's exactly what I needed! All I need now is to add in to explode the previous selection. Thank you for your help!
Message 7 of 7

ronjonp
Mentor
Mentor
Accepted solution

@dcalhounGT6GH 

Glad to help 🙂 .. here's a version that will perform the explode as well.

(defun c:m-only	(/ o s)
  (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "*MIR*"))))
    (foreach e (mapcar 'cadr (ssnamex s))
      (if (vlax-write-enabled-p (setq o (vlax-ename->vla-object e)))
	(progn (vla-put-xscalefactor o -1) (vla-explode o) (vla-delete o))
      )
    )
  )
  (princ)
)