trouble freezing layers with activex

Discussion in 'AutoCAD' started by Nathan Withers, Aug 19, 2004.

  1. Don't have time to mess with this all day. I'm trying to freeze all layers
    (except the active layer). Using the code below, my routine reports that
    none of the layers can be frozen. What am I missing.

    (setq $acad (vlax-get-acad-object)) ;get acad object
    (setq $doc (vla-get-activedocument $acad)) ;get active document object
    (setq $laytbl (vla-get-layers $doc)) ;get layers collection
    (vlax-for item $laytbl ;for each item in the layers collection
    (progn
    ...
    (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-freeze '(item
    :vlax-true)))
    (princ (strcat "\nCan't freeze layer " (vla-get-name item)))
    );end if
    ...
    );end progn
    );end vlax-for
     
    Nathan Withers, Aug 19, 2004
    #1
  2. Yes. I realize that. But I am trying to improve upon routines that someone
    else wrote using that method. Using "command" in a lisp is not true lisp...
    it is scripting. All things being equal VLisp routines will typically
    execute faster than vanilla lisp or scripts too.

     
    Nathan Withers, Aug 19, 2004
    #2
  3. Not in THAT much of a rush. What I meant was that I don't have the time to
    make it work right now, because of other commitments. But I would like to
    get it working without resorting to using "command". I try to stay away
    from using that whenever possible. See my reply Kent C. for more info.
     
    Nathan Withers, Aug 19, 2004
    #3
  4. Before anybody else replies with "try this other method", and without
    stepping on the toes of those that already ahve suggested it:

    I am trying to make this work using ony vlisp. I'm trying to speed up and
    improve upon code already written by another individual. I don't care if it
    is more complex to code using vlisp. It will run much faster than scripting
    with the layer command, or plain vanilla lisp.

    I'm a bit of a purist: once I start a routine with a language, or
    programming style, I don't like to jump to another mid-routine.
     
    Nathan Withers, Aug 19, 2004
    #4
  5. Nathan Withers

    Jeff Mishler Guest

    Well, you need to remember that passing a list with the quote, ala '(item
    :vlax-true), causes lisp to interpret each symbol literally. Try changing
    that to (list item :vlax-true)

    HTH,
     
    Jeff Mishler, Aug 19, 2004
    #5
  6. Nathan Withers

    Jeff Mishler Guest

    Since I once believed this, you may want to read the entire thread at:
    http://theswamp.org/phpBB2/viewtopic.php?t=1449

    It was a real eye opener for me.......

    Jeff
     
    Jeff Mishler, Aug 19, 2004
    #6
  7. Nathan Withers

    T.Willey Guest

    or another option is

    (vlax-for item $laytbl ;for each item in the layers collection
    (if (= (getvar "clayer") (vla-get-name item))
    (princ (strcat "\nCan't freeze layer " (vla-get-name item)))
    (putx item 'Freeze -1)
    );end if
    );end vlax-for

    Tim
     
    T.Willey, Aug 19, 2004
    #7
  8. Excellent! That worked. Wasn't think about the quote being the problem.

    It's funny that you suggested that just as I found this method that also
    works.

    (if (/= (vla-get-name item) (getvar "clayer"))
    (vla-put-freeze item :vlax-true)
    )

    That reminds me... is there a way to find the current (active) layer using
    activex? Doesn't seem to be a method or propety in the layers collection
    for that.
     
    Nathan Withers, Aug 19, 2004
    #8
  9. Nathan Withers

    Jeff Mishler Guest

    (vla-get-name (vla-get-activelayer $doc))
     
    Jeff Mishler, Aug 19, 2004
    #9
  10. Nathan Withers

    John Uhden Guest

    Your problem is simple... you quoted the list so that item is not evaluated.
    Construct the list instead.
    (vl-catch-all-apply 'vla-put-freeze (list item :vlax-true))

    But you shouldn't need to catch any items.
    Presuming your $doc is global...
    (setq ActiveLayer (vlax-get $doc 'ActiveLayer))
    (vlax-for Layer (vlax-get $doc 'Layers)
    (or
    (equal Layer ActiveLayer)
    (vlax-put Layer 'Freeze -1)
    )
    )
     
    John Uhden, Aug 20, 2004
    #10
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.