Author Topic: Looking for a Layer Script File  (Read 1578 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2084
Looking for a Layer Script File
« on: September 09, 2016, 08:01:22 PM »
I can't get the layer restore C:LRES to work.
Oops

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ARCH:FINDPATH Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ARCH:FINDPATHIT  ()
  (setq DWGPATH (strcat (getvar "dwgprefix") (getvar "dwgname")))
  (setq FINDPATH (substr DWGPATH 1 (- (strlen DWGPATH) 4))))

(defun C:LSAV  (/ lfile lfile1 lfilen entx lname layeron layerfr f1 f2)
  (setvar "cmdecho" 0)
  ;;(setq lfile "c:/ARCH_LAYSETS") 
  ;;(setq lfile (strcat  "\\ARCH_LAYSETS"))
  ;;(setq lfile1 (strcat lfile ".scr"))
  (ARCH:FINDPATHIT) ;new routine
  (setq lfile1 (strcat FINDPATH ".scr"))
  (setq lfilen (open lfile1 "w"))
  (prompt (strcat "\n* Storing Layer settings to: " lfile1 " *"))
  (terpri)
  (setq CLAYER1 (GETVAR "CLAYER"))
  (write-line "layer" lfilen)
  (write-line "S" lfilen)
  (write-line CLAYER1 lfilen)
  (setq entx (tblnext "layer" 1))
  (while entx
    (progn (setq lname (cdr (assoc 2 entx)))
           (setq layeron (cdr (assoc 62 entx)))
           (if (minusp layeron)
             (setq layeron "off")
             (setq layeron "on"))
           (setq layerfr (cdr (assoc 70 entx)))
           (setq f1 (/ layerfr 2))
           (setq f2 (/ layerfr 2.0))
           (if (< f1 f2)
             (setq layerfr "freeze")
             (setq layerfr "thaw"))
           (write-line layeron lfilen)
           (write-line lname lfilen)
           (write-line layerfr lfilen)
           (write-line lname lfilen)
           (setq entx (tblnext "layer"))))
  (write-line "" lfilen)
  (write-line "LAYS-RESTORE-MSG\n" lfilen)
  (close lfilen)
  (setvar "cmdecho" 1)
  (princ))
;;;
(defun C:LRES  (/ LRES)
  ;;(command "script" "c:/ARCH_LAYSETS")
  ;;(command "script" (findfile (strcat FINDPATH "\\ARCH_LAYSETS.scr")))
  (ARCH:FINDPATHIT) ;new routine   
  (setq LRES (findfile (strcat FINDPATH ".scr")))
  (setvar "cmdecho" 0)
  (command "script" LRES)
  (princ))
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2159
  • class keyThumper<T>:ILazy<T>
Re: Looking for a Layer Script File
« Reply #1 on: September 09, 2016, 09:31:16 PM »

In what way is it not working ?

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

GDF

  • Water Moccasin
  • Posts: 2084
Re: Looking for a Layer Script File
« Reply #2 on: September 09, 2016, 09:48:49 PM »
Xref layers
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2159
  • class keyThumper<T>:ILazy<T>
Re: Looking for a Layer Script File
« Reply #3 on: September 09, 2016, 10:12:29 PM »

What about them ?

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2159
  • class keyThumper<T>:ILazy<T>
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Looking for a Layer Script File
« Reply #5 on: September 11, 2016, 11:46:54 AM »
Assuming you want something quick (based on your code), to elaborate on Kerry's suggestion of using LayerStates, you could use something like the following.

Since your code requires

Code: [Select]
(defun c:LSav (/)
  (layerstate-save (getvar 'DWGNAME) 3 nil)
  (princ)
)


(defun c:LRes (/)
  (if (layerstate-restore (getvar 'DWGNAME) nil)
    (vla-regen (vla-get-activedocument (vlax-get-acad-object))
               (if (eq (getvar 'CVPORT) 1)
                 acAllViewports
                 acActiveViewport
               )
    )
  )
  (princ)
)

(vl-load-com)
(princ)



Since your code only accounts for on/off and freeze/thaw, I set the bit code to work the same way for the layerstate-save function.
Quote
1- Restore the saved On or Off value
2- Restore the saved Frozen or Thawed value
4- Restore the saved Lock value
8- Restore the saved Plot or No Plot value
16- Restore the saved VPVSDFLT value
32- Restore the saved Color
64- Restore the saved LineType
128- Restore the saved LineWeight
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

GDF

  • Water Moccasin
  • Posts: 2084
Re: Looking for a Layer Script File
« Reply #6 on: September 12, 2016, 10:27:38 AM »
Thanks guys. Been out of pocket. I was having trouble with script files running for xref layers.

I will start using layer states from now on.

Thanks Alan for the code.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2084
Re: Looking for a Layer Script File
« Reply #7 on: September 12, 2016, 10:37:04 AM »
Oh and thanks kdub.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Looking for a Layer Script File
« Reply #8 on: September 12, 2016, 11:00:04 AM »
Welcome.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox