TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CADaver on September 26, 2006, 02:20:41 PM
-
Okay here's one for the gurus, I have no idea where to even start looking. We all have a pile of functions that will delete all layer filters (is there one to delete selected filters?), but I want a function to create a layer filter, specifically xref layer filtered out (~*|*). Anybody have a clue where to start?
psst.. i'm busting a guys chops on the "other" forum about being too lazy to hit invert, so don't let this get out...
-
I don't have time to write a proper version of this (e.g. resolve the fact a filter with the name "NoXrefs" may alsready exist) but here's a start --
(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
"NoXrefs"
(entmakex
'(
(0 . "xrecord")
(100 . "AcDbXrecord")
(280 . 1)
(1 . "NoXrefs")
(1 . "~*|*")
(1 . "*")
(1 . "*")
(70 . 0)
(1 . "*")
(1 . "*")
(-3
( "ACAD"
(1000 . "( NAME== \"~*|*\" )")
)
)
)
)
)
(princ)
)
-
Here is one using ActiveX controls. [just a start also, but works]
(defun MySetXRec (Obj CodeList DataList / )
; Sets XRecordData. Dxf numbers between 1-369, except 5, 100, 105.
; See help for types and numbers to use.
(vla-SetXRecordData Obj
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbInteger
(cons 0 (1- (length CodeList)))
)
CodeList
)
)
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbVariant
(cons 0 (1- (length Datalist)))
)
DataList
)
)
)
)
(setq LayDict (vla-GetExtensionDictionary (vla-get-Layers (vla-get-ActiveDocument (vlax-get-Acad-Object)))))
(if (vl-catch-all-error-p (setq LayFltDict (vl-catch-all-apply 'vla-Item (list LayDict "AcLyDictionary"))))
(setq LayFltDict (vla-AddObject LayDict "AcLyDictionary" "AcDbDictionary"))
)
(setq xRec (vla-AddXRecord LayFltDict "Non-XrefLayers"))
(MySetXRec xRec'(1 90 300 301) '("AcLyLayerFilter" 1 "MyNon-Xrefs" "NAME==\"~*|*\""))
The two list represent what has to be there
1 = What the xrecord is, here it's an "AcLyLayerFilter"
90 = Not sure, but has to be there to use it
300 = Name
301 = What to filter
-
Another quick variant --
(defun c:Foo ( / xdict dict xrecname )
(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)
)
)
)
)
)
(princ
(if (dictsearch dict (setq xrecname "No_Xref_Layers"))
(strcat
"Layer filter named <"
xrecname
"> already exists."
)
(if
(dictadd dict xrecname
(entmakex
(append
'(
(0 . "xrecord")
(100 . "AcDbXrecord")
(280 . 1)
)
(list (cons 1 xrecname))
'(
(1 . "~*|*")
(1 . "*")
(1 . "*")
(70 . 0)
(1 . "*")
(1 . "*")
(-3
( "ACAD"
(1000 . "( NAME== \"~*|*\" )")
)
)
)
)
)
)
(strcat
"Created layer filter named <"
xrecname
">."
)
"Doh! Something horrible happened: Call mommy."
)
)
)
(princ)
)
-
Another version - not mine though reworked
Dan
;;; From: "GaryDF" <arch_prog...@hotmail.com>
;;; Newsgroups: autodesk.autocad.customization
;;; References: <3788944.1106770311821.JavaMail.jive@jiveforum1.autodesk.com>
;;; 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:MakeFilters ( / filtlst)
(setq filtlst
(list ;;name Lay col lt flags lw plot
(list "OnThawed" "*" "*" "*" 13 "*" "*")
(list "OffThawed" "*" "*" "*" 15 "*" "*")
(list "OnFrozen" "*" "*" "*" 5 "*" "*")
)
)
(sdg_CreateLayerFilter filtlst)
)
(c:MakeFilters)
-
Thanks Dan.
Here is a link to the original thread & GaryDF's lisp.
http://tinyurl.com/kzf6k
-
<"The Horror!">
snicker
-
Thanks everyone, it'll take me a day or twenty to hash through all these, but I can already see a half dozen new routines for the office.
-
Nice. But how do you make a group filter?
-
How to set a certain layerfilter(name) active without using te layer dialog command... ?
-
Autocad 2009-2012
(command "_.layer" "_filter" "_set" filterName "_exit" "")
filterName - The exact name of the layerfilter (name), case sensitive
Example, for English Autocad, set the active filter - "All"
(command "_.layer" "_filter" "_set" "All" "_exit" "")
Other good stuff to create layer filters getFilterDatas and addLayerFilter from gile
http://forums.augi.com/showpost.php?p=952247&postcount=3
http://cadxp.com/index.php?/topic/20851-exporterimporter-des-filtres-de-calque/
-
Thanks!! :-)
-
the undocumented command +LAYER lets you set one current...
Command: +layer
Specify filter [All/All Used Layers/Unreconciled New Layers/Viewport
Overrides/Xref/07333000M01] <All>: *Cancel*