Author Topic: Check Dwg for Mirrored blocks  (Read 3339 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Check Dwg for Mirrored blocks
« on: October 14, 2004, 05:13:19 PM »
I have this code to go through the entire drawing to check for any block that is mirrored and if any draw a circle from the insertion point of any blocks found. My question is, is there a better way or another way this can be written? Also, I would like this to report via command prompt how many it found.


Code: [Select]

(defun c:mblk ()
  (setq cmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command ".layer" "s" "0" "")
  (setq savosmode (getvar "OSMODE"))
  (command ".layer" "on" "0" "thaw" "0" "unlock" "0" "")
  (setvar "osmode" 0)
  (setq blks (ssget "x" '((0 . "INSERT"))))
  (setq count (sslength blks))
  (setq count (sslength blks))
  (setq index 0)
  (repeat count
    (setq b1 (entget (ssname blks index)))
    (setq b2 (cdr(assoc 41 b1)))
    (setq b3 (rtos b2 2 0))
    (setq b4 (substr b3 1 1))
    (if (= b4 "-")
      (progn
 (setq c1 (cdr(assoc 10 b1)))
 (command "circle" c1 50)
 );end progn
      );end if
    (setq index (+ index 1))
    );end repeat
  (setvar "CMDECHO" cmd)
  (setvar "OSMODE" savosmode)
  (princ)
)
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Check Dwg for Mirrored blocks
« Reply #1 on: October 14, 2004, 05:50:55 PM »
In my opinion it is better to separate a solution to a particular problem into logical functions, each function doing exactly one thing (and one thing only), and then the program, which is a collection of functions, solves the problem. Not only does it make it far easier to analyze the problem and distribute the responsibility of the "work" logically, it is a cornerstone of code re-use.

In this case I see a total of 4 functions: one to find mirrored inserts, one to cycle thru a selection set and apply an affect to the members of that selection set, one that applies a specific effect upon an entity and then finally a c:function which calls the afore mentioned functions comprising "the solution" appropriately such that the problem is solved and accessible to the user as a command line utility.

Passing batton ...

Edit: Removed superfluous code.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

SMadsen

  • Guest
Check Dwg for Mirrored blocks
« Reply #2 on: October 14, 2004, 05:51:07 PM »
You can grab all mirrored block by adding a relational filter:

(setq sset (ssget "X" '((0 . "INSERT")(-4 . "<")(41 . 0))))

This will only include inserts that has an x-scale factor lesser than 0.

*didn't see Mr. Puckett sneak in there*

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Check Dwg for Mirrored blocks
« Reply #3 on: October 14, 2004, 05:55:02 PM »
<cough>, that's what I meant. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Check Dwg for Mirrored blocks
« Reply #4 on: October 14, 2004, 08:35:10 PM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Check Dwg for Mirrored blocks
« Reply #5 on: October 15, 2004, 08:53:41 AM »
Ok, here is my revised code. Thanks to everyone.

Code: [Select]

(defun c:Mblk ()
(setq cmd (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(command ".layer" "on" "0" "thaw" "0" "unlock" "0" "")
(command ".layer" "s" "0" "")
(setq savosmode (getvar "OSMODE"))
(setvar "osmode" 0)
(setq sset (ssget "X" '((0 . "INSERT")(-4 . "<")(41 . 0))))
    (if (/= sset nil)
      (progn
      (setq i (sslength sset))
      (setq index 0)
(repeat i
(setq b1 (entget (ssname sset index)))
(setq c1 (cdr(assoc 10 b1)));;find block insertion
(command "circle" c1 50);;<----Draw a circle from block insertion
(setq index (+ index 1))
)
(prompt (strcat "\n*-* " (itoa i) " - Mirrored Blocks found!  Please FIX....*-*"))
      )
(prompt "No Mirrored Blocks Found! Have a nice day....")
)
(setvar "CMDECHO" cmd)
(setvar "OSMODE" savosmode)
(princ)
)


The purpose is to locate any blocks such as doors, toilet fixtures etc... and locate them on the floor plan so that the user can go in and fix. I like the un-mirror lisp as well but if a door is inserted in place and then mirrored then un-mirroring it will of course flip the door, hence it will be incorrect door swing and location.

The end result is BLOCKS should never (in my opinion) be MIRROR'ed. This will cause problems for anyone in the future revising that block.

My 2 cents...

Thanks again guys..
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

SMadsen

  • Guest
Check Dwg for Mirrored blocks
« Reply #6 on: October 15, 2004, 09:01:56 AM »
Heh what a polite prompt ..
Code looks good.