Author Topic: Layer States  (Read 3555 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Layer States
« on: February 12, 2018, 01:39:41 PM »
Anyone have any good layer state routines, or comments to mine.

Layer states named after layout tab name:
Code: [Select]
(defun C:State (/ tmp)
  (initget "I X S R D")
  (setq tmp (getkword "\n* Layer States: [Import eXport - Save Restore - Delete]"))
  (initget 7) 
  (cond ((= tmp "I")(LSImportIT))
        ((= tmp "X")(LSXportIT))
        ((= tmp "S")(LSSaveIT))
        ((= tmp "R")(LSRestoreIT))
        ((= tmp "D")(LSDeleteIT)))
  (princ)
)
;;;
(defun ARCH:State (/ tmp) 
  (setq tmp (layerstate-has (getvar "ctab")))
  (if (= tmp T)(LSRestoreIT))   
  (princ)
)
;;;
(ARCH:State);place in your acaddoc file



(defun LSImportIT  (/ tmp)
  (setq tmp (strcat (getvar 'dwgprefix)(vl-string-right-trim ".dwg" (getvar 'dwgname)) " ctab-" (getvar "ctab") ".las"))
  (if (/= tmp nil)
    (progn
      (princ (strcat "\n* Importing LayerStates to: " tmp))
      (command "mspace")
      (layerstate-import tmp)
      (command "pspace")
    )
  )
  (princ))
;;;
(defun LSXportIT  (/ tmp)
  (setq tmp (strcat (getvar 'dwgprefix)(vl-string-right-trim ".dwg" (getvar 'dwgname)) " ctab-" (getvar "ctab") ".las"))
  (princ (strcat "\n* Exporting Layer States to: " tmp))
  (command "mspace")
  (layerstate-export (getvar "ctab") tmp)
  (command "pspace")
  (princ))
;;;
(defun LSSaveIT  ()
  (princ (strcat "\n* Saving New Layer States to: " (getvar "ctab")))
  (command "mspace")
  (layerstate-save (getvar "ctab") 255 nil)
  (command "pspace")
  (princ))
;;;
(defun LSRestoreIT  ()
  (princ (strcat "\n* Restoring Layer States from: " (getvar "ctab")))
  (command "mspace")
  (layerstate-restore (getvar "ctab") nil 255)
  (command "pspace")
  (princ))
;;;
(defun LSDeleteIT  ()
  (princ (strcat "\n* Deleting Layer States from: " (getvar "ctab")))
  (command "mspace")
  (layerstate-delete (getvar "ctab"))
  (command "pspace")
  (princ))

Gary

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

JohnK

  • Administrator
  • Seagull
  • Posts: 10595
Re: Layer States
« Reply #1 on: February 12, 2018, 02:21:02 PM »
I don't have much of my old lisp stuff anymore but I did find this one (not much, I know, but I hope it helps).

Code - Auto/Visual Lisp: [Select]
  1. (defun DeleteLayerStates ( / )
  2.   ;; Delete all layer states
  3.   ;; Ex: (DeleteLayerStates)
  4.   (vl-catch-all-apply
  5.     '(lambda ()
  6.        (vla-remove
  7.            (vla-get-layers
  8.              (vla-get-activedocument
  9.                (vlax-get-acad-object))))
  10.          "ACAD_LAYERSTATES")))
  11.   (princ)
  12.   )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Layer States
« Reply #2 on: February 12, 2018, 02:55:16 PM »
Subset of one of my fav's (used when turning over dwgs to clients):

