Author Topic: entmod layer table  (Read 4258 times)

0 Members and 1 Guest are viewing this topic.

curmudgeon

  • Newt
  • Posts: 194
entmod layer table
« on: December 18, 2010, 11:30:02 PM »
I want to freeze and thaw layers within a routine. the layer names follow a simple format: ##-####
subroutine for getting the list of layer names:
Code: [Select]
(defun rak ( / lyr_lst)
  (setq lyr_lst nil)
  (setq lyr_lst (list (cdr (assoc 2 (tblnext "LAYER" T)))))
  (while (setq it (cdr (assoc 2 (tblnext "LAYER"))))
    (setq lyr_lst (append lyr_lst (list it)))
  )
  (setq lyr_lst (vl-sort lyr_lst (function (lambda (a b) (< a b)))))

  (setq n_lst (list))
  (foreach c lyr_lst
    (if (wcmatch c "##-*")
      (setq n_lst (append n_lst (list c))
      )
    )
  )
)

that works.

freeze all the layers in that list:
Code: [Select]
(foreach z n_lst
      (setq it (entget (tblobjname "layer" z)))
      (setq it (subst (cons 70 1) (assoc 70 it) it))
      (entmod it)
    )

gets them frozen OK, but I switch back to (70 . 0) with the same code modified
Code: [Select]
(foreach z n_lst
      (setq it (entget (tblobjname "layer" z)))
      (setq it (subst (cons 70 0) (assoc 70 it) it))
      (entmod it)
    )
I get no joy.

HOWEVER, on the command line, if I invoke the LAYER command
-la thaw *
everything regens together, I UNDO on the command line and viola! my thawed layers have returned.

wassup?

PS - now I see the excess lines in the first bit of code, tightening that up now.
Code: [Select]
(defun rak ( / )
  (setq n_lst nil)
  (setq n_lst (list (cdr (assoc 2 (tblnext "LAYER" T)))))
  (while (setq it (cdr (assoc 2 (tblnext "LAYER"))))
    (if (wcmatch it "##-*")
      (setq n_lst (append n_lst (list it)))
    )
  )
  (setq n_lst (vl-sort n_lst (function (lambda (a b) (< a b)))))
)
« Last Edit: December 18, 2010, 11:39:23 PM by curmudgeon »
Never express yourself more clearly than you are able to think.

curmudgeon

  • Newt
  • Posts: 194
Re: entmod layer table
« Reply #1 on: December 19, 2010, 12:14:50 AM »
FYI
playing with REDRAW instead of FREEZE, still creating n_lst to cycle through.
found erata:

when CLAYER is 0, 0 is included in n_lst even though (wcmatch "0" "##-*") faithfully returns nil.
when CLAYER is anything except zed, n_lst is created with only the expected layer names.

???
Never express yourself more clearly than you are able to think.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: entmod layer table
« Reply #2 on: December 19, 2010, 09:10:43 AM »
Your last rak functions always adds the first layer in the layer table to n_lst. That is why layer "0" is always in the list.
Improved code:
Code: [Select]
(defun rak ( / it n_lst)
  (while (setq it (cdr (assoc 2 (tblnext "LAYER" (not it)))))
    (if (wcmatch it "##-*")
      (setq n_lst (cons it n_lst))
    )
  )
  (vl-sort n_lst '<)
)

After thawing the layers you may have to regenerate the drawing.
Code: [Select]
(vl-cmdf "_.regenall")

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: entmod layer table
« Reply #3 on: December 19, 2010, 09:32:00 AM »
Also, bear in mind that your freeze/thaw code will disrupt any layers whose DXF 70 code contains other bits, eg 4=locked, 2=Frozen in VP etc.

Better to use a boole operation:

Code: [Select]
;; Freeze Layer
;; layer = layer entity (tblobjname)

(defun FreezeLayer ( layer / elist )
  (setq elist (entget layer))
  (entmod (subst (cons 70 (boole 7 1 (cdr (assoc 70 elist)))) (assoc 70 elist) elist))
)

;; Thaw Layer
;; layer = layer entity (tblobjname)

(defun ThawLayer ( layer / elist )
  (setq elist (entget layer))
  (entmod (subst (cons 70 (boole 4 1 (cdr (assoc 70 elist)))) (assoc 70 elist) elist))
)

Perhaps some handy calling functions:

Code: [Select]
;; Freeze Layer If
;; wc = Wildcard String

(defun FreezeLayerif ( wc / def )
  (while (setq def (tblnext "LAYER" (not def)))
    (if (wcmatch (cdr (assoc 2 def)) wc)
      (FreezeLayer (tblobjname "LAYER" (cdr (assoc 2 def))))
    )
  )
)

;; Thaw Layer If
;; wc = Wildcard String

(defun ThawLayerif ( wc / def )
  (while (setq def (tblnext "LAYER" (not def)))
    (if (wcmatch (cdr (assoc 2 def)) wc)
      (ThawLayer (tblobjname "LAYER" (cdr (assoc 2 def))))
    )
  )
)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: entmod layer table
« Reply #4 on: December 19, 2010, 10:26:43 AM »
I wrote this a while ago, it may provide a little for for thought (or nausea) ... workin' the layers collection.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: entmod layer table
« Reply #5 on: December 19, 2010, 11:41:48 AM »
I wrote this a while ago, it may provide a little for for thought (or nausea) ... workin' the layers collection.

Nice post there Michael - looks like you've put in some time to explain things properly, in which case, I'll definitely take some time to look over it.

Lee

EDIT: lovin' the comments :lol:
« Last Edit: December 19, 2010, 11:48:28 AM by Lee Mac »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: entmod layer table
« Reply #6 on: December 20, 2010, 03:59:51 PM »
Thanks Lee.

Off topic ... have really been enjoying your posts lately, you've taken to lisp really well. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: entmod layer table
« Reply #7 on: December 20, 2010, 05:52:32 PM »
Off topic ... have really been enjoying your posts lately, you've taken to lisp really well. :)

Thanks Michael  :-)