Author Topic: Help to Modify a LISP  (Read 5582 times)

0 Members and 1 Guest are viewing this topic.

RolandOrzabal

  • Newt
  • Posts: 86
  • "memories fade but the scars still linger"
Help to Modify a LISP
« on: October 31, 2012, 05:02:55 AM »
can somebody help me to modify a lisp i found at cadalyst. This is useful but after issuing the command and the routine thawing the drawing, if the user accidentally hits escape key, it does not revert back to its old state and shows all the frozen layers. Maybe an error tap will solve this but am not that good at that...

here's the code :

Code: [Select]

;;;========================================================================
;;;                    *** LYR-UNHIDE.LSP ***
;;;========================================================================
;;;
;;; This function dynamicaly "TURN ON" frozen layers by selecting objects
;;; lying on these layers. The procedure is achieved by temporary turning
;;; on all layers to enable selection.
;;;
;;;
;;; "Specially recommanded to use on Xrefs" - Raymond Rizkallah, Aug. 2007
;;;========================================================================

(defun C:LUH (/ entsll laynam laypmt  )

  (setq orgm (getvar "regenmode"))
  (setq laylst nil laypmt " ")
  (command "undo" "m" "undo" "g")

    (setvar "regenmode" 1)
  (command "layer" "t" "*" "on" "*" "")
  (while
    (setq entsll (nentsel "\n Select object on layer to be unhidden: "))
    (setq laynam (cdr (assoc 8 (entget (car entsll)))))
    (if (null laylst) (setq laylst (strcat laynam ",")) (setq laylst (strcat laylst laynam ",")))
    ;(prompt (strcat "\n   <" (substr laylst 1 (1- (strlen laylst))) ">"))

    (setq laypmt (strcat laypmt "<" laynam "> ; "))    (prompt (strcat "\n" laypmt))

  ) ;end while

  ; (command "undo" "end" "undo" "1")   
  (if laylst (command "layer" "t" laylst "on" laylst "u" laylst ""))  ;end if
 
  (setvar "regenmode" orgm)
  (princ)

) ;end function

;;;========================================================================

(prompt "\n Use [C:LUH] to dynamicaly reveal hidden layers. ")
(princ)

"memories fade but the scars still linger"

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Help to Modify a LISP
« Reply #1 on: October 31, 2012, 07:00:01 AM »
I´m little confuse what you want to do ... is it another to isolate or unisolate layers?

RolandOrzabal

  • Newt
  • Posts: 86
  • "memories fade but the scars still linger"
Re: Help to Modify a LISP
« Reply #2 on: October 31, 2012, 11:10:00 AM »
I´m little confuse what you want to do ... is it another to isolate or unisolate layers?

Hi Cadplayer, just wanted to have a error trap in which when the user hit the escape key, those layers that were temporarily thawed will be frozen/hidden again.

if you try running the program, after issuing the command and hitting the escape key, it does not restore the previous state of the layers.
you will need to run undo command first for it to restore the previous layer states...