Code: [Select]
(defun _JennyCraig ( doc )
    ;;  Remove all layer states, layer filters and groups from the
    ;;  document (which may be an ObjectDBX document) but leave the
    ;;  layer's xdict intact in case it's used to store other data.
    ;;  Return T if any of the undesirables nuked.
    (   (lambda ( remove layers keys / owner result )
            (and
                (eq :vlax-true (vla-get-hasextensiondictionary layers))
                (setq owner (vla-getextensiondictionary layers))
                (foreach key keys (remove owner key))
            )
            result                 
        )
        (lambda ( owner key / lst offender )   
            (and
                (setq lst (list owner key))
                (setq offender (vl-catch-all-apply 'vla-item lst))
                (eq 'vla-object (type offender))
                (vl-catch-all-apply 'vla-remove lst)
                (vl-catch-all-error-p (vl-catch-all-apply 'vla-item lst))
                (setq result t) ;; lexical global
            )       
        )
        (vla-get-layers doc)
       '("ACAD_LAYERSTATES" "ACAD_LAYERFILTERS" "ACLYDICTIONARY")         
    )
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

GDF

  • Water Moccasin
  • Posts: 2081
Re: Layer States
« Reply #3 on: February 12, 2018, 03:53:20 PM »
Thanks guys
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Ben Clark

  • Newt
  • Posts: 94
Re: Layer States
« Reply #4 on: February 13, 2018, 05:59:21 PM »
Subset of one of my fav's (used when turning over dwgs to clients):

Code: [Select]
(defun _JennyCraig ( doc )
    ;;  Remove all layer states, layer filters and groups from the
    ;;  document (which may be an ObjectDBX document) but leave the
    ;;  layer's xdict intact in case it's used to store other data.
    ;;  Return T if any of the undesirables nuked.
    (   (lambda ( remove layers keys / owner result )
            (and
                (eq :vlax-true (vla-get-hasextensiondictionary layers))
                (setq owner (vla-getextensiondictionary layers))
                (foreach key keys (remove owner key))
            )
            result                 
        )
        (lambda ( owner key / lst offender )   
            (and
                (setq lst (list owner key))
                (setq offender (vl-catch-all-apply 'vla-item lst))
                (eq 'vla-object (type offender))
                (vl-catch-all-apply 'vla-remove lst)
                (vl-catch-all-error-p (vl-catch-all-apply 'vla-item lst))
                (setq result t) ;; lexical global
            )       
        )
        (vla-get-layers doc)
       '("ACAD_LAYERSTATES" "ACAD_LAYERFILTERS" "ACLYDICTIONARY")         
    )
)

I need to draw attention to your function name. Hilarious.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Layer States
« Reply #5 on: February 13, 2018, 06:38:44 PM »
Consequence of 3 decades writing LISP.  :whistling:
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: 7524
Re: Layer States
« Reply #6 on: February 13, 2018, 10:32:10 PM »
Subset of one of my fav's (used when turning over dwgs to clients):

Code: [Select]
(defun _JennyCraig ( doc )
    ;;  Remove all layer states, layer filters and groups from the
    ;;  document (which may be an ObjectDBX document) but leave the
    ;;  layer's xdict intact in case it's used to store other data.
    ;;  Return T if any of the undesirables nuked.
    (   (lambda ( remove layers keys / owner result )
            (and
                (eq :vlax-true (vla-get-hasextensiondictionary layers))
                (setq owner (vla-getextensiondictionary layers))
                (foreach key keys (remove owner key))
            )
            result                 
        )
        (lambda ( owner key / lst offender )   
            (and
                (setq lst (list owner key))
                (setq offender (vl-catch-all-apply 'vla-item lst))
                (eq 'vla-object (type offender))
                (vl-catch-all-apply 'vla-remove lst)
                (vl-catch-all-error-p (vl-catch-all-apply 'vla-item lst))
                (setq result t) ;; lexical global
            )       
        )
        (vla-get-layers doc)
       '("ACAD_LAYERSTATES" "ACAD_LAYERFILTERS" "ACLYDICTIONARY")         
    )
)

I need to draw attention to your function name. Hilarious.
MP has tidbits of funnies all throughout his comments in code. Always made me chuckle. 😁

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Layer States
« Reply #7 on: February 14, 2018, 08:12:16 AM »
Glad to hear I’ve brought lolz here and there. :laugh:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

BIGAL

  • Swamp Rat
  • Posts: 1392
  • 40 + years of using Autocad
Re: Layer States
« Reply #8 on: February 15, 2018, 03:19:16 AM »
Just me I a moving away from getkword where you have multiple choice say more than 3 to either a list dcl choice or something like Grrr's matrix dcl which only require a couple of lines to execute, as they use a library routine.
A man who never made a mistake never made anything