Author Topic: Mirror a plan and keeping blocks  (Read 1573 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Mirror a plan and keeping blocks
« on: May 05, 2014, 05:17:51 AM »
In some project we have a building and mirror of the same building, So we draft one plan and mirror the second one, but we facing a problem that the blocks mirrored
So, Is there a way to Mirror a plan and keeping blocks as it is?

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Mirror a plan and keeping blocks
« Reply #1 on: May 05, 2014, 07:53:47 AM »
Here is a simple program to mirror every object in a selection except blocks:
Code: [Select]
(defun c:mymirror ( / f i o p q s )
    (if (and (setq s (ssget "_:L"))
             (setq p (getpoint "\nSpecify 1st point of mirror line: "))
             (setq q (getpoint "\nSpecify 2nd point of mirror line: " p))
        )
        (progn
            (initget "Yes No")
            (setq f (= "Yes" (getkword "\nErase source objects? [Yes/No] <No>: "))
                  p (trans p 1 0)
                  q (trans q 1 0)
            )
            (repeat (setq i (sslength s))
                (setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
                (if (= "AcDbBlockReference" (vla-get-objectname o))
                    (vlax-invoke (vla-copy o) 'move (vlax-get o 'insertionpoint) (LM:reflect (vlax-get o 'insertionpoint) p q))
                    (vlax-invoke o 'mirror p q)
                )
                (if f (vla-delete o))
            )
        )
    )
    (princ)
)

;; Reflect  -  Lee Mac
;; Reflects a point 'p' in the line given by (a,b)

(defun LM:reflect ( p a b / s v w )
    (setq v (mapcar '- a b)
          w (mapcar '- p b)
          s (/ (apply '+ (mapcar '* v w)) (apply '+ (mapcar '* v v)) 0.5)
    )
    (mapcar '(lambda ( a b c ) (+ c (- (* a s) b))) v w b)
)

(vl-load-com) (princ)

This thread may also be of interest: Mirror Block Without Mirroring Text


HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Mirror a plan and keeping blocks
« Reply #2 on: May 06, 2014, 05:09:40 AM »
thanks LEE.
Working perfict with blocks wich aligned to mirror line but other blocks have a posision problem.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Mirror a plan and keeping blocks
« Reply #3 on: May 06, 2014, 05:41:25 PM »
Sorry, this is because the program uses the block insertion point as a base point for the mirror operation, and simply displaces the block reference by twice the vector from the block insertion point to a perpendicular point on the mirror line.

For better results, perhaps the center of the block bounding box should be used.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Mirror a plan and keeping blocks
« Reply #4 on: May 07, 2014, 07:12:49 AM »
Code: [Select]
(defun c:mymirror ( / f i o p q s
   lst mix miy mxx mxy n1 n2 n3 n4 p p3 p3x p3y p4 p4x p4y q xd xn1 xn2 xn3 xn4 yd yn1 yn2 yn3 yn4)
  (if (and (setq s (ssget "_:L"))
   (setq p (getpoint "\nSpecify 1st point of mirror line: "))
   (setq q (getpoint "\nSpecify 2nd point of mirror line: " p))        )
    (progn
      (initget "Yes No")
      (setq f (= "Yes" (getkword "\nErase source objects? [Yes/No] <No>: ")))
      (setq p (trans p 1 0))
      (setq q (trans q 1 0))
     
  (repeat (setq i (sslength s))
    (setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
    (if (= "AcDbBlockReference" (vla-get-objectname o))
      (progn
(setq lst (LM:boundingbox o))
(setq xd (- (nth 0 q) (nth 0 p)))
(setq yd (- (nth 1 q) (nth 1 p)))
(setq n1  (nth 0 lst))
(setq xn1 (nth 0 n1))
(setq yn1 (nth 1 n1))
(setq n2  (nth 1 lst))
(setq xn2 (nth 0 n2))
(setq yn2 (nth 1 n2))
(setq n3  (nth 2 lst))
(setq xn3 (nth 0 n3))
(setq yn3 (nth 1 n3))
(setq n4  (nth 3 lst))
(setq xn4 (nth 0 n4))
(setq yn4 (nth 1 n4))
(setq mxx (min xn1 xn2 xn3 xn4))
(setq mxy (min yn1 yn2 yn3 yn4))
(setq mix (max xn1 xn2 xn3 xn4))
(setq miy (max yn1 yn2 yn3 yn4))
(setq p3x (/ (+ mxx mix) 2))
(setq p3y (/ (+ mxy miy) 2))
(setq p4x (+ p3x xd))
(setq p4y (+ p3y yd))

(setq p3 (list p3x p3y 0))
(setq p4 (list p4x p4y 0))

(vlax-invoke o 'mirror p q)
(vlax-invoke o 'mirror p3 p4)
)      
      ;(vlax-invoke (vla-copy o) 'move (vlax-get o 'insertionpoint) (LM:reflect (vlax-get o 'insertionpoint) p q))
      (vlax-invoke o 'mirror p q)
      )
    (if f (vla-delete o))
    )
      )
    )
  (princ)
  )