is it possible that after you hit escape and the routine stopped, it will automatically restore the layer state and no need for the undo command....
"memories fade but the scars still linger"

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: Help to Modify a LISP
« Reply #3 on: October 31, 2012, 12:53:44 PM »
Try this (as an example to fix your routine, or use it if you like it)
Code - Auto/Visual Lisp: [Select]
  1. (defun C:THAWLAY (/ *error* acDoc layers layer freez_list on_list e)
  2.         layers (vla-get-layers acDoc)
  3.   )
  4.  
  5.   (defun *error* (msg)
  6.     (foreach x on_list (vla-put-LayerOn (vla-item layers x) :vlax-true))
  7.     (foreach x freez_list (vla-put-Freeze (vla-item layers x) :vlax-true))
  8.     (vla-regen acDoc acActiveViewport)
  9.     (vla-EndUndoMark acDoc)
  10.   )
  11.  
  12.   (vlax-for layer layers
  13.     (if
  14.       (= (vla-get-Freeze layer) :vlax-true)
  15.        (progn
  16.          (vla-put-Freeze layer :vlax-false)
  17.          (setq freez_list (cons (vla-get-Name layer) freez_list))
  18.        )
  19.        (progn
  20.          (vla-put-LayerOn layer :vlax-false)
  21.          (setq on_list (cons (vla-get-Name layer) on_list))
  22.        )
  23.     )
  24.   )
  25.  
  26.   (vla-regen acDoc acActiveViewport)
  27.  
  28.   (while
  29.     (or
  30.       (setq e (car (nentsel)))
  31.       (and (= (getvar 'errno) 7) (setvar 'errno 0))
  32.     )
  33.      (if e
  34.        (progn
  35.          (setq layer      (cdr (assoc 8 (entget e)))
  36.                freez_list (vl-remove layer freez_list)
  37.                on_list    (cons layer on_list)
  38.          )
  39.          (vla-put-LayerOn (vla-item layers layer) :vlax-false)
  40.        )
  41.      )
  42.   )
  43.  
  44.   (*error* nil)
  45.   (princ)
  46. )

RolandOrzabal

  • Newt
  • Posts: 86
  • "memories fade but the scars still linger"
Re: Help to Modify a LISP
« Reply #4 on: October 31, 2012, 09:06:18 PM »
@stefan, what does your routine do? i've tried it and it does nothing...or maybe i've done something wrong....

what the routine does is that it "temporarily" turns on frozen and off layers, then you select which layers you want to turn on/thaw then it reverts back to the previous layer state except for the ones you pick.

the problem is that after you "temporarily" turn on the frozen/off layers and you hit escape, the frozen/off layers are all thawed/on and you need to issue undo command to turn them back to their state.

what i want if possible is that when you hit escape key, it reverts back to its previous state and no need to issue the undo command.
"memories fade but the scars still linger"

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: Help to Modify a LISP
« Reply #5 on: November 01, 2012, 06:50:46 AM »
@stefan, what does your routine do? i've tried it and it does nothing...or maybe i've done something wrong....
Works only for frozen layers. On error (or hitting escape) will turn on temporary hidden layers, but will keep changes already made.

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: Help to Modify a LISP
« Reply #6 on: November 01, 2012, 08:26:24 AM »
To answer your fist post, try this
Code - Auto/Visual Lisp: [Select]
  1. ;;;========================================================================
  2. ;;;                    *** LYR-UNHIDE.LSP ***
  3. ;;;========================================================================
  4. ;;;
  5. ;;; This function dynamicaly "TURN ON" frozen layers by selecting objects
  6. ;;; lying on these layers. The procedure is achieved by temporary turning
  7. ;;; on all layers to enable selection.
  8. ;;;
  9. ;;;
  10. ;;; "Specially recommanded to use on Xrefs" - Raymond Rizkallah, Aug. 2007
  11. ;;;========================================================================
  12.  
  13. (defun C:LUH (/ *error* entsll laynam laypmt  )
  14.  
  15.   (setq orgm (getvar "regenmode"))
  16.   (setq laylst nil laypmt " ")
  17.   (command "undo" "m")
  18.  
  19.   (defun *error* (msg)
  20.     (command "undo" "b")
  21.     )
  22.  
  23.     (setvar "regenmode" 1)
  24.   (command "layer" "t" "*" "on" "*" "")
  25.   (while
  26.     (setq entsll (nentsel "\n Select object on layer to be unhidden: "))
  27.     (setq laynam (cdr (assoc 8 (entget (car entsll)))))
  28.     (if (null laylst) (setq laylst (strcat laynam ",")) (setq laylst (strcat laylst laynam ",")))
  29.     ;(prompt (strcat "\n   <" (substr laylst 1 (1- (strlen laylst))) ">"))
  30.  
  31.     (setq laypmt (strcat laypmt "<" laynam "> ; "))    (prompt (strcat "\n" laypmt))
  32.  
  33.   ) ;end while
  34.  
  35.   ; (command "undo" "end" "undo" "1")
  36.   (command "undo" "b")
  37.   (if laylst (command "layer" "t" laylst "on" laylst "u" laylst ""))  ;end if
  38.  
  39.   (setvar "regenmode" orgm)
  40.   (princ)
  41.  
  42. ) ;end function
  43.  
  44. ;;;========================================================================
  45.  
  46. (prompt "\n Use [C:LUH] to dynamicaly reveal hidden layers. ")
  47.  

