wildcard for vla-item layers

Discussion in 'AutoCAD' started by kemp, Jun 16, 2004.

  1. kemp

    kemp Guest

    Here's the code I have:
    (vla-item *layers* layer)


    How can I add widcards to the layer *Vent and make this function?

    Thanks, kemp
     
    kemp, Jun 16, 2004
    #1
  2. One way would be to (vlax-for) your way through
    the layer collection and test each with (wcmatch).
     
    Jason Piercey, Jun 16, 2004
    #2
  3. kemp

    kemp Guest

    Will this cause a lot of overhead if have to run this 188 times? I
    supose I can test it to see.

    Thanks!
     
    kemp, Jun 16, 2004
    #3
  4. kemp

    kemp Guest

    Will this cause a lot of overhead if have to run this 188 times? I
    supose I can test it to see.

    Thanks!
     
    kemp, Jun 16, 2004
    #4
  5. Why do you need to run it 188 times? Perhaps
    there is another solution to your problem?
     
    Jason Piercey, Jun 16, 2004
    #5
  6. kemp

    kemp Guest

    I have a database with 188 layers listed in it. I am trying to set the
    layers on/off based on the database settings and this function is inside
    of a foreach statement. Maybe there is a better way to handle this but I
    am only a novice :) Take a look and tell me what you think - this is
    what I have so far, I have not added the vlax-for or wcmatch yet.

    (foreach data-list-line data-list
    (if (not (vl-catch-all-error-p
    (vl-catch-all-apply
    '(lambda ()
    (vla-item *layers* layer))
    nil)))
    (progn
    (if (= LayerFreeze "thaw")
    (vla-put-freeze (vla-item *layers* layer) :vlax-false)
    ;add more functions once this works
    )
    )
    )
    )

    Thanks for your help Jason!

    kemp
     
    kemp, Jun 16, 2004
    #6
  7. What does "data-list" look like? How is it
    formatted?
     
    Jason Piercey, Jun 16, 2004
    #7
  8. kemp

    kemp Guest

    data-list is in this format:

    (("1" "A" "B" "C" "D" "E" "F" "G" "H")
    ("2" "A" "B" "C" "D" "E" "F" "G" "H")
    ("3" "A" "B" "C" "D" "E" "F" "G" "H"))
     
    kemp, Jun 16, 2004
    #8
  9. There are that many elements for each item
    in the list?
    The frist item is the layer name? what about
    the rest of them?
     
    Jason Piercey, Jun 16, 2004
    #9
  10. kemp

    kemp Guest

    Well, I have one more value in that list than in reality. The fields
    include:

    Layer name
    Color
    Lineweight
    Plot Style
    Description
    Plot/noplot value
    Freeze/thaw
    on/off
     
    kemp, Jun 16, 2004
    #10
  11. Possibly something like this?

    (foreach item data-list
    (if
    (vl-catch-all-error-p
    (vl-catch-all-apply
    (function
    (lambda ()
    (setq name (nth 0 item))
    (setq object (vla-item *layers* name))
    )
    )
    )
    )
    (princ (strcat "\nlayer " name " doesn't exist"))
    (progn
    (vla-put-color object (nth 1 item))
    (vla-put-lineweight object (nth 2 item))
    (vla-put-plotstylename object (nth 3 item))

    ; inlcude the rest......
    )
    )
    )
     
    Jason Piercey, Jun 16, 2004
    #11
  12. kemp

    kemp Guest

    This is much cleaner code than mine, but it must also be able to allow
    for layers with varying xref names, so I have been passing the name
    varible with a wildcard (eg *A-Wall). This wildcard is my sticking point
    because it fails the vla-item test every time.

    At this point I am working on the wcmatch function with the vlax-for
    function like you suggested earlier to see how it works. Unless there is
    a better method for this also?

    Thanks!

    kemp
     
    kemp, Jun 16, 2004
    #12
  13. Guess I don't really understand. I thought the
    data-list contained all the layer names and properties
    for each layer. Not sure why you would need
    to use vlax-for or wcmatch if that is the case.

    Are you saying that the first element in each item
    within data-list is a wildcard pattern and not an
    actual layer name?
     
    Jason Piercey, Jun 16, 2004
    #13
  14. kemp

    kemp Guest

    Yes, you are correct. The name element of the array does not always have
    the exact layer name that needs to be manipulated. I wildcard the
    majority of them. The way I have this script currently working is using

    (command "._layer")
    ;;foreach code goes in here
    (command "T" name "C" color name "LT" linetype name "LW" lineweight
    layer........ )
    ;;end foreach
    (command "")

    It works with the wildcards but it's pretty slow as you can imagine when
    I do this 188 times.

    Thanks,

    kemp
     
    kemp, Jun 16, 2004
    #14
  15. Perhaps this is a more suitable solution.

    ; function to retrieve layer objects from
    ; the specified document whose names match
    ; the specified pattern.
    ; Arguments:
    ; [document] - vla-object, document object
    ; [pattern] - string, wildcard pattern
    ; return: list of vla-objects or nil
    (defun getLayerObjects (document pattern)
    (setq pattern (strcase pattern))
    (vlax-for item (vla-get-layers document)
    (if (wcmatch (vla-get-name item) pattern)
    (setq lst (cons item lst))))
    (reverse lst)
    )

    (foreach item data-list
    (setq pattern (nth 0 item))
    (if
    (setq
    objects
    (getLayerObjects
    (vla-get-activedocument
    (vlax-get-acad-object))
    pattern
    )
    )
    (foreach object objects
    (vla-put-color object (nth 1 item))
    (vla-put-lineweight object (nth 2 item))
    (vla-put-plotstylename object (nth 3 item))

    ; inlcude the rest......
    )
    )
    )

    That is it for me today, I'm outta here headed
    for a 5 day weekend :)
     
    Jason Piercey, Jun 16, 2004
    #15
  16. PS: you should/could move the (vla-get-activedocument......)
    out of the foreach loop, as you really only
    need to do that once. Not much point in
    getting the activedocument 188 times.
     
    Jason Piercey, Jun 16, 2004
    #16
  17. kemp

    kemp Guest

    Thanks a lot Jason, I'll dig into it tomorrow so I can see exactly what
    your code does (they are actually making me work now). Have a great long
    weekend!

    kemp
     
    kemp, Jun 16, 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.