Author Topic: Make a layer filter... yes i said MAKE  (Read 11063 times)

0 Members and 1 Guest are viewing this topic.

CADaver

  • Guest
Make a layer filter... yes i said MAKE
« 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...


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Make a layer filter... yes i said MAKE
« Reply #1 on: September 26, 2006, 02:59:07 PM »
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 --

Code: [Select]
(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)
   
)
« Last Edit: September 26, 2006, 03:10:31 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Make a layer filter... yes i said MAKE
« Reply #2 on: September 26, 2006, 03:11:09 PM »
Here is one using ActiveX controls.  [just a start also, but works]
Code: [Select]
(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
  )
 )
)
)
Code: [Select]
(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
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Make a layer filter... yes i said MAKE
« Reply #3 on: September 26, 2006, 05:09:00 PM »
Another quick variant --

Code: [Select]
(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)
   
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

dan19936

  • Guest
Re: Make a layer filter... yes i said MAKE
« Reply #4 on: September 26, 2006, 08:43:21 PM »
Another version - not mine though reworked

Dan

Code: [Select]
;;; 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)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make a layer filter... yes i said MAKE
« Reply #5 on: September 27, 2006, 08:07:13 AM »
Thanks Dan.

Here is a link to the original thread & GaryDF's lisp.
http://tinyurl.com/kzf6k
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Birdy

  • Guest
Re: Make a layer filter... yes i said MAKE
« Reply #6 on: September 27, 2006, 12:21:56 PM »
<"The Horror!">
snicker

CADaver

  • Guest
Re: Make a layer filter... yes i said MAKE
« Reply #7 on: September 27, 2006, 02:06:25 PM »
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.

Crank

  • Water Moccasin
  • Posts: 1503
Re: Make a layer filter... yes i said MAKE
« Reply #8 on: September 28, 2006, 02:10:49 PM »
Nice. But how do you make a group filter?
Vault Professional 2023     +     AEC Collection

lamarn

  • Swamp Rat
  • Posts: 636
Re: Make a layer filter... yes i said MAKE
« Reply #9 on: February 22, 2012, 08:23:21 AM »
How to set a certain layerfilter(name) active without using te layer dialog command... ?
Design is something you should do with both hands. My 2d hand , my 3d hand ..

VVA

  • Newt
  • Posts: 166
Re: Make a layer filter... yes i said MAKE
« Reply #10 on: February 22, 2012, 11:45:14 AM »
Autocad 2009-2012
 
Code: [Select]
(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"
Code: [Select]
(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/
« Last Edit: February 22, 2012, 12:03:26 PM by VVA »

lamarn

  • Swamp Rat
  • Posts: 636
Re: Make a layer filter... yes i said MAKE
« Reply #11 on: February 22, 2012, 12:07:58 PM »
Thanks!! :-)
Design is something you should do with both hands. My 2d hand , my 3d hand ..

cadtag

  • Swamp Rat
  • Posts: 1152
Re: Make a layer filter... yes i said MAKE
« Reply #12 on: February 22, 2012, 01:15:12 PM »
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*
The only thing more dangerous to the liberty of a free people than big government is big business