RolandOrzabal

  • Newt
  • Posts: 86
  • "memories fade but the scars still linger"
Re: Help to Modify a LISP
« Reply #7 on: November 01, 2012, 08:40:44 PM »
To answer your fist post, try this
Code - Auto/Visual Lisp: [Select]
  1. ;;;========================================================================
  2. ;;;                    *** LYR-UNHIDE.LSP ***
  3. ;;;========================================================================
  4. ;;;
  5. ;;; This function dynamicaly "TURN ON" frozen layers by selecting objects
  6. ;;; lying on these layers. The procedure is achieved by temporary turning
  7. ;;; on all layers to enable selection.
  8. ;;;
  9. ;;;
  10. ;;; "Specially recommanded to use on Xrefs" - Raymond Rizkallah, Aug. 2007
  11. ;;;========================================================================
  12.  
  13. (defun C:LUH (/ *error* entsll laynam laypmt  )
  14.  
  15.   (setq orgm (getvar "regenmode"))
  16.   (setq laylst nil laypmt " ")
  17.   (command "undo" "m")
  18.  
  19.   (defun *error* (msg)
  20.     (command "undo" "b")
  21.     )
  22.  
  23.     (setvar "regenmode" 1)
  24.   (command "layer" "t" "*" "on" "*" "")
  25.   (while
  26.     (setq entsll (nentsel "\n Select object on layer to be unhidden: "))
  27.     (setq laynam (cdr (assoc 8 (entget (car entsll)))))
  28.     (if (null laylst) (setq laylst (strcat laynam ",")) (setq laylst (strcat laylst laynam ",")))
  29.     ;(prompt (strcat "\n   <" (substr laylst 1 (1- (strlen laylst))) ">"))
  30.  
  31.     (setq laypmt (strcat laypmt "<" laynam "> ; "))    (prompt (strcat "\n" laypmt))
  32.  
  33.   ) ;end while
  34.  
  35.   ; (command "undo" "end" "undo" "1")
  36.   (command "undo" "b")
  37.   (if laylst (command "layer" "t" laylst "on" laylst "u" laylst ""))  ;end if
  38.  
  39.   (setvar "regenmode" orgm)
  40.   (princ)
  41.  
  42. ) ;end function
  43.  
  44. ;;;========================================================================
  45.  
  46. (prompt "\n Use [C:LUH] to dynamicaly reveal hidden layers. ")
  47.  



Thanks a lot! it's just how i wanted it to be....
thanks again stefan
"memories fade but the scars still linger"

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Help to Modify a LISP
« Reply #8 on: November 02, 2012, 01:34:27 PM »
Perhaps this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:LayAllThaw  ()
  2.     (vla-put-Freeze lay :vlax-false))
  3.   (princ))
  4.  
  5. (defun c:LayAllOn  ()
  6.     (vla-put-LayerOn lay :vlax-true))
  7.   (princ))
  8.  
  9. (defun c:LayAllShow () (c:LayAllThaw) (c:LayAllOn))
  10.  
  11. (setq *LayUnHide-StateName* "*LayerUnHide*")
  12. (defun c:LayUnHide  (/ *error* LayersToTurnOn en)
  13.   (defun *error*  (msg)
  14.     (if (layerstate-has *LayUnHide-StateName*)
  15.       (progn (layerstate-restore *LayUnHide-StateName* nil) (layerstate-delete *LayUnHide-StateName*)))
  16.     (cond ((or (not msg) (wcmatch (strcase msg "EXIT,QUIT,ABORT"))))
  17.           (t (prompt (strcat "*** Error: " msg " ***"))))
  18.     (princ))
  19.   (layerstate-save *LayUnHide-StateName* 3 nil)
  20.   (c:LayAllShow)
  21.   (while (setq en (entsel "\nSelect object on layer to unhide: "))
  22.     (setq LayersToTurnOn (cons (cdr (assoc 8 (entget en))) LayersToTurnOn)))
  23.   (*error* nil)
  24.     (if (vl-position (vla-get-Name lay) LayersToTurnOn)
  25.       (progn (vla-put-LayerOn lay :vlax-true) (vla-put-Freeze lay :vlax-false))))
  26.   (princ))
