Author Topic: [Community Project] Clean Drawing Program  (Read 19673 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: [Community Project] Clean Drawing Program
« Reply #30 on: March 25, 2015, 02:50:56 PM »
Think it is not a good idea to put all purge routines in single command because lisp is too slow even if compiled. On huge drawings it will freeze or even crash autocad


If you just use a simple wblock it's not slow at all.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: [Community Project] Clean Drawing Program
« Reply #31 on: March 25, 2015, 03:02:02 PM »
There are a number of precautions one need take when using wblock * (or -ExportToAutoCAD yada) to ensure things don't FUBAR on you. This includes making sure the WCS is active in all paper-space resident viewports and model-space before performing the export. Failure to ensure will sometimes produce wack-a-doodle, undersirable results ...

/Red Sector A
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7526
Re: [Community Project] Clean Drawing Program
« Reply #32 on: March 25, 2015, 04:33:06 PM »
There are a number of precautions one need take when using wblock * (or -ExportToAutoCAD yada) to ensure things don't FUBAR on you. This includes making sure the WCS is active in all paper-space resident viewports and model-space before performing the export. Failure to ensure will sometimes produce wack-a-doodle, undersirable results ...

/Red Sector A


Funny you say that .. noticed that many moons back when I wblocked some files with twisted UCS set to view and shite was out in space :)


