Author Topic: Flip Attributed Block  (Read 138 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 1996
Flip Attributed Block
« 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.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7042
Re: Flip Attributed Block
« Reply #1 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. )

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 1996
Re: Flip Attributed Block
« Reply #2 on: November 06, 2019, 10:25:44 AM »
Thank you, Iíll give it try after lunch.

Thanks Ron!!!
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 1996
Re: Flip Attributed Block
« Reply #3 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.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7042
Re: Flip Attributed Block
« Reply #4 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. )

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 1996
Re: Flip Attributed Block
« Reply #5 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.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7042
Re: Flip Attributed Block
« Reply #6 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:

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 1996
Re: Flip Attributed Block
« Reply #7 on: November 06, 2019, 12:21:34 PM »
I almost tried that change...
Thanks again!!!!!!!!!!!!!!!!!

Works perfectly



Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7042
Re: Flip Attributed Block
« Reply #8 on: November 06, 2019, 02:10:04 PM »
Glad to help :)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC