Save and restore Layer States code from Tony

Discussion in 'AutoCAD' started by Tom Quok, Oct 13, 2004.

  1. Tom Quok

    Tom Quok Guest

    I've got this code of Tony's from this discussion group awhile back and
    modify it for my needs and it works great in 2004. but it does not seem to
    work in 2005. It does not create and save the layer states and the layer
    states created in 2004 is not showing up in 2005.
    Does anyone know how to modify it to work in 2005?

    Tom

    (defun IDArch_LyrState ()
    (vl-load-com)
    (PlanLyrName)
    (if (/= IDStateName nil)
    (progn
    (ldelete IDStateName)
    (lsave IDStateName "65535")
    )
    )
    )
    ;;;------------------------------------------------------------------------
    ;;;Author: Tony Tanzillo
    ;;;REQUIREMENTS: AutoCAD ver 2000+
    ;;;OBJECT: Save and Restore Layer States compatible with AutoCAD's Layer
    ;;;Manager.
    ;;;SUBR's: (lsave name bit)
    ;;; (lrestore name)
    ;;; (ldelete name)

    ;;;---------------------------------------------------------
    ;;;Layer Bit Settings Bit Value
    ;;;All layer properties================== 65535
    ;;;Color================================= 32
    ;;;Frozen or thawed====================== 2
    ;;;Linetype============================== 64
    ;;;Lineweight============================ 128
    ;;;Locked or unlocked==================== 4
    ;;;New viewport layers frozen or thawed== 16
    ;;;None================================== 0
    ;;;On or off============================= 1
    ;;;Plotting on or off==================== 8
    ;;;Plot style============================ 256
    ;;;---------------------------------------------------------
    ;;;(vl-load-com)
    (defun LayerGetObject (ProgId / Result)
    ;; First try using explicit version-dependent progid:
    (setq result
    (vla-getinterfaceobject
    (vlax-get-acad-object)
    (strcat ProgId "." (substr (getvar "acadver") 1 2))
    )
    )
    ;; Else try the version-independent progid:
    (if (not result)
    (setq result
    (vla-getinterfaceobject
    (vlax-get-acad-object)
    progid
    )
    )
    )
    result
    )

    (setq *lsman* (LayerGetObject "autocad.acadlayerstatemanager"))
    (vla-setdatabase *lsman* (vla-get-database (vla-get-activedocument
    (vlax-get-acad-object))))

    (defun lsave (nam bit)
    (setq nam (strcase nam))
    (if (member nam (getstatenames))
    (vl-catch-all-apply 'vla-delete (list *lsman* nam))
    )
    (vl-catch-all-apply 'vla-save (list *lsman* nam bit))
    ;;;(prompt (strcat "\n" nam " Saved"))
    (princ)
    )

    (defun lrestore (nam)
    (if (member (setq nam (strcase nam)) (getstatenames))
    (progn (vl-catch-all-apply 'vla-restore (list *lsman* nam))
    (vl-cmdf "_.regenall")
    (prompt (strcat "\n" nam " Restored"))
    )
    )
    (princ)
    )

    (defun ldelete (nam)
    (if (member (setq nam (strcase nam)) (getstatenames))
    (progn (vl-catch-all-apply 'vla-delete (list *lsman* nam))
    ;;;(prompt (strcat "\n" nam " Deleted"))
    )
    )
    (princ)
    )

    ;;;Utility Return Saved States
    (defun getstatenames (/ nams dict obj)
    (setq dict (vla-getextensiondictionary
    (vla-get-layers
    (vla-get-activedocument (vlax-get-acad-object))
    )
    )
    )
    (if (not
    (vl-catch-all-error-p
    (setq obj (vl-catch-all-apply
    (function (lambda () (vla-item dict "ACAD_LAYERSTATES")))
    )
    )
    )
    )
    (vlax-for n obj
    (setq nams (cons (strcase (vla-get-name n)) nams))
    )
    )
    (if nams
    (acad_strlsort nams)
    )
    )

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun PlanLyrName ()
    (setq IDStateName nil)
    (cond
    ((= vw "d") (setq IDStateName "Demolition Plan"))
    ((= vw "dp") (setq IDStateName "Demo-Construction Plan"))
    ((= vw "dpe") (setq IDStateName "Demo-Const-Elec Plan"))
    ((= vw "dpf") (setq IDStateName "Demo-Const-Finish Plan"))
    ((= vw "dpef")
    (setq IDStateName "Demo-Const-Elec-Finish Plan")
    )
    ((= vw "dpefr")
    (setq IDStateName "Demo-Const-Elec-Finish-Reflected Ceiling Plan")
    )
    ((= vw "pef") (setq IDStateName "Const-Elec-Finish Plan"))
    ((= vw "e") (setq IDStateName "Elec-Phone-Data Plan"))
    ((= vw "f") (setq IDStateName "Finish Plan"))
    ((= vw "p") (setq IDStateName "Construction Plan"))
    ((= vw "pe") (setq IDStateName "Const-Elec Plan"))
    ((= vw "pf") (setq IDStateName "Const-Finish Plan"))
    ((= vw "r") (setq IDStateName "Reflected Ceiling Plan"))
    (t nil)
    )
    )
     
    Tom Quok, Oct 13, 2004
    #1
  2. Tom Quok

    LUCAS Guest

    (defun IDARCH_LYRSTATE ()
    (vl-load-com)
    (setq VW "p");point it out
    (PLANLYRNAME)
    (if (/= IDSTATENAME NIL)
    (progn
    (LDELETE IDSTATENAME)
    (LSAVE IDSTATENAME "65535")
    )
    )
    )

    ;;(LRESTORE IDSTATENAME)----restore layer state
     
    LUCAS, Oct 14, 2004
    #2
  3. Tom Quok

    Tom Quok Guest

    I know I can still restore the layer states using Tony's "lrestore", but the
    layer state names created using Tony's code were also listed under the
    "Layer States Manager" dialog box in R2004, and I was able to also restore
    it thru Autocad's Layer State Manager.
    In 2005, the layer states names created in 2004 disappear, layer states
    names created using this code in 2005 does not show up in the "Layer States
    Manager" (but can still be restored thru "lrestore" )
    My problem is I still want the names to show up in the Layer States
    manager's dialog box so someone who does not have this routine can restore
    it thru Autocad's Layer Manager.
     
    Tom Quok, Oct 14, 2004
    #3
  4. Tom Quok

    doug k Guest

    if you try to save a layer state with autocad and you are naming it the same
    as one previously saved with tony's routine, do you get the "overwrite
    existing state?" message, even though the name doesn't appear in autocad's
    list?

    i get this with layer states that were saved with toolpac's layer state
    manager.

    its as if they *are* there somewhere, maybe limboland.
     
    doug k, Oct 14, 2004
    #4
  5. Tom Quok

    Tom Quok Guest

    Interesting ... I do get the "overwrite existing state" msg. So, is there a
    way to get this to reappear without saving it thru autocad?
     
    Tom Quok, Oct 14, 2004
    #5
  6. Tom Quok

    doug k Guest

    not that i've found.

    there are some subtle changes with how layer states are saved in 2005 (such
    as separate option for "offing" layers created later)
    and i suspect that may be the culprit here.

    i had asked dotsoft to look into it a while back, but they are so busy
    writing code (that i also need) that i am not going to nag 'em about it.
     
    doug k, Oct 14, 2004
    #6
  7. Tom Quok

    j.buzbee Guest

    Yep, Layer States dissappear from 2004 to 2005. Imagine how I felt when I
    realized that the 12 standard Layer States that I created for 700+ layers
    were gone! Fortunately, Objectdbx will open a 2004 drawing in 2005 allowing
    me to "read" the Layer States and then translate that into a 2005 document.
    It's a bit complex but if you have legacy Layer States it's worth the time
    to write.

    jb
     
    j.buzbee, Oct 15, 2004
    #7
  8. Tom Quok

    Tom Quok Guest

    bummer. I'm not familiar with objectdbx, and my knowledge of visual lisp is
    just good enough to get by (no expert). Is it possible and if yes, can
    anyone show me how to tweak Tony's code to get it to work in 2005?

    Thanks

    Tom
     
    Tom Quok, Oct 16, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.