Fixed it with:
Code - Auto/Visual Lisp: [Select]
  1. (setvar 'tilemode 1)
  2. (command "_.ucs" "_World")
  3. (command "._-wblock" file "*")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: [Community Project] Clean Drawing Program
« Reply #33 on: March 25, 2015, 05:02:25 PM »
Yep ... and post processing is required to fix other wblock | exporttoautocad | yada aberrations. For example: wipeouts.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: [Community Project] Clean Drawing Program
« Reply #34 on: March 29, 2015, 06:25:41 AM »
I belive this part of code ahould be considered (copied from another thread)
Code: [Select]
  ((lambda (dict)
     (if (dictsearch (namedobjdict) dict)
       (progn
(dictremove (namedobjdict) dict)
(princ "\nDGN Line Styles Removed")
       )
       (princ "\nDGN Line Styles not found")
     )
   )
    "ACAD_DGNLINESTYLECOMP"
  ) ;Delete DGN

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: [Community Project] Clean Drawing Program
« Reply #35 on: March 29, 2015, 06:28:14 AM »
This too
Code: [Select]
(vl-load-com)
(setq doc (vla-get-ActiveDocument (setq *acad (vlax-get-Acad-Object))))

(progn
  (vlax-for layer (vla-get-Layers doc)
    (vl-catch-all-apply
      'vla-Remove
      (list (vla-GetExtensionDictionary layer)
    "ADSK_XREC_LAYER_RECONCILED"
      )
    ) ;(vl-catch-all-apply 'vla-Delete (list (vla-GetExtensionDictionary layer)))
  )
  (princ "\nRECONCILED Layers Removed")
) ; Delete reconciled filter

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: [Community Project] Clean Drawing Program
« Reply #36 on: March 29, 2015, 12:48:36 PM »
This code deletes all non-acad dictionaries.
Code - Auto/Visual Lisp: [Select]
  1.             (or (/= 3 (car &))
  2.                 (wcmatch (strcase (cdr &)) "ACAD_*")
  3.                 (wcmatch (cdr &) "AcDb*")
  4.                 (dictremove (namedobjdict) (cdr &))
  5.             )
  6.           )

Peter2

  • Swamp Rat
  • Posts: 650
Re: [Community Project] Clean Drawing Program
« Reply #37 on: March 29, 2015, 12:59:36 PM »
This code deletes all non-acad dictionaries. ...
I would say it is important to make differences between "Purging" (not used) things and deleting things.
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: [Community Project] Clean Drawing Program
« Reply #38 on: March 29, 2015, 02:44:02 PM »
This code deletes all non-acad dictionaries...

I HIGHLY advise against the sledge hammer approach. For example, if you delete "Ks_ShapeRefDictionary" you are in for a world of pain and quite possibly a lynching. Not all non acad dictionaries are evil and many of them are essential. In the case of "Ks_ShapeRefDictionary" it's essential for proper loading/display even if you are a mere consumer of a model (rather than the owner/maintainer).

tl:dr: Don't be the guy who knows enough to be dangerous.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: [Community Project] Clean Drawing Program
« Reply #39 on: March 29, 2015, 03:54:16 PM »
This code deletes all non-acad dictionaries...

I HIGHLY advise against the sledge hammer approach. For example, if you delete "Ks_ShapeRefDictionary" you are in for a world of pain and quite possibly a lynching. Not all non acad dictionaries are evil and many of them are essential. In the case of "Ks_ShapeRefDictionary" it's essential for proper loading/display even if you are a mere consumer of a model (rather than the owner/maintainer).

tl:dr: Don't be the guy who knows enough to be dangerous.
Sometimes we have no choise to be or not to be a chicken. Life is also dangerous, it cause death.
At least noone said you cannot add filter mask for exceptions.

I had purged drawings deleting dictionaries 6mb->250kb, 150mb->20mb. Sure, all that MBs was very useful.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: [Community Project] Clean Drawing Program
« Reply #40 on: March 29, 2015, 04:05:13 PM »
This isn't about being a chicken. It's about judicious use of technique. As for espousing the merits of cleaning files you're preaching to the choir. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: [Community Project] Clean Drawing Program
« Reply #41 on: March 29, 2015, 05:20:40 PM »
This isn't about being a chicken. It's about judicious use of technique. As for espousing the merits of cleaning files you're preaching to the choir. :)
Some drawings like a boat floating from hands to hands. When drawing I recieve freezes my autocad I extremely need to clean all damn garbage to do my work.
I also need s/pline optimization including processing in blocks or/and to restore exploded text from lines and arcs. And of course I need to explode all proxy. So don't say me about danger. I have no idea on how to be careful  :-P

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: [Community Project] Clean Drawing Program
« Reply #42 on: March 29, 2015, 05:27:09 PM »
< .. >  And of course I need to explode all proxy. So don't say me about danger. I have no idea on how to be careful  :P




With all due respect .. In this case you will deserve all the pain that will be heaped upon your head.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: [Community Project] Clean Drawing Program
« Reply #43 on: March 29, 2015, 05:36:18 PM »
I applaud the use of these techniques to clean up bloat in drawings. My average drawing is under 200k and I regularly purge everything. If it isn't in needed "right now", it gets purged ... I also flatten and overkill often just to make dang sure there isn't anything floating about in space or overlapping unnecessarily.

I only do 2d drawings so flattening it doesn't matter .. and I don't share with others so being aggressive cleaning it up doesn't matter either.

Make sure to clean up xrefs that aren't loading and images that are no longer being loaded.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: [Community Project] Clean Drawing Program
« Reply #44 on: March 29, 2015, 05:46:19 PM »
Make sure to clean up xrefs that aren't loading and images that are no longer being loaded.

This is under construction for me
Below is VVA's version

Code - Auto/Visual Lisp: [Select]
  1. (defun C:DUXI (/ *error* file tmpObj retxref retimg retimgobj pat)
  2. ;;; Delete Unfound Xref and Image
  3. ;;; posted VVA http://forum.dwg.ru/showthread.php?t=36574
  4.   (defun *error* (msg)
  5.     (princ msg)
  6.     (mip:layer-status-restore)
  7.     (princ)
  8.   ) ;_ end of defun
  9.   (defun mip:layer-status-restore ()
  10.     (foreach item *MIP_LAYER_LST*
  11.       (if (not (vlax-erased-p (car item)))
  12.         (vl-catch-all-apply
  13.           '(lambda ()
  14.              (vla-put-lock
  15.                (car item)
  16.                (cdr (assoc "lock" (cdr item)))
  17.              ) ;_ end of vla-put-lock
  18.              (vla-put-freeze
  19.                (car item)
  20.                (cdr (assoc "freeze" (cdr item)))
  21.              ) ;_ end of vla-put-freeze
  22.            ) ;_ end of lambda
  23.         ) ;_ end of vl-catch-all-apply
  24.       ) ;_ end of if
  25.     ) ;_ end of foreach
  26.     (setq *MIP_LAYER_LST* nil)
  27.   ) ;_ end of defun
  28.  
  29.   (defun mip:layer-status-save ()
  30.     (setq *MIP_LAYER_LST* nil)
  31.     (vlax-for item
  32.                    (vla-get-layers
  33.                      (vla-get-activedocument (vlax-get-acad-object))
  34.                    ) ;_ end of vla-get-layers
  35.       (setq *MIP_LAYER_LST*
  36.              (cons (list item
  37.                          (cons "freeze" (vla-get-freeze item))
  38.                          (cons "lock" (vla-get-lock item))
  39.                    ) ;_ end of cons
  40.                    *MIP_LAYER_LST*
  41.              ) ;_ end of cons
  42.       ) ;_ end of setq
  43.       (vla-put-lock item :vlax-false)
  44.       (if (= (vla-get-freeze item) :vlax-true)
  45.         (vl-catch-all-apply
  46.           '(lambda () (vla-put-freeze item :vlax-false))
  47.         ) ;_ end of vl-catch-all-apply
  48.       ) ;_ end of if
  49.     ) ;_ end of vlax-for
  50.   ) ;_ end of defun
  51.  
  52.   (defun DetachImage (ImgName)
  53.     (vl-catch-all-apply
  54.       '(lambda ()
  55.          (vla-delete
  56.            (vla-item
  57.              (vla-item
  58.                (vla-get-dictionaries
  59.                  (vla-get-activedocument (vlax-get-acad-object))
  60.                ) ;_ end of vla-get-dictionaries
  61.                "ACAD_IMAGE_DICT"
  62.              ) ;_ end of vla-Item
  63.              ImgName
  64.            ) ;_ end of vla-Item
  65.          ) ;_ end of vla-Delete
  66.        ) ;_ end of lambda
  67.     ) ;_ end of vl-catch-all-apply
  68.   ) ;_ end of defun
  69.   (setq pat '("AcDbRasterImage" "AcDbBlockReference"))
  70.                   (vla-get-activedocument (vlax-get-acad-object))
  71.                 ) ;_ end of vla-get-Layouts
  72.     (princ "\nWait... the search for rasters and xrefs in ")(princ (vla-get-name lay))
  73.     (vlax-for item (vla-get-block lay)
  74.       (cond
  75.         ((and
  76.            (member (vla-get-objectname item) pat)
  77.            (eq (vla-get-objectname item) "AcDbBlockReference")
  78.            (vlax-property-available-p item 'Path)
  79.            (setq file (vla-get-path item))
  80.            (setq tmpObj
  81.                   (vla-item
  82.                     (vla-get-blocks
  83.                       (vla-get-activedocument (vlax-get-acad-object))
  84.                     ) ;_ end of vla-get-Blocks
  85.                     (vla-get-name item)
  86.                   ) ;_ end of vla-Item
  87.            ) ;_ end of setq
  88.          ) ;_ end of and
  89.          (if
  90.            (not (or (findfile file)
  91.                     (findfile (strcat (vl-filename-base file)
  92.                                       (vl-filename-extension file)
  93.                               ) ;_ end of strcat
  94.                     ) ;_ end of findfile
  95.                 ) ;_ end of or
  96.            ) ;_ end of not
  97.            (setq retxref (cons tmpobj retxref))
  98.          ) ;_ end of if
  99.         )
  100.         ((and
  101.            (member (vla-get-objectname item) pat)
  102.            (eq (vla-get-objectname item) "AcDbRasterImage")
  103.            (setq file (vla-get-imagefile item))
  104.          ) ;_ end of and
  105.          (if
  106.            (not (or (findfile file)
  107.                     (findfile (strcat (vl-filename-base file)
  108.                                       (vl-filename-extension file)
  109.                               ) ;_ end of strcat
  110.                     ) ;_ end of findfile
  111.                 ) ;_ end of or
  112.            ) ;_ end of not
  113.            (progn
  114.              (if (not (member (vla-get-name item) retimg))
  115.              (setq retimg (cons (vla-get-name item) retimg)))
  116.              (setq retimgobj (cons item retimgobj))
  117.            )
  118.          ) ;_ end of if
  119.         )
  120.         (t nil)
  121.       ) ;_ end of cond
  122.     ) ;_ end of vlax-for
  123.     (princ " ...OK")
  124.   ) ;_ end of vlax-for
  125.   (princ "\nTotal: ")
  126.   (princ (length retimg))(princ " unfound rasters and ")
  127.   (princ (length retxref))(princ " unfound xrefs ")
  128.   (if (or retimg retxref)
  129.     (progn
  130.   (initget "Image Xref Both")
  131.   (setq file (getkword "Delete unfound [Image/Xref/Both] <both>: "))
  132.   (cond ((= file "Image")
  133.          (setq pat '("AcDbRasterImage"))
  134.          )
  135.         ((= file "Xref")
  136.          (setq pat '("AcDbBlockReference"))
  137.          )
  138.         (t (setq pat '("AcDbRasterImage" "AcDbBlockReference")))
  139.         )
  140.   (mip:layer-status-save)
  141.   (if (member "AcDbRasterImage" pat)
  142.     (progn
  143.       (mapcar '(lambda(x)
  144.                  (vl-catch-all-apply 'vla-delete (list x))
  145.                  )
  146.               retimgobj
  147.               )
  148.        (mapcar '(lambda(x)
  149.                  (vl-catch-all-apply 'DetachImage (list x))
  150.                  )
  151.               retimg
  152.               )
  153.       )
  154.     )
  155.    (if (member "AcDbBlockReference" pat)
  156.     (progn
  157.        (mapcar '(lambda(x)
  158.                   (vl-catch-all-apply 'vla-detach (list x))
  159.                   )
  160.                retxref
  161.                )
  162.       )
  163.     )
  164.  (mip:layer-status-restore)
  165.   )
  166.     )
  167.   (princ)
  168. )