Jump to content

Better Code for Mirroring Object


Bill Tillman

Recommended Posts

I'm using a simple code to insert a block, it uses ENTMAKE. This is my preferred method to using COMMAND... and it's much faster. In some instances when the block is inserted I need to mirror it about it's insert point and erase the old copy. The code I came up with works fine but it uses the command method and it's noticeably slower. Only by a second or two but it is noticeable. So trying to expand my skill set I was wondering if there is a better method for handling this task.

(command-s "._MIRROR" (entlast) "" pt "Y")

Link to comment
Share on other sites

Hi, you could set the x or y scale to negative with entmod..

 

(setq e (entget (entlast)))
(setq e (subst (cons 41 (- (cdr (assoc 41 e))))(assoc 41 e) e)) ; 42 for y axis
(entmod e)

  • Thanks 1
Link to comment
Share on other sites

Elaborating FranknBeans's suggestion - consider this example, by combining with my favourite grread function:

 

; Flip block example - with (grread)
(defun C:test ( / e enx g s k itm )
 (and
   (setq e (car (entsel "\nPick a block to flip: "))) 
   (member '(0 . "INSERT") (setq enx (entget e)))
   (princ "\nPress [X/Y/Z] to flip the block <exit>: ")
   (while (not s) (setq g (grread)) 
     (cond 
       ( (or (eq g '(2 13)) (= 25 (car g))) (setq s T) )
       ( (= 2 (car g)) 
         (and
           (setq k (cadr (assoc (strcase (chr (cadr g))) '(("X" 41)("Y" 42)("Z" 43)))))
           (setq itm (assoc k enx))
           (entmod (setq enx (subst (cons k (- (cdr itm))) itm enx)))
         )
       )
     ); cond
   ); while
 ); and
 (princ)
); defun C:test

Link to comment
Share on other sites

Once again this forum is filled with the greatest people. Thanks for the help. I put FrankNBeans example to work earlier and it's working great.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...