How to access layer filters via AutoLISP

Discussion in 'AutoCAD' started by John Avitt, Oct 15, 2004.

  1. John Avitt

    John Avitt Guest

    I can't figure out how to access layer filters via AutoLISP. I have some
    drawing files that have scores of layer filters, and I would like to be able
    to delete these objects via AutoLISP. Any help is appreciated.

    Thank you.

    John
     
    John Avitt, Oct 15, 2004
    #1
  2. Try:

    (setq ss (ssget "x" (list (cons 8 "contorno"))))

    Contorno = layer name

    Select all entities in layer Contorno

    []´s,

    Rogério
     
    Rogerio_Brazil, Oct 15, 2004
    #2
  3. whatever...

    here is the lisp:

    ;VISUAL LISP VERSION, TAKES LONG SOMETIMES
    (defun C:DELFILTERS-VL ( / lext-dict ldict lay_entity lay_filters filter_names)
    (setq lext-dict
    (entget
    (vlax-vla-object->ename
    (vla-GetExtensionDictionary
    (vla-get-layers
    (vla-get-ActiveDocument
    (vlax-get-acad-object)
    )
    )
    )
    )
    )
    )
    (if (setq ldict (member (cons 3 "ACAD_LAYERFILTERS") lext-dict))
    (cdr (assoc 360 ldict))
    nil
    )
    (setq lay_entity (cdr (assoc 360 ldict)))
    (setq lay_filters (entget lay_entity))
    (while (assoc 3 lay_filters)
    (progn
    (setq filter_names (cdr (assoc 3 lay_filters)))
    (dictremove lay_entity filter_names)
    (setq lay_filters (entget lay_entity))
    )
    )
    (princ)
    )


    Rogerio_Brazil <>
    |>Try:
    |>
    |>(setq ss (ssget "x" (list (cons 8 "contorno"))))
    |>
    |>Contorno = layer name
    |>
    |>Select all entities in layer Contorno
    |>
    |>[]´s,
    |>
    |>Rogério

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Oct 15, 2004
    #3
  4. James, don`t work in cad 2000.

    Command: DELFILTERS-VL
    error: bad argument type: lentityp nil
    ; error: An error has occurred inside the *error*

    How to proceed?

    Thanks,

    Rogério
     
    Rogerio_Brazil, Oct 15, 2004
    #4
  5. I saved with name: DELFILTERS-VL.lsp.

    Is corrrect? Wath extension? (sorry my english).

    Thanks.

    Rogério
     
    Rogerio_Brazil, Oct 15, 2004
    #5
  6. do these lines one at a time, which one errors out?

    (vlax-get-acad-object)

    (vla-get-ActiveDocument (vlax-get-acad-object))

    (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)))

    (vla-GetExtensionDictionary (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object) ) ) )

    (vlax-vla-object->ename (vla-GetExtensionDictionary (vla-get-layers (vla-get-ActiveDocument
    (vlax-get-acad-object)))))



    Rogerio_Brazil <>
    |>James, don`t work in cad 2000.
    |>
    |>Command: DELFILTERS-VL
    |>error: bad argument type: lentityp nil
    |>; error: An error has occurred inside the *error*
    |>
    |>How to proceed?
    |>
    |>Thanks,
    |>
    |>Rogério

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Oct 15, 2004
    #6
  7. All lines ok.

    with cmdecho = 1,
    Command: DELFILTERS-VL
    error: bad argument type: lentityp nil
    ; error: An error has occurred inside the *error*

    Command: (vlax-get-acad-object)
    #<VLA-OBJECT IAcadApplication 00ac8928>

    Command: (vla-get-ActiveDocument (vlax-get-acad-object))
    #<VLA-OBJECT IAcadDocument 0288c3ac>

    Command: (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)))
    #<VLA-OBJECT IAcadLayers 027c4b1c>

    Command: (vla-GetExtensionDictionary (vla-get-layers (vla-get-ActiveDocument
    (vlax-get-acad-object) ) ) )
    #<VLA-OBJECT IAcadDictionary 0284fa9c>

    Command: (vlax-vla-object->ename (vla-GetExtensionDictionary (vla-get-layers
    (vla-get-ActiveDocument
    ((((_> (vlax-get-acad-object)))))
    <Entity name: 6a01468>

    thanks
     
    Rogerio_Brazil, Oct 15, 2004
    #7
  8. John Avitt

    T.Willey Guest

    Could it just be a case of no (vl-load-com)??

    Tim
     
    T.Willey, Oct 15, 2004
    #8
  9. no, one of the lines would have failed.

    "T.Willey" <>
    |>Could it just be a case of no (vl-load-com)??
    |>
    |>Tim

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Oct 15, 2004
    #9
  10. ok, continue copying and pasting the lisp lines to the command line til something bugs out.
    This is debugging the hard way.

    The easy way is to open the code in the Visual Lisp editor (type VLIDE to get it)
    then put the cursor before the first line of code after the defun line,
    then hit F9 so it sets a little red blotch at that point.
    Then pick the Tools->Load Text in Editor pulldown item,
    then run the DELFILTERS-VL command.

    It will kick you to the vlide and let you step through the code with F8.
    It will stop on the error line.
    You can highlight variables and right click to set a watch or inspect the value of the variable at that time.
    I think only 5% of lispers know how to do this but its so easy.

    If all this fails, look for more threads, this routine gets posted like every month....
    Maybe others code will work better.
    I'll still watch this thread though.
    thx

    Rogerio_Brazil <>
    |>All lines ok.
    |>
    |>with cmdecho = 1,
    |>Command: DELFILTERS-VL
    |>error: bad argument type: lentityp nil
    |>; error: An error has occurred inside the *error*
    |>
    |>Command: (vlax-get-acad-object)
    |>#<VLA-OBJECT IAcadApplication 00ac8928>
    |>
    |>Command: (vla-get-ActiveDocument (vlax-get-acad-object))
    |>#<VLA-OBJECT IAcadDocument 0288c3ac>
    |>
    |>Command: (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)))
    |>#<VLA-OBJECT IAcadLayers 027c4b1c>
    |>
    |>Command: (vla-GetExtensionDictionary (vla-get-layers (vla-get-ActiveDocument
    |>(vlax-get-acad-object) ) ) )
    |>#<VLA-OBJECT IAcadDictionary 0284fa9c>
    |>
    |>Command: (vlax-vla-object->ename (vla-GetExtensionDictionary (vla-get-layers
    |>(vla-get-ActiveDocument
    |>((((_> (vlax-get-acad-object)))))
    |><Entity name: 6a01468>
    |>
    |>thanks

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Oct 15, 2004
    #10
  11. John Avitt

    John Avitt Guest

    I have found what may be a short cut.
    Simply delete the ACAD_LAYERFILTERS dictionary object, as in:

    ....
    (setq lay_entity (cdr (assoc 360 ldict)))
    (entdel lay_entity)
    ....

    Would there be any harm doing it this way?

    Thank you.

    John
     
    John Avitt, Oct 15, 2004
    #11
  12. John Avitt

    John Avitt Guest

    Here is the entire code. Note that I did not have to use vla or vlax.
    The main problem I had was just finding where the data was stored.
    Once I figured that out, the rest was easy.

    (defun c:deleteLF (/ a b c d e f g x) ; begin defun
    (setvar "cmdecho" 0) ; command echo
    (command "undo" "begin") ; undo begin
    (setq x (cons 3 "ACAD_LAYERFILTERS")) ; construct
    (setq a (tblobjname "LAYER" "0")) ; get a known layer
    (setq b (entget a)) ; get entity data
    (setq c (cdr (assoc 330 b))) ; get parent object (TABLE)
    (setq d (entget c)) ; get entity data
    (setq e (cdr (assoc 360 d))) ; get extension dictionary
    (setq f (entget e)) ; get entity data
    (if ; begin if
    (setq g (member x f)) ; test expression
    (entdel (cdr (assoc 360 g))) ; then expression
    (prompt "\nNo layer filters found.") ; else expression
    ) ; end if
    (command "undo" "end") ; undo end
    (princ) ; exit quietly
    ) ; end defun


     
    John Avitt, Oct 15, 2004
    #12
  13. note that sometimes the e variable needs to look at (cdr (assoc 350 d))..
    I ran into this on several drawings here and had to resort to different purging methods using DBX.
    Dotsoft Toolpack has great tools for this too, some of the best around.

    "John Avitt" <>
    |>Here is the entire code. Note that I did not have to use vla or vlax.
    |>The main problem I had was just finding where the data was stored.
    |>Once I figured that out, the rest was easy.
    |>
    |>(defun c:deleteLF (/ a b c d e f g x) ; begin defun
    |> (setvar "cmdecho" 0) ; command echo
    |> (command "undo" "begin") ; undo begin
    |> (setq x (cons 3 "ACAD_LAYERFILTERS")) ; construct
    |> (setq a (tblobjname "LAYER" "0")) ; get a known layer
    |> (setq b (entget a)) ; get entity data
    |> (setq c (cdr (assoc 330 b))) ; get parent object (TABLE)
    |> (setq d (entget c)) ; get entity data
    |> (setq e (cdr (assoc 360 d))) ; get extension dictionary
    |> (setq f (entget e)) ; get entity data
    |> (if ; begin if
    |> (setq g (member x f)) ; test expression
    |> (entdel (cdr (assoc 360 g))) ; then expression
    |> (prompt "\nNo layer filters found.") ; else expression
    |> ) ; end if
    |> (command "undo" "end") ; undo end
    |> (princ) ; exit quietly
    |>) ; end defun
    |>
    |>
    |>|>> I have found what may be a short cut.
    |>> Simply delete the ACAD_LAYERFILTERS dictionary object, as in:
    |>>
    |>> ...
    |>> (setq lay_entity (cdr (assoc 360 ldict)))
    |>> (entdel lay_entity)
    |>> ...
    |>>
    |>> Would there be any harm doing it this way?
    |>>
    |>> Thank you.
    |>>
    |>> John
    |>>
    |>>
    |>> |>> > whatever...
    |>> >
    |>> > here is the lisp:
    |>> >
    |>> > ;VISUAL LISP VERSION, TAKES LONG SOMETIMES
    |>> > (defun C:DELFILTERS-VL ( / lext-dict ldict lay_entity lay_filters
    |>> filter_names)
    |>> > (setq lext-dict
    |>> > (entget
    |>> > (vlax-vla-object->ename
    |>> > (vla-GetExtensionDictionary
    |>> > (vla-get-layers
    |>> > (vla-get-ActiveDocument
    |>> > (vlax-get-acad-object)
    |>> > )
    |>> > )
    |>> > )
    |>> > )
    |>> > )
    |>> > )
    |>> > (if (setq ldict (member (cons 3 "ACAD_LAYERFILTERS") lext-dict))
    |>> > (cdr (assoc 360 ldict))
    |>> > nil
    |>> > )
    |>> > (setq lay_entity (cdr (assoc 360 ldict)))
    |>> > (setq lay_filters (entget lay_entity))
    |>> > (while (assoc 3 lay_filters)
    |>> > (progn
    |>> > (setq filter_names (cdr (assoc 3 lay_filters)))
    |>> > (dictremove lay_entity filter_names)
    |>> > (setq lay_filters (entget lay_entity))
    |>> > )
    |>> > )
    |>> > (princ)
    |>> > )
    |>> >
    |>> >
    |>> > Rogerio_Brazil <>
    |>> > |>Try:
    |>> > |>
    |>> > |>(setq ss (ssget "x" (list (cons 8 "contorno"))))
    |>> > |>
    |>> > |>Contorno = layer name
    |>> > |>
    |>> > |>Select all entities in layer Contorno
    |>> > |>
    |>> > |>[]´s,
    |>> > |>
    |>> > |>Rogério
    |>> >
    |>> > James Maeding
    |>> > jmaeding at hunsaker dot com
    |>> > Civil Engineer/Programmer
    |>>
    |>>
    |>

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Oct 15, 2004
    #13
  14. John Avitt

    ikaage Guest

    this will work.
     
    ikaage, Oct 15, 2004
    #14
  15. yep, that one is nice

    ikaage <>
    |>this will work.

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Oct 15, 2004
    #15
  16. John Avitt

    John Avitt Guest

    Are you saying that sometimes the extension dictionary is in 350 and
    sometimes in 360? If so, do you know why?

    Thank you.

    John


     
    John Avitt, Oct 18, 2004
    #16
  17. nupe, can't say I do. I didn't look that close but I did an inspect on the item where I expected it to be 360 and it
    was 350. I forget at which level, I just know the completely activex way of doing it covers that.
    Problem is is runs super slow sometimes compared to the non-object lisp way...

    "John Avitt" <>
    |>Are you saying that sometimes the extension dictionary is in 350 and
    |>sometimes in 360? If so, do you know why?
    |>
    |>Thank you.
    |>
    |>John
    |>
    |>
    |>|>> note that sometimes the e variable needs to look at (cdr (assoc 350 d))..
    |>> I ran into this on several drawings here and had to resort to different
    |>purging methods using DBX.
    |>> Dotsoft Toolpack has great tools for this too, some of the best around.
    |>>
    |>> "John Avitt" <>
    |>> |>Here is the entire code. Note that I did not have to use vla or vlax.
    |>> |>The main problem I had was just finding where the data was stored.
    |>> |>Once I figured that out, the rest was easy.
    |>> |>
    |>> |>(defun c:deleteLF (/ a b c d e f g x) ; begin defun
    |>> |> (setvar "cmdecho" 0) ; command echo
    |>> |> (command "undo" "begin") ; undo begin
    |>> |> (setq x (cons 3 "ACAD_LAYERFILTERS")) ; construct
    |>> |> (setq a (tblobjname "LAYER" "0")) ; get a known layer
    |>> |> (setq b (entget a)) ; get entity data
    |>> |> (setq c (cdr (assoc 330 b))) ; get parent object
    |>(TABLE)
    |>> |> (setq d (entget c)) ; get entity data
    |>> |> (setq e (cdr (assoc 360 d))) ; get extension
    |>dictionary
    |>> |> (setq f (entget e)) ; get entity data
    |>> |> (if ; begin if
    |>> |> (setq g (member x f)) ; test expression
    |>> |> (entdel (cdr (assoc 360 g))) ; then expression
    |>> |> (prompt "\nNo layer filters found.") ; else expression
    |>> |> ) ; end if
    |>> |> (command "undo" "end") ; undo end
    |>> |> (princ) ; exit quietly
    |>> |>) ; end defun
    |>> |>
    |>> |>
    |>> |>|>> |>> I have found what may be a short cut.
    |>> |>> Simply delete the ACAD_LAYERFILTERS dictionary object, as in:
    |>> |>>
    |>> |>> ...
    |>> |>> (setq lay_entity (cdr (assoc 360 ldict)))
    |>> |>> (entdel lay_entity)
    |>> |>> ...
    |>> |>>
    |>> |>> Would there be any harm doing it this way?
    |>> |>>
    |>> |>> Thank you.
    |>> |>>
    |>> |>> John
    |>> |>>
    |>> |>>
    |>> |>> |>> |>> > whatever...
    |>> |>> >
    |>> |>> > here is the lisp:
    |>> |>> >
    |>> |>> > ;VISUAL LISP VERSION, TAKES LONG SOMETIMES
    |>> |>> > (defun C:DELFILTERS-VL ( / lext-dict ldict lay_entity lay_filters
    |>> |>> filter_names)
    |>> |>> > (setq lext-dict
    |>> |>> > (entget
    |>> |>> > (vlax-vla-object->ename
    |>> |>> > (vla-GetExtensionDictionary
    |>> |>> > (vla-get-layers
    |>> |>> > (vla-get-ActiveDocument
    |>> |>> > (vlax-get-acad-object)
    |>> |>> > )
    |>> |>> > )
    |>> |>> > )
    |>> |>> > )
    |>> |>> > )
    |>> |>> > )
    |>> |>> > (if (setq ldict (member (cons 3 "ACAD_LAYERFILTERS") lext-dict))
    |>> |>> > (cdr (assoc 360 ldict))
    |>> |>> > nil
    |>> |>> > )
    |>> |>> > (setq lay_entity (cdr (assoc 360 ldict)))
    |>> |>> > (setq lay_filters (entget lay_entity))
    |>> |>> > (while (assoc 3 lay_filters)
    |>> |>> > (progn
    |>> |>> > (setq filter_names (cdr (assoc 3 lay_filters)))
    |>> |>> > (dictremove lay_entity filter_names)
    |>> |>> > (setq lay_filters (entget lay_entity))
    |>> |>> > )
    |>> |>> > )
    |>> |>> > (princ)
    |>> |>> > )
    |>> |>> >
    |>> |>> >
    |>> |>> > Rogerio_Brazil <>
    |>> |>> > |>Try:
    |>> |>> > |>
    |>> |>> > |>(setq ss (ssget "x" (list (cons 8 "contorno"))))
    |>> |>> > |>
    |>> |>> > |>Contorno = layer name
    |>> |>> > |>
    |>> |>> > |>Select all entities in layer Contorno
    |>> |>> > |>
    |>> |>> > |>[]´s,
    |>> |>> > |>
    |>> |>> > |>Rogério
    |>> |>> >
    |>> |>> > James Maeding
    |>> |>> > jmaeding at hunsaker dot com
    |>> |>> > Civil Engineer/Programmer
    |>> |>>
    |>> |>>
    |>> |>
    |>>
    |>> James Maeding
    |>> jmaeding at hunsaker dot com
    |>> Civil Engineer/Programmer
    |>

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Oct 18, 2004
    #17
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.