call laymrg from within lisp

Discussion in 'AutoCAD' started by Casey Roberts, Oct 6, 2004.

  1. What is the correct syntax to use the express tools 'laymrg' command from
    within lisp?

    I have string variables stored with layer names to be merged as well as the
    destination layer name.


    Thanks,

    Casey
     
    Casey Roberts, Oct 6, 2004
    #1
  2. Casey Roberts

    Matt W Guest

    Have you tried (C:Laymrg)??


    --
    I support two teams: the Red Sox and whoever beats the Yankees.


    | What is the correct syntax to use the express tools 'laymrg' command from
    | within lisp?
    |
    | I have string variables stored with layer names to be merged as well as
    the
    | destination layer name.
    |
    |
    | Thanks,
    |
    | Casey
    |
    |
     
    Matt W, Oct 6, 2004
    #2
  3. Casey Roberts

    C Witt Guest

    see my reply to your first post on this..
     
    C Witt, Oct 6, 2004
    #3
  4. Well, heres the code i came up with / gleaned from other sources as noted.
    Currently, it doesn't handle layers within blocks and other objects, but it
    works for simple objects which is enough for me right now.

    If anybody has any ways to improve please feel free to comment.

    Thanks,

    Casey

    ;; (C.) 1996 by Vladimir Nesterovsky<>
    ;; USE THESE FUNCTIONS FOR ANY NON-PROFITABLE PURPOSE WHILE
    ;; KEEPING THIS NOTICE. NO WARRANTIES ARE GIVEN WHATSOEVER.


    ;; strtol convert string of chars into list of 1-char strings|;

    (defun strtol (s / lst c)
    (repeat (setq c (strlen s))
    (Setq lst (cons (substr s c 1) lst)
    c (1- c)
    )
    )
    lst
    )

    ;; helper function

    (defun strp (s) (and (= 'STR (type s)) (/= s "")))

    ;; STRTOK - break strng on char if it's in chs (char-string).
    ;; Like "C" strtok() break string to tokens delimited by one
    ;; OR MORE chars.
    ;; parse free format -- no empty tokens --
    ;; (strtok " 1,, 2, 3,")->{"1" "2" "3"}

    (defun strtok (strng chs / len c l s cnt chsl)
    (setq chsl (strtol chs))
    (setq len (strlen strng)
    s ""
    cnt (1+ len)
    )
    (while (> (setq cnt (1- cnt)) 0)
    (setq c (substr strng cnt 1))
    (if (member c chsl)
    (if (strp s)
    (setq l (cons s l)
    s ""
    )
    )
    (setq s (strcat c s))
    )
    )
    (if (strp s)
    (cons s l)
    l
    )
    )


    (defun strf (s field) (vpn_printf "%.*s" field s))



    ;Casey's Programming starts here
    ;October 5 2004


    (defun c:mergelay ()
    (TBLNEXT "LAYER" T)
    (SETQ LAYERLIST NIL)
    (SETQ LEN 0)
    (WHILE (TBLNEXT "LAYER") (SETQ LEN (+ 1 LEN)))
    (TBLNEXT "LAYER" T)
    (REPEAT LEN
    (SETQ L1 (CDR (aSSOC 2 (TBLNEXT "LAYER"))))
    (SETQ L1 (LIST L1))
    (SETQ LAYERLIST (APPEND LAYERLIST L1))
    )
    (setq badlist nil)

    (foreach layname layerlist
    (if (wcmatch layname "*$0$*")
    (progn
    (setq badlist (append badlist (list layname)))
    )
    ) ;end if


    ) ;foreach

    (foreach oldname badlist
    (setq newname (cadr (strtok oldname "*$0$*")))
    (setq ss1 (ssget "x" (list (cons 8 oldname))))

    (if (not (tblsearch "layer" newname))
    (command "layer" "new" newname "")
    ) ;check if new name already exists, if not, create it

    (setq olay (getvar "clayer"))
    (setvar "clayer" "0")
    (if ss1
    (command "chprop" ss1 "" "la" newname "")
    )
    (command "purge" "la" oldname "n")
    (setvar "clayer" olay)
    ) ;end foreach

    ) ;defun
     
    Casey Roberts, Oct 6, 2004
    #4
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.