레이어 상태(온오프/락/동결)를 저장하고, 바로 불러오는 리습 > 공유

본문 바로가기

공유

레이어 상태(온오프/락/동결)를 저장하고, 바로 불러오는 리습

페이지 정보

작성자 zwcad사용자 댓글 6건 조회 3,678회 작성일 23-05-26 15:15

본문

캐드 프로그램 종류, 버전: zwcad2023에서 테스트 완료

-명령어 요약 -
L1S - 현재 레이어 ON/OFF , LOCK/UNLOCK , FREEZE/THAW 상태 저장
L1 - L1S로 저장했던 시점으로 레이어 상태 복구
L0 - 도면을 처음 열었던 시점의 레이어 상태로 복구

아키모아에 올라온 레이어 상태 저장 리습을 보완했습니다.
기존에는 레이어 상태를 저장하는 텍스트 파일이 도면 저장 폴더에 저장되었는데, 임시 폴더 (temp)로 저장되도록 수정하였고
현재 작업 레이어가 동결하려는 대상 레이어일 경우 동결되지 않는 부분이 있어 우회 함수를 추가하였습니다 (현재 레이어를 0으로 설정)
그리고 도면 오픈 시점의 레이어 상태를 저장해서, 편집하고 다시 저장할때 L0만 입력하면 되도록 추가했습니다.
또한 ON/OFF상태, FREEZE/THAW 상태만 기억하도록 되어있었으나 LOCK/UNLOCK 상태도 기억하고, 불러오도록 수정했습니다.
수정하고 나니 사용성이 아주 좋아져서 만족스럽게 사용중인 리습입니다.

아래는 리습 코드입니다

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ


(defun c:L1S (/ pathb path0 path1 path2 path3 AcDoc oSpace LayerObjS LayerNameList_frz LayerNameList_off LayerNameList_lock LayerName_frz LayerName_off LayerName_lock k la_wr1 la1 la_wr2 la2 la_wr3 la3)

(vl-load-com)

(setq pathb (strcat (getenv "TEMP") "\\DB\\"))
(vl-mkdir pathb)
(setq path0 (strcat (getenv "TEMP") "\\DB\\1\\"))
(vl-mkdir path0)


(setq path1 (strcat (getenv "TEMP") "\\DB\\1\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "_freeze_layerlist.txt")) ;파일이 위치한곳에 freeze-layerlist.txt 파일이름 경로 설정
(setq path2 (strcat (getenv "TEMP") "\\DB\\1\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "_off_layerlist.txt")) ;파일이 위치한곳에 freeze-layerlist.txt 파일이름 경로 설정
(setq path3 (strcat (getenv "TEMP") "\\DB\\1\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "_lock_layerlist.txt")) ;파일이 위치한곳에 freeze-layerlist.txt 파일이름 경로 설정

(princ "\nLayer List Off....")
(setq AcDoc (vla-get-activedocument (vlax-get-acad-object)))
(cond
((= (vla-get-activespace AcDoc) 1) (setq oSpace (vla-get-modelspace AcDoc)))
((= (vla-get-activespace AcDoc) 0) (setq oSpace (vla-get-paperspace AcDoc)))
)

(setq LayerObjS (vla-get-layers AcDoc))






(setq LayerNameList_frz '())
(vlax-for xxx LayerObjS
(setq LayerName_frz (vla-get-name xxx))
(if (= (vla-get-Freeze xxx) :vlax-true)
(setq LayerNameList_frz (append LayerNameList_frz (list LayerName_frz)))
)
)

(if (/= layerNameList_frz nil)
(progn
(setq la_wr1 (open path1 "w")) ;freeze-layerlist.txt 쓰기전용으로 열기를 la_wr1에 지정
(setq k 0) ;k은 0
(repeat (length LayerNameList_frz) ;new-lst의 원자 개수만큼 반복시작
(setq la1 (nth k LayerNameList_frz)) ;new-lst의 k번째 원자를 la에 정의
(write-line la1 la_wr1) ;freeze-layerlist.txt 에 la를 기입
(setq k (+ k 1)) ;k에 1씩 추가하고 반복
)
(close la_wr1) ;열기한 파일을 닫기
(princ "\n")(princ path1) (princ " 을 생성하였습니다.") ;파일을 생성한 경로 출력
(princ)
)

(if (/= (findfile path1) nil)
(progn
(vl-file-delete path1)
(princ "\n")(princ path1) (princ " 을 제거하였습니다.") ;파일을 생성한 경로 출력
(princ)
)
)

)


(setq LayerNameList_off '())
(vlax-for xxx LayerObjS
(setq LayerName_off (vla-get-name xxx))
(if (= (vla-get-LayerOn xxx) :vlax-false)
(setq LayerNameList_off (append LayerNameList_off (list LayerName_off)))
)
)
 
(if (/= layerNameList_off nil)
(progn
(setq la_wr2 (open path2 "w")) ;freeze-layerlist.txt 쓰기전용으로 열기를 la_wr1에 지정
(setq k 0) ;k은 0
(repeat (length LayerNameList_off) ;new-lst의 원자 개수만큼 반복시작
(setq la2 (nth k LayerNameList_off)) ;new-lst의 k번째 원자를 la에 정의
(write-line la2 la_wr2) ;freeze-layerlist.txt 에 la를 기입
(setq k (+ k 1)) ;k에 1씩 추가하고 반복
)
(close la_wr2) ;열기한 파일을 닫기

(princ "\n")(princ path2) (princ " 을 생성하였습니다.") ;파일을 생성한 경로 출력
(princ)
)

(if (/= (findfile path2) nil)
(progn
(vl-file-delete path2)
(princ "\n")(princ path2) (princ " 을 제거하였습니다.") ;파일을 생성한 경로 출력
(princ)
)
)

)


(setq LayerNameList_lock '())
(vlax-for xxx LayerObjS
(setq LayerName_lock (vla-get-name xxx))
(if (= (vla-get-lock xxx) :vlax-true)
(setq LayerNameList_lock (append LayerNameList_lock (list LayerName_lock)))
)
)

(if (/= layerNameList_lock nil)
(progn
(setq la_wr3 (open path3 "w"))
(setq k 0)
(repeat (length LayerNameList_lock)
(setq la3 (nth k LayerNameList_lock))
(write-line la3 la_wr3)
(setq k (+ k 1))
)
(close la_wr3)
(princ "\n")(princ path3) (princ " 을 생성하였습니다.")
(princ)
)

(if (/= (findfile path3) nil)
(progn
(vl-file-delete path3)
(princ "\n")(princ path3) (princ " 을 제거하였습니다.")
(princ)
)
)

)




(princ)
)









(defun c:L1 (/ ladb1 ladb2 ladb3 doc path1 path2 path3 op1 op2 op3 temp1 temp2 temp3)

(vl-load-com)

(set-layers-on)
(set-layers-unlock)
(thaw-layers)
(setvar "clayer" "0")
(setq ladb1 '())
(setq ladb2 '())
(setq ladb3 '())
(setq doc (vla-get-activedocument (vlax-get-acad-object)))


(setq path1 (strcat (getenv "TEMP") "\\DB\\1\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "_freeze_layerlist.txt"))

(if (/= (findfile path1) nil)
(progn
(setq op1 (open path1 "r"))
(while (setq temp1 (read-line op1))
(setq ladb1 (append ladb1 (list temp1)))
)
(close op1)

(vlax-for obj (vla-get-layers doc)
(if (vl-position (vla-get-name obj) ladb1)
(vl-catch-all-apply 'vla-put-freeze (list obj :vlax-true))
)
)
)
)


(setq path2 (strcat (getenv "TEMP") "\\DB\\1\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "_off_layerlist.txt"))

(if (/= (findfile path2) nil)
(progn
(setq op2 (open path2 "r"))
(while (setq temp2 (read-line op2))
(setq ladb2 (append ladb2 (list temp2)))
)
(close op2)

(vlax-for obj (vla-get-layers doc)
(if (vl-position (vla-get-name obj) ladb2)
(vl-catch-all-apply 'vla-put-layeron (list obj :vlax-false))
)
)
)
)


(setq path3 (strcat (getenv "TEMP") "\\DB\\1\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "_lock_layerlist.txt"))

(if (/= (findfile path3) nil)
(progn
(setq op3 (open path3 "r"))
(while (setq temp3 (read-line op3))
(setq ladb3 (append ladb3 (list temp3)))
)
(close op3)

(vlax-for obj (vla-get-layers doc)
(if (vl-position (vla-get-name obj) ladb3)
(vl-catch-all-apply 'vla-put-lock (list obj :vlax-true))
)
)
)
)

(princ "\n1번 레이어 목록으로 설정 완료")
(princ)
)






(defun L0S (/ pathb path0 path1 path2 path3 AcDoc oSpace LayerObjS LayerNameList_frz LayerNameList_off LayerNameList_lock LayerName_frz LayerName_off LayerName_lock k la_wr1 la1 la_wr2 la2 la_wr3 la3)

(vl-load-com)

(setq pathb (strcat (getenv "TEMP") "\\DB\\"))
(vl-mkdir pathb)
(setq path0 (strcat (getenv "TEMP") "\\DB\\0\\"))
(vl-mkdir path0)


(setq path1 (strcat (getenv "TEMP") "\\DB\\0\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "_freeze_layerlist.txt")) ;파일이 위치한곳에 freeze-layerlist.txt 파일이름 경로 설정
(setq path2 (strcat (getenv "TEMP") "\\DB\\0\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "_off_layerlist.txt")) ;파일이 위치한곳에 freeze-layerlist.txt 파일이름 경로 설정
(setq path3 (strcat (getenv "TEMP") "\\DB\\0\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "_lock_layerlist.txt")) ;파일이 위치한곳에 freeze-layerlist.txt 파일이름 경로 설정


(setq AcDoc (vla-get-activedocument (vlax-get-acad-object)))
(cond
((= (vla-get-activespace AcDoc) 1) (setq oSpace (vla-get-modelspace AcDoc)))
((= (vla-get-activespace AcDoc) 0) (setq oSpace (vla-get-paperspace AcDoc)))
)

(setq LayerObjS (vla-get-layers AcDoc))






(setq LayerNameList_frz '())
(vlax-for xxx LayerObjS
(setq LayerName_frz (vla-get-name xxx))
(if (= (vla-get-Freeze xxx) :vlax-true)
(setq LayerNameList_frz (append LayerNameList_frz (list LayerName_frz)))
)
)

(if (/= layerNameList_frz nil)
(progn
(setq la_wr1 (open path1 "w")) ;freeze-layerlist.txt 쓰기전용으로 열기를 la_wr1에 지정
(setq k 0) ;k은 0
(repeat (length LayerNameList_frz) ;new-lst의 원자 개수만큼 반복시작
(setq la1 (nth k LayerNameList_frz)) ;new-lst의 k번째 원자를 la에 정의
(write-line la1 la_wr1) ;freeze-layerlist.txt 에 la를 기입
(setq k (+ k 1)) ;k에 1씩 추가하고 반복
)
(close la_wr1) ;열기한 파일을 닫기
(princ)
)

(if (/= (findfile path1) nil)
(progn
(vl-file-delete path1)
(princ "\n")(princ path1) (princ " 을 제거하였습니다.") ;파일을 생성한 경로 출력
(princ)
)
)

)


(setq LayerNameList_off '())
(vlax-for xxx LayerObjS
(setq LayerName_off (vla-get-name xxx))
(if (= (vla-get-LayerOn xxx) :vlax-false)
(setq LayerNameList_off (append LayerNameList_off (list LayerName_off)))
)
)
 
(if (/= layerNameList_off nil)
(progn
(setq la_wr2 (open path2 "w")) ;freeze-layerlist.txt 쓰기전용으로 열기를 la_wr1에 지정
(setq k 0) ;k은 0
(repeat (length LayerNameList_off) ;new-lst의 원자 개수만큼 반복시작
(setq la2 (nth k LayerNameList_off)) ;new-lst의 k번째 원자를 la에 정의
(write-line la2 la_wr2) ;freeze-layerlist.txt 에 la를 기입
(setq k (+ k 1)) ;k에 1씩 추가하고 반복
)
(close la_wr2) ;열기한 파일을 닫기
(princ)
)

(if (/= (findfile path2) nil)
(progn
(vl-file-delete path2)
(princ "\n")(princ path2) (princ " 을 제거하였습니다.") ;파일을 생성한 경로 출력
(princ)
)
)

)


(setq LayerNameList_lock '())
(vlax-for xxx LayerObjS
(setq LayerName_lock (vla-get-name xxx))
(if (= (vla-get-lock xxx) :vlax-true)
(setq LayerNameList_lock (append LayerNameList_lock (list LayerName_lock)))
)
)

(if (/= layerNameList_lock nil)
(progn
(setq la_wr3 (open path3 "w"))
(setq k 0)
(repeat (length LayerNameList_lock)
(setq la3 (nth k LayerNameList_lock))
(write-line la3 la_wr3)
(setq k (+ k 1))
)
(close la_wr3)
(princ)
)

(if (/= (findfile path3) nil)
(progn
(vl-file-delete path3)
(princ "\n")(princ path3) (princ " 을 제거하였습니다.")
(princ)
)
)

)




(princ)
)








(defun c:L0 (/ ladb1 ladb2 ladb3 doc path1 path2 path3 op1 op2 op3 temp1 temp2 temp3)

(vl-load-com)
(set-layers-on)
(set-layers-unlock)
(thaw-layers)

(setvar "clayer" "0")
(setq ladb1 '())
(setq ladb2 '())
(setq ladb3 '())
(setq doc (vla-get-activedocument (vlax-get-acad-object)))


(setq path1 (strcat (getenv "TEMP") "\\DB\\0\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "_freeze_layerlist.txt"))

(if (/= (findfile path1) nil)
(progn
(setq op1 (open path1 "r"))
(while (setq temp1 (read-line op1))
(setq ladb1 (append ladb1 (list temp1)))
)
(close op1)

(vlax-for obj (vla-get-layers doc)
(if (vl-position (vla-get-name obj) ladb1)
(vl-catch-all-apply 'vla-put-freeze (list obj :vlax-true))
)
)
)
)


(setq path2 (strcat (getenv "TEMP") "\\DB\\0\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "_off_layerlist.txt"))

(if (/= (findfile path2) nil)
(progn
(setq op2 (open path2 "r"))
(while (setq temp2 (read-line op2))
(setq ladb2 (append ladb2 (list temp2)))
)
(close op2)

(vlax-for obj (vla-get-layers doc)
(if (vl-position (vla-get-name obj) ladb2)
(vl-catch-all-apply 'vla-put-layeron (list obj :vlax-false))
)
)
)
)


(setq path3 (strcat (getenv "TEMP") "\\DB\\0\\" (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4)) "_lock_layerlist.txt"))

(if (/= (findfile path3) nil)
(progn
(setq op3 (open path3 "r"))
(while (setq temp3 (read-line op3))
(setq ladb3 (append ladb3 (list temp3)))
)
(close op3)

(vlax-for obj (vla-get-layers doc)
(if (vl-position (vla-get-name obj) ladb3)
(vl-catch-all-apply 'vla-put-lock (list obj :vlax-true))
)
)
)
)

(princ "\n 레이어 상태 복구 완료")
(princ)
)
(defun set-layers-on ()
  (vl-catch-all-apply
    '(lambda ()
      (vlax-for obj (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (vla-put-layeron obj :vlax-true)
      )
    )
  )
 )

(defun set-layers-unlock ()
  (vl-catch-all-apply
    '(lambda ()
      (vlax-for obj (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (vla-put-lock obj :vlax-false)
      )
    )
  )
 )

(defun thaw-layers ()
  (vl-catch-all-apply
    '(lambda ()
      (vlax-for obj (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (vla-put-freeze obj :vlax-false)
      )
    )
  )
 )

(L0S)
  • 트위터로 보내기
  • 페이스북으로 보내기
  • 구글플러스로 보내기

댓글목록

zwcad사용자님의 댓글

zwcad사용자 작성일

오토캐드에서는 작동이 안되어 확인해보니
(set-layers-on)  ->  (command "layer" "on" "*" "")
(set-layers-unlock)  ->  (command "layer" "u" "*" "")
(thaw-layers)  -> (command "layer" "t" "*" "")
로 변경해서 사용해야 하네요

유저님의 댓글

유저 작성일

autocad 2022 쓰고 있는데 구문 변경 안해도 잘 되네요 잘쓰겠습니다

유저님의 댓글

유저 작성일

근데 제가 작업하면서 레어어를 Lock 시키면 흐리게 처리하도록 해놨는데 L1으로 복구하면 원래대로 밝게 보입니다 LAYLOCKFADECTL 변수 수치는 그대로구요 방법이 없을까요

zwcad사용자님의 댓글

zwcad사용자 작성일

제 오토캐드 기간이 만료되어 확인할수는 없지만.. (set-layers-unlock) 함수가 문제인 것 같은데
해당 구문을 (command "layer" "u" "*" "") 로 변경하면 정상 작동할 듯 싶습니다
그게 아니라면 lock 시키는 구문을 수정해야 하는데 zwcad에서는 재현이 안되다 보니 도움을 드리기 어렵네요

유저님의 댓글

유저 작성일

잘알겠습니다. 감사합니다

zwcad사용자님의 댓글

zwcad사용자 작성일

command 구문으로 변경하면 정상 작동하나 속도가 많이 느려 기존 구문 이용 후  regen 하는게 나을 듯 합니다


XICAD, Copyright © izzarder.com All rights reserved.