TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: GDF on November 06, 2019, 08:47:07 AM

Title: Flip Attributed Block
Post by: GDF on November 06, 2019, 08:47:07 AM
I would like to flip all attributed blocks named SYMRM in a drawing automatically in lieu of selecting them one at a time.
The code I have below is not very good...please help.

Code - Auto/Visual Lisp: [Select]
  1. (defun ARCH:DTOR (degr) (/ (* degr pi) 180))
  2.  
  3. (defun C:FIA  (/ objx insx1 insx2)
  4.   (prompt "\n* Flip Attribute Block: \"SYMRM\"")
  5.   (setq objx (entget (car (entsel "\n* Select Block to Flip:"))))
  6.   (setq insx1 (cdr (assoc 10 objx)))
  7.   (setq insx2 (polar insx1 (ARCH:DTOR 180.0) 1))
  8.   (command "mirror" (cdr (assoc -1 objx)) "" insx1 insx2 "y")
  9.   (command "ATTSYNC" "N" "SYMRM")
  10.   (princ))
  11.  

Thanks for any assistance.
Title: Re: Flip Attributed Block
Post by: ronjonp on November 06, 2019, 09:38:30 AM
I use this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:br180 (/ s o)
  2.   (if (setq s (ssget ":L"))
  3.     (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  4.       (if (vlax-property-available-p (setq o (vlax-ename->vla-object e)) 'rotation)
  5.         (vla-put-rotation o (+ pi (vla-get-rotation o)))
  6.       )
  7.     )
  8.   )
  9.   (princ)
  10. )
Title: Re: Flip Attributed Block
Post by: GDF on November 06, 2019, 10:25:44 AM
Thank you, I’ll give it try after lunch.

Thanks Ron!!!
Title: Re: Flip Attributed Block
Post by: GDF on November 06, 2019, 10:57:18 AM
Your routine rotates the attributed block, and I need it to mirrored.

I have included the block that I use in the drawing file that has been mirrored. Therefore the all SymRM attributed blocks needs to be unmirrored in the file.
Title: Re: Flip Attributed Block
Post by: ronjonp on November 06, 2019, 11:14:06 AM
Give this a try Gary :)
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ s o)
  2.   (setvar 'mirrtext 0)
  3.   (if (setq s (ssget ":L" '((0 . "insert") (2 . "SYMRM"))))
  4.     (foreach o (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
  5.       (vlax-invoke o 'mirror (setq p (vlax-get o 'insertionpoint)) (mapcar '+ p '(0 1 0)))
  6.       (vla-delete o)
  7.     )
  8.   )
  9.   ;; (command "ATTSYNC" "N" "SYMRM")
  10.   (princ)
  11. )
Title: Re: Flip Attributed Block
Post by: GDF on November 06, 2019, 11:38:57 AM
Wow...this is harder to explain than I thought.

See the example dwg enclosed...the block on the left is in the correct orientation. The one on the right needs to be mirrored. All of these blocks in the file need to be flipped to look like the on one the left side.
Title: Re: Flip Attributed Block
Post by: ronjonp on November 06, 2019, 12:04:26 PM
Wow...this is harder to explain than I thought.

See the example dwg enclosed...the block on the left is in the correct orientation. The one on the right needs to be mirrored. All of these blocks in the file need to be flipped to look like the on one the left side.
Change this:
Code - Auto/Visual Lisp: [Select]
  1. (mapcar '+ p '(0 1 0))
To this:
Code - Auto/Visual Lisp: [Select]
  1. (mapcar '+ p '(1 0 0))

It's usually a good idea to include a before and after drawing  :wink:
Title: Re: Flip Attributed Block
Post by: GDF on November 06, 2019, 12:21:34 PM
I almost tried that change...
Thanks again!!!!!!!!!!!!!!!!!

Works perfectly



Title: Re: Flip Attributed Block
Post by: ronjonp on November 06, 2019, 02:10:04 PM
Glad to help :)