View Full Version : Layer state creates new layers?
randyspear
2009-05-01, 04:37 PM
I have set up 2 layer states and created buttons for each one in one of our clients tool palettes. I initially set them up in a drawing with all layers loaded into it. The problem is that when i select the command the layer state works but creates any missing layers in the current drawing. How do i get it to stop creating layers and only change the properties of layers in the particular drawing?
I could add a purge layers command at the end of the macro so but they I might get rid of some layers that the user may want kept in the drawing. This will be my temporary solution right now but i'm curious to see if anyone has a way around this.
Thanks,
irneb
2009-05-04, 11:31 AM
Just a query ... how do you apply a layer state through a "macro"? Are you using the LISP function layerstate-restore or something else?
If as above, you might want to look at creating a custom function which saves a list of layers before running layerstate-restore. Then deletes any layers not in that list.
randyspear
2009-05-04, 11:51 AM
I'm just using the macro below:
^C^C-la;state;import;Drive:/path/layerstate.las;r;layerstate;;;-pu;la;;n;
What sort of format does the layer list get saved to? Is it only possible through lisp?
thanks,
irneb
2009-05-04, 01:19 PM
Uhhh!:Oops: Sorry ... forgot completely about the command line
However, I think you still need to go the LISP route to delete the new layers.
Here's an example using the normal command line as per your macro.
(vl-load-com)
;;; Restore Layer State without adding new layers
(defun SetLayerState (name / lst lay todel layers-collection)
;; Get a list of current layers
(while (setq lay (tblnext "LAYER" (not lay))) (setq lst (cons (cdr (assoc 2 lay)) lst)))
;; Run the command to import & set layer state
(command ".-LAYER"
"_stAte"
"_Import"
(findfile (strcat name ".LAY"))
"_Restore"
name
""
""
) ;_ end of command
;; Get new layers to delete
(setq lay nil
layers-collection
(vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
) ;_ end of setq
(while (setq lay (tblnext "LAYER" (not lay)))
;; Check if not a member of the old layer list
(if (not (member (cdr (assoc 2 lay)) lst))
(setq todel (cons (vla-Item layers-collection (cdr (assoc 2 lay))) todel))
) ;_ end of if
) ;_ end of while
;; Delete these layers if they're not used
(foreach lay todel
(if (= (vla-get-Used lay) :vlax-false)
(vla-Delete lay)
) ;_ end of if
) ;_ end of foreach
(princ)
) ;_ end of defunSave it to a LSP file in the support paths, add some form of loading this file (either autoloads in your ACADDOC.LSP or add to startup suite). Then add the following as macros to your buttons:
^C^C(SetLayerState "LayerStateName");
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.