Author Topic: Purge unused Fields  (Read 2980 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
Purge unused Fields
« on: October 16, 2018, 10:52:24 AM »
Hi all,
Since my drawings are becoming too cumbersome to work because of the hundreds fields I generate and use, I wrote this to erase all field definitions:

Code - Auto/Visual Lisp: [Select]
  1. ; Fields - Erase All
  2.  
  3. (defun C:FieldsEraseAll ( / *error* acDoc L )
  4.  
  5.   (defun *error* ( m )
  6.     (and acDoc (vla-EndUndoMark acDoc))
  7.     (and m (princ m)) (princ)
  8.   ); defun *error*
  9.  
  10.   (cond
  11.     ( (= "Yes" (progn (initget "Yes No") (cond ((getkword "\nErase all fields [Yes/No] <No>: "))("No"))))
  12.       (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc)
  13.       (mapcar 'entdel
  14.         (setq L
  15.           (mapcar 'cdr
  16.             (vl-remove-if-not (function (lambda (x) (= 330 (car x))))
  17.               (vl-member-if (function (lambda (x) (= 90 (car x)))) (dictsearch (namedobjdict) "ACAD_FIELDLIST"))
  18.             )
  19.           )
  20.         )
  21.       )
  22.       (vla-Regen acDoc acActiveViewport)
  23.       (alert (strcat "\nAll the " (itoa (length L)) " Fields have been erased!"))
  24.     )
  25.   ); cond  
  26.   (*error* nil) (princ)
  27. ); defun
  28.  

However I noticed that in that "ACAD_FIELDLIST" dictionary are stored field definitons of the FIELDs that I generated previously inside of the graphical entities that I deleted already...
So my question is how I can determine if the field definition has a graphical reference somewhere, so I could entdel it if it doesn't ?

BTW heres a sub to obtain them in a list:

Code - Auto/Visual Lisp: [Select]
  1. (defun GetFieldDefinitions (  / fdic L len )
  2.   (setq fdic (dictsearch (namedobjdict) "ACAD_FIELDLIST"))
  3.   (setq L (cdr (member (setq len (assoc 90 fdic)) fdic)))
  4.   (setq L (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (and (= 330 (car x)) (eq 'ENAME (type (cdr x)))))) L)))
  5.   (if (= (cdr len) (length L)) ; just checkin' if everything is as expected
  6.     L
  7.   )
  8. )
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Purge unused Fields
« Reply #1 on: October 16, 2018, 11:47:34 AM »
How do look field expression of one of your non-graphical linked field and how expression of one that has linked graphical elements?
If there are no obvious differences why do you use fields for descriptions of not linked elements - isn't simple text or similar enough? If you have many fields, you store them all alltoghether in the same layer? How you differentiate them then if not by expressions they are generated? You said that you noticed there are those that have linked grapical entities - how then you noticed this - by erasing graphical data - field expressions become broken? If that's the case - erase all graphics, collect fields that are broken - store them in a list; undo grapical deletion and finally erase those left fields that don't belong to stored list...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Purge unused Fields
« Reply #2 on: October 16, 2018, 03:32:58 PM »

How do look field expression of one of your non-graphical linked field and how expression of one that has linked graphical elements?

Providing a simple example as a .gif demo so you can see the problem.
Usually I use alot of fields, inside of blocks/acad_tables but that doesn't seem to matter.


If there are no obvious differences why do you use fields for descriptions of not linked elements - isn't simple text or similar enough?

Say I have a floor plan, with 30 rooms - each room is represented by a closed lwpline and it also has an attributed block, standing for a "room label"..
so one attribute of that block is a field that refers to the lwpline's area. Also I used to generate a roomtable as ACAD_TABLE object, where the cells use fields aswell.
So on comming corrections I don't have to regenerate all of the information in form of new "room label" blocks and a "room table" - I just regen and the fields update.

Now you are asking then why I'd want to get rid of them? The answer is:
I copy the entire floor plans or all of the floor plans in order to draw facades/sections.
That means I'll rotate/move the plan and/or do whatever I want with it, and don't bother with the original one, that stays within my titleblock as finished.
So I erase that copy in the end, note that it contained all of the fields that were copied aswell.. so thats how their definitions sum up into that dictionary.

And all of this is a repetitive process:
getting a phone call to resize/move some window or door, then I make the changes on the "finished" floor plan, copy it, trace if I did all the required changes.

In the end before sending the architectural drawing to the structural/electrical/water supply designers,
I erase all of the fields, else the drawing gets too heavy for them and I get calls to resend a light version.

^^ BTW I've skipped all of these explanations to not get answers out-of-the-context like "your doing it wrong" or to "switch to BIM".


If you have many fields, you store them all alltoghether in the same layer? How you differentiate them then if not by expressions they are generated?

I don't see how does the layer matters for the field definitions?
I could sort them out graphically and remove them but, the problem are the redundant ones inside the "ACAD_FIELDLIST" dictionary.


You said that you noticed there are those that have linked grapical entities - how then you noticed this - by erasing graphical data - field expressions become broken?

Again, check the demo.. although I could find the ones with broken links with:
Code: [Select]
(vl-remove-if-not '(lambda (x) (vl-some '(lambda (xx) (and (= 301 (car xx)) (wcmatch (cdr xx) "*`#*"))) (entget x))) (GetFieldDefinitions))But that won't work when the actual entity is erased, where the field is located within.


If that's the case - erase all graphics, collect fields that are broken - store them in a list; undo grapical deletion and finally erase those left fields that don't belong to stored list...

Erase all graphics, collect fields that don't have references, which is different from broken links "####"
The problem is how to find out the field definitions that don't have references.


Attached that same test drawing.

(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: Purge unused Fields
« Reply #3 on: October 17, 2018, 12:03:00 AM »

Say I have a floor plan, with 30 rooms - each room is represented by a closed lwpline and it also has an attributed block, standing for a "room label"..
so one attribute of that block is a field that refers to the lwpline's area. Also I used to generate a roomtable as ACAD_TABLE object, where the cells use fields aswell.
So on comming corrections I don't have to regenerate all of the information in form of new "room label" blocks and a "room table" - I just regen and the fields update.

Now you are asking then why I'd want to get rid of them? The answer is:
I copy the entire floor plans or all of the floor plans in order to draw facades/sections.
That means I'll rotate/move the plan and/or do whatever I want with it, and don't bother with the original one, that stays within my titleblock as finished.
So I erase that copy in the end, note that it contained all of the fields that were copied aswell.. so thats how their definitions sum up into that dictionary.

And all of this is a repetitive process:
getting a phone call to resize/move some window or door, then I make the changes on the "finished" floor plan, copy it, trace if I did all the required changes.

In the end before sending the architectural drawing to the structural/electrical/water supply designers,
I erase all of the fields, else the drawing gets too heavy for them and I get calls to resend a light version.

Have you tried to WBLOCK graphical elements without fields and use WBLOCKED DWG as xref(s) for manipulations and creating light version without field definitions... I don't know, but I suppose that dictionary would be without big entity definitions after you use blank DWG as master one and then attach all xrefs as well as your remaining DWGs with ACAD_TABLE entities with fields...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube