; Recomended to put this lisp in startup autolisp suite
;;; Created by: "GaryDF"
;;; Modified by Igal Averbuh 2015
;;; From: "GaryDF"
;;; Newsgroups: autodesk.autocad.customization
;;; References:
;;; Subject: Re: need lisp to CREATE layer filters
;;; Date: Thu, 27 Jan 2005 08:28:08 -0600
;;; Posted by Elise Moss
;;; ON/OFF
;;; On 1
;;; Off 3
;;; FREEZE/THAW
;;; Freeze 4
;;; Thaw 12
;;; CURRENT VPORT
;;; Freeze 16
;;; Thaw 48
;;; NEW VPORT
;;; Freeze 64
;;; Thaw 192
;;; LOCK/UNLOCK
;;; Lock 256
;;; UnLock 768
;;; PLOT
;;; Plot 1024
;;; Don't Plot 3072

(defun sdg_CreateLayerFilter (filtlst / lfiltobj safecode safefilt)
(vl-load-com)
(setq LFILTOBJ (vla-addobject
(vla-GetExtensionDictionary
(vla-Get-Layers
(vla-Get-ActiveDocument
(vlax-Get-Acad-Object)
)
)
)
"ACAD_LAYERFILTERS"
"AcDbDictionary"
)
SAFECODE (vlax-make-safearray 2 '(0 . 6))
SAFEFILT (vlax-make-safearray 12 '(0 . 6))
)
(vlax-safearray-fill SAFECODE (list 1 1 1 1 70 1 1))
(foreach
SUBLST FILTLST
(vlax-safearray-fill
SAFEFILT
(mapcar '(lambda (X) (vlax-make-variant X 8)) SUBLST)
)
(vla-addxrecord LFILTOBJ (nth 0 SUBLST))
(vla-setxrecorddata
(vla-item LFILTOBJ (nth 0 SUBLST))
SAFECODE
SAFEFILT
)
)
(prin1)
)
(defun c:FZ ( / filtlst)
(setq filtlst
(list ;;name Lay col lt flags lw plot
(list "ON" "*" "*" "*" 13 "*" "*")
(list "OFF" "*" "*" "*" 15 "*" "*")
(list "FROZEN" "*" "*" "*" 5 "*" "*")
)
)
(sdg_CreateLayerFilter filtlst)
)

(c:FZ)

(command "-layer" "filter" "D" "NOPLOT" "")

(command "-layer" "filter" "D" "VP-FROZEN" "")

(command "-layer" "filter" "D" "LOCKED" "")

(command "-layer" "filter" "N" "P" "" "PLOTTABLE==\"False\"" "NOPLOT" "x" "")

(command "-layer" "filter" "N" "P" "" "VPFROZEN==\"True\"" "VP-FROZEN" "x" "")

(command "-layer" "filter" "N" "P" "" "LOCKED==\"True\"" "LOCKED" "x" "")

(defun c:Foo ( / xdict dict )

(setq xdict
(vlax-vla-object->ename
(vla-getextensiondictionary
(vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
)
)
)

(setq dict
(if (setq dict (dictsearch xdict "ACAD_LAYERFILTERS"))
(cdr (assoc -1 dict))
(dictadd xdict "ACAD_LAYERFILTERS"
(entmakex
'(
(0 . "dictionary")
(100 . "AcDbDictionary")
(280 . 0)
(281 . 1)
)
)
)
)
)

(dictadd
dict
"NO XREFS"
(entmakex
'(
(0 . "xrecord")
(100 . "AcDbXrecord")
(280 . 1)
(1 . "NO XREFS")
(1 . "~*|*")
(1 . "*")
(1 . "*")
(70 . 0)
(1 . "*")
(1 . "*")
(-3
( "ACAD"
(1000 . "( NAME== \"~*|*\" )")
)
)
)
)
)

(princ)

)

(c:foo)

(defun c:Foz ( / xdict dict )

(setq xdict
(vlax-vla-object->ename
(vla-getextensiondictionary
(vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
)
)
)

(setq dict
(if (setq dict (dictsearch xdict "ACAD_LAYERFILTERS"))
(cdr (assoc -1 dict))
(dictadd xdict "ACAD_LAYERFILTERS"
(entmakex
'(
(0 . "dictionary")
(100 . "AcDbDictionary")
(280 . 0)
(281 . 1)
)
)
)
)
)

(dictadd
dict
"TPZ"
(entmakex
'(
(0 . "xrecord")
(100 . "AcDbXrecord")
(280 . 1)
(1 . "TPZ")
(1 . "TPZ*")
(1 . "*")
(1 . "*")
(70 . 0)
(1 . "*")
(1 . "*")
(-3
( "ACAD"
(1000 . "( NAME== \"TPZ*\" )")
)
)
)
)
)

(princ)

)

(c:foz)

(defun c:Fob ( / xdict dict )

(setq xdict
(vlax-vla-object->ename
(vla-getextensiondictionary
(vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
)
)
)

(setq dict
(if (setq dict (dictsearch xdict "ACAD_LAYERFILTERS"))
(cdr (assoc -1 dict))
(dictadd xdict "ACAD_LAYERFILTERS"
(entmakex
'(
(0 . "dictionary")
(100 . "AcDbDictionary")
(280 . 0)
(281 . 1)
)
)
)
)
)

(dictadd
dict
"BAR"
(entmakex
'(
(0 . "xrecord")
(100 . "AcDbXrecord")
(280 . 1)
(1 . "BAR")
(1 . "BAR*")
(1 . "*")
(1 . "*")
(70 . 0)
(1 . "*")
(1 . "*")
(-3
( "ACAD"
(1000 . "( NAME== \"BAR*\" )")
)
)
)
)
)

(princ)

)

(c:fob)
(command "-layer" "filter" "s" "All" "x" "")

Advertisements