« Last Edit: November 02, 2012, 01:41:00 PM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

RolandOrzabal

  • Newt
  • Posts: 86
  • "memories fade but the scars still linger"
Re: Help to Modify a LISP
« Reply #9 on: November 04, 2012, 08:23:47 PM »
irneb; am getting this error :

Code: [Select]
; error: An error has occurred inside the *error* functiontoo few arguments
« Last Edit: November 07, 2012, 12:44:50 AM by NOD684 »
"memories fade but the scars still linger"

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Help to Modify a LISP
« Reply #10 on: November 05, 2012, 11:41:50 AM »
After a quick glance, change:
Code - Auto/Visual Lisp: [Select]
  1. (wcmatch (strcase msg "EXIT,QUIT,ABORT"))
to:
Code - Auto/Visual Lisp: [Select]
  1. (wcmatch (strcase msg) "*EXIT*,*QUIT*,*ABORT*")

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help to Modify a LISP
« Reply #11 on: November 05, 2012, 01:10:11 PM »
First test & this fails for me on ACAD 2006.
Can not change the current layer.
Code: [Select]
(defun c:layallon ()
  (vlax-for lay (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (vla-put-layeron lay :vlax-true)
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help to Modify a LISP
« Reply #12 on: November 05, 2012, 01:18:08 PM »
Where are these routines?
layerstate-has
layerstate-save

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Help to Modify a LISP
« Reply #13 on: November 05, 2012, 01:21:07 PM »
Where are these routines?
layerstate-has
layerstate-save


Those are part of the layerstate-* AutoLISP functions, but I'm not sure in which version they were introduced:

« Last Edit: November 05, 2012, 01:24:26 PM by Lee Mac »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help to Modify a LISP
« Reply #14 on: November 05, 2012, 02:07:39 PM »
Thanks Lee, they don't exist in vanilla 2006.

Perhaps one of those calls withing the error handler is throwing the error.

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

RolandOrzabal

  • Newt
  • Posts: 86
  • "memories fade but the scars still linger"
Re: Help to Modify a LISP
« Reply #15 on: November 05, 2012, 07:52:08 PM »
Thanks Lee! revised code below but nothings happening...wonder whats wrong..

or is it on my side?

Code: [Select]

 (vl-load-com)
 (defun c:LayAllThaw  ()
   (vlax-for lay  (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
     (vla-put-Freeze lay :vlax-false))
   (princ))
 
 (defun c:LayAllOn  ()
   (vlax-for lay  (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
     (vla-put-LayerOn lay :vlax-true))
   (princ))
 
 (defun c:LayAllShow () (c:LayAllThaw) (c:LayAllOn))
 
 (setq *LayUnHide-StateName* "*LayerUnHide*")
 (defun c:LayUnHide  (/ *error* LayersToTurnOn en)
   (defun *error*  (msg)
     (if (layerstate-has *LayUnHide-StateName*)
       (progn (layerstate-restore *LayUnHide-StateName* nil) (layerstate-delete *LayUnHide-StateName*)))
     (cond ((or (not msg) (wcmatch (strcase msg) "*EXIT*,*QUIT*,*ABORT*"))))
           (t (prompt (strcat "*** Error: " msg " ***"))))
     (princ))
   (layerstate-save *LayUnHide-StateName* 3 nil)
   (c:LayAllShow)
   (while (setq en (entsel "\nSelect object on layer to unhide: "))
     (setq LayersToTurnOn (cons (cdr (assoc 8 (entget en))) LayersToTurnOn)))
   (*error* nil)
   (vlax-for lay  (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
     (if (vl-position (vla-get-Name lay) LayersToTurnOn)
       (progn (vla-put-LayerOn lay :vlax-true) (vla-put-Freeze lay :vlax-false))))
   (princ))
 
"memories fade but the scars still linger"

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Help to Modify a LISP
« Reply #16 on: November 06, 2012, 03:09:12 AM »
Sorry about the typo, thanks Lee for catching it. I'll have to do a bit of testing on this, it seems the parentheses are wrong elsewhere too.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help to Modify a LISP
« Reply #17 on: November 06, 2012, 08:15:49 AM »
Replace this :
Code: [Select]
      (if (layerstate-has *LayUnHide-StateName*)
         (progn (layerstate-restore *LayUnHide-StateName* nil) (layerstate-delete *LayUnHide-StateName*)))

with this to see it that is where the error is:
Code: [Select]
      (vl-catch-all-apply '(lambda ()
      (if (layerstate-has *LayUnHide-StateName*)
         (progn (layerstate-restore *LayUnHide-StateName* nil) (layerstate-delete *LayUnHide-StateName*)))
      ))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

RolandOrzabal

  • Newt
  • Posts: 86
  • "memories fade but the scars still linger"
Re: Help to Modify a LISP
« Reply #18 on: November 06, 2012, 08:20:44 PM »
still nothing happens...

LayAllShow returns an Invalid Layer Error
"memories fade but the scars still linger"

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Help to Modify a LISP
« Reply #19 on: November 07, 2012, 12:24:21 AM »
OK, fixed it ... sorry real stupid mistakes. Comes from trying to program without debugging inside VLIDE.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:LayAllThaw  ()
  2.     (vl-catch-all-apply 'vla-put-Freeze (list lay :vlax-false)))
  3.   (princ))
  4.  
  5. (defun c:LayAllOn  ()
  6.     (vl-catch-all-apply 'vla-put-LayerOn (list lay :vlax-true)))
  7.   (princ))
  8.  
  9. (defun c:LayAllShow () (c:LayAllThaw) (c:LayAllOn))
  10.  
  11. (setq *LayUnHide-StateName* "_LayerUnHide_")
  12. (defun c:LayUnHide  (/ *error* LayersToTurnOn en)
  13.   (defun *error*  (msg)
  14.     (if (layerstate-has *LayUnHide-StateName*)
  15.       (progn (layerstate-restore *LayUnHide-StateName* nil)
  16.       (layerstate-delete *LayUnHide-StateName*)))
  17.     (cond ((or (not msg) (wcmatch (strcase msg) "*EXIT*,*QUIT*,*ABORT*")))
  18.    (t (prompt (strcat "*** Error: " msg " ***"))))
  19.     (princ))
  20.   (layerstate-save *LayUnHide-StateName* 3 nil)
  21.   (c:LayAllShow)
  22.   (while (setq en (entsel "\nSelect object on layer to unhide: "))
  23.     (setq LayersToTurnOn (cons (cdr (assoc 8 (entget (car en)))) LayersToTurnOn)))
  24.   (*error* nil)
  25.     (if (vl-position (vla-get-Name lay) LayersToTurnOn)
  26.       (progn (vla-put-LayerOn lay :vlax-true) (vla-put-Freeze lay :vlax-false))))
  27.   (princ))
Firstly the cond inside the *error* handler was simply incorrect! 2nd had to add the catch into the All on/thaw defuns. 3rd add a regen after thawing. And lastly car of the entsel  :-[
 
Edit: [RANT]And WTH? I'm attempting to do this from IE9 today. On the office PC. Now I can fully realize just how much suffering the guys complaining about the forum's code blocks have. It's not just copying the code from the post, it's also issues with pasting the code into the edit box. You keep losing formatting - line feeds and tabs just go crazy! I've never had such issues with FF! ... [/RANT]
« Last Edit: November 07, 2012, 12:50:17 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

RolandOrzabal

  • Newt
  • Posts: 86
  • "memories fade but the scars still linger"
Re: Help to Modify a LISP
« Reply #20 on: November 07, 2012, 12:40:36 AM »
OK, fixed it ... sorry real stupid mistakes. Comes from trying to program without debugging inside VLIDE.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:LayAllThaw  ()
  2.     (vl-catch-all-apply 'vla-put-Freeze (list lay :vlax-false)))
  3.   (princ))
  4.  
  5. (defun c:LayAllOn  ()
  6.     (vl-catch-all-apply 'vla-put-LayerOn (list lay :vlax-true)))
  7.   (princ))
  8.  
  9. (defun c:LayAllShow () (c:LayAllThaw) (c:LayAllOn))
  10.  
  11. (setq *LayUnHide-StateName* "_LayerUnHide_")
  12. (defun c:LayUnHide  (/ *error* LayersToTurnOn en)
  13.   (defun *error*  (msg)
  14.     (if (layerstate-has *LayUnHide-StateName*)
  15.       (progn (layerstate-restore *LayUnHide-StateName* nil)
  16.       (layerstate-delete *LayUnHide-StateName*)))
  17.     (cond ((or (not msg) (wcmatch (strcase msg) "*EXIT*,*QUIT*,*ABORT*")))
  18.    (t (prompt (strcat "*** Error: " msg " ***"))))
  19.     (princ))
  20.   (layerstate-save *LayUnHide-StateName* 3 nil)
  21.   (c:LayAllShow)
  22.   (while (setq en (entsel "\nSelect object on layer to unhide: "))
  23.     (setq LayersToTurnOn (cons (cdr (assoc 8 (entget (car en)))) LayersToTurnOn)))
  24.   (*error* nil)
  25.     (if (vl-position (vla-get-Name lay) LayersToTurnOn)
  26.       (progn (vla-put-LayerOn lay :vlax-true) (vla-put-Freeze lay :vlax-false))))
  27.   (princ))
Firstly the cond inside the *error* handler was simply incorrect! 2nd had to add the catch into the All on/thaw defuns. 3rd add a regen after thawing. And lastly car of the entsel  :-[


irneb thanks a lot for your effort,
am getting this error

after issuing the command it will show all off/frozen layers,
after picking the layer to turn-on/thaw, this error shows up


Code: [Select]
Command: layunhide
Regenerating model.

Command:
Select object on layer to unhide:
Select object on layer to unhide:
*** Error: Automation Error. Invalid layer ***
« Last Edit: November 07, 2012, 12:44:07 AM by NOD684 »
"memories fade but the scars still linger"

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Help to Modify a LISP
« Reply #21 on: November 07, 2012, 02:31:35 AM »
Replacement for lines 29-31:
Code - Auto/Visual Lisp: [Select]
  1.     (if (vl-position (vla-get-Name lay) LayersToTurnOn)
  2.       (foreach func '((vla-put-LayerOn . :vlax-true) (vla-put-Freeze . :vlax-false))
  3.  (vl-catch-all-apply (car func) (list lay (cdr func))))))
Again, for some reason certain layers cause errors - perhaps current layer? Or locked? Or defpoints / 0? Anyhow the catch should perform correctly. Also added another regen, otherwise the thaw doesn't display imediately after completing.
 
Edit: Again! See how screwed up IE's working with the forum editor? Tab indents just go silly!  :realmad:
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

RolandOrzabal

  • Newt
  • Posts: 86
  • "memories fade but the scars still linger"
Re: Help to Modify a LISP
« Reply #22 on: November 07, 2012, 03:00:24 AM »
irneb...no error this time

LayAllShow shows all frozen/off layers

but after picking the layer to turn on/thaw
nothing happens...it is still OFF/frozen

0 is not my current Layer.
tried it on other drawings but still the same
"memories fade but the scars still linger"

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Help to Modify a LISP
« Reply #23 on: November 07, 2012, 03:35:20 AM »
I don't know what to tell you. It seems to work fine here in ACA 2013 (sorry don't have a Vanilla here) ... for a while. Though sometimes I have to do it twice to the same layer before it catches. It's as if the first time round the layer doesn't allow itself to be "shown", but the second time round it says: "Agh alright ... if you want it so much then FINE!!!"  :realmad: Bloody lazy layers  :pissed:
 
It doesn't happen on all layers, just some of them. I can't figure out why this happens. Nothing locked or any such. It seems to happen on layers which were frozen or off - makes no difference. Anyone know why this occurs?
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

RolandOrzabal

  • Newt
  • Posts: 86
  • "memories fade but the scars still linger"
Re: Help to Modify a LISP
« Reply #24 on: November 07, 2012, 04:03:20 AM »
I don't know what to tell you. It seems to work fine here in ACA 2013 (sorry don't have a Vanilla here) ... for a while. Though sometimes I have to do it twice to the same layer before it catches. It's as if the first time round the layer doesn't allow itself to be "shown", but the second time round it says: "Agh alright ... if you want it so much then FINE!!!"  :realmad: Bloody lazy layers  :pissed:
 
It doesn't happen on all layers, just some of them. I can't figure out why this happens. Nothing locked or any such. It seems to happen on layers which were frozen or off - makes no difference. Anyone know why this occurs?

don't know too why...am using 2010
on my side even though i select the layers i want to show multiple time..still nothing happens.

I tried it on somebody else's pc and somebody else's file
same problem
"memories fade but the scars still linger"

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Help to Modify a LISP
« Reply #25 on: November 07, 2012, 04:16:32 AM »
When I say multiple times, I don't mean pick the layer numerous times. I mean run the LayUnHide command twice, pick the same object again & press enter again. After the 2nd run the layer turns on ... extremely strange!
 
I even thought it might be due to the Layer Manager Palette (since that sometimes causes these "cannot change layer properties" issues). But turning it off didn't do anything. Unfortunately I can't check if the ribbon has an effect, since there's no "Classic" setup in ACA - no menu bar either! I'm lost on this.
 
I was thinking of adding a repeat loop to perform the change multiple times, or even testing if the catch failed and repeat until it doesn't. That seems to work:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:LayAllThaw  ()
  2.     (vl-catch-all-apply 'vla-put-Freeze (list lay :vlax-false)))
  3.   (princ))
  4. (defun c:LayAllOn  ()
  5.     (vl-catch-all-apply 'vla-put-LayerOn (list lay :vlax-true)))
  6.   (princ))
  7. (defun c:LayAllShow () (c:LayAllThaw) (c:LayAllOn))
  8. (setq *LayUnHide-StateName* "_LayerUnHide_")
  9. (defun c:LayUnHide  (/ *error* LayersToTurnOn en)
  10.   (defun *error*  (msg)
  11.     (if (layerstate-has *LayUnHide-StateName*)
  12.       (progn (layerstate-restore *LayUnHide-StateName* nil)
  13.       (layerstate-delete *LayUnHide-StateName*)))
  14.     (cond ((or (not msg) (wcmatch (strcase msg) "*EXIT*,*QUIT*,*ABORT*")))
  15.    (t (prompt (strcat "*** Error: " msg " ***"))))
  16.     (princ))
  17.   (layerstate-save *LayUnHide-StateName* 3 nil)
  18.   (c:LayAllShow)
  19.   (while (setq en (entsel "\nSelect object on layer to unhide: "))
  20.     (setq LayersToTurnOn (cons (cdr (assoc 8 (entget (car en)))) LayersToTurnOn)))
  21.   (*error* nil)
  22.     (if (vl-position (vla-get-Name lay) LayersToTurnOn)
  23.       (foreach func '((vla-put-LayerOn . :vlax-true) (vla-put-Freeze . :vlax-false))
  24.  (while (vl-catch-all-error-p (vl-catch-all-apply (car func) (list lay (cdr func))))))))
  25.   (princ))
Though I really don't like the idea of looping until some weird thing stops happening ... or rather not-happening. It's like a cop-out and could lead to an infinite loop.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.