tblsearch and wcmatch

Discussion in 'AutoCAD' started by amjarch, Sep 27, 2004.

  1. amjarch

    amjarch Guest

    I have searched this forum and tried to get this little combo to work but i must be missing som thing. I need to essentially tblsearch the layer list for a certain layer name or any variant (ie "s-gd-iden" or any thing like" i-gd-iden-096") and do certain things if anything is there or not. I am sure this must sound familiar. Here is the total code, where am I messing up? The commented out stuff in the middle is how I used to do it. I am trying to accommodate modified layers in a drawing that requires multiple scales.

    ;------------------------
    ; INSERT grid bubble
    ;------------------------
    (defun c:gbub (/ dim_scl ortho_mode c_layer os_mode blk1 ang0 ang pt1)
    (setq dim_scl (getvar "dimscale")
    ortho_mode (getvar "orthomode")
    c_layer (getvar "clayer")
    os_mode (getvar "osmode")
    tbls (tblsearch "layer" "S-D-IEDN")
    test (wcmatch (cdr (assoc 2 tbls)) "s-gd-iden*, S-GD-IDEN*")
    )
    (if (= test nil) (command "layer" "m" "S-GD-IDEN" "c" "31" "" "") (setq layname (cdr (assoc 2 tbls)))
    )
    (if (= test t) (command "layer" "s" layname "")
    )
    ;(if (not (tblsearch "layer" "S-GD-IEDN"))
    ;(command "layer" "m" "S-GD-IDEN" "c" "31" "" "")
    ;(command "layer" "s" "S-GD-IDEN" "")
    ;)
    (setvar "cmdecho" 0)
    (setvar "osmode" 1)
    (setvar "orthomode" 1)
    (setq pt1 (getpoint "\nInsertion Point:"))
    (setvar "osmode" 0)
    (setq ang0 (getangle pt1 "\nDirection:"))
    (setq ang (angtos ang0))
    (setq ang1 (fix ang0))
    (print)
    (setq blk1 (cond ((= ang1 4)(strcat kpath "tags/T09 gridv2.dwg"))
    ((= ang1 1)(strcat kpath "tags/gridv1.dwg"))
    ((= ang1 0)(strcat kpath "tags/gridh1.dwg"))
    ((= ang1 3)(strcat kpath "tags/gridh2.dwg"))
    )
    )
    (command "insert" blk1 pt1 dim_scl "" "")
    (setvar "orthomode" ortho_mode)
    (setvar "clayer" c_layer)
    (setvar "osmode" os_mode)
    (princ)
    )

    Thanks a ton,
    Drew
     
    amjarch, Sep 27, 2004
    #1
  2. amjarch

    Paul Turvill Guest

    As you discovered, you can't use (tblsearch ...) because it doesn't accept
    wildcards; it requires the exact name of a layer to be found.

    As for your "test" variable, try:

    (setq test (wcmatch (strcase (cdr (assoc 2 tbls))) "S-GD-IDEN*"))

    Also, the "M" option to the LAYER command will switch to the layer in
    question if it exists, is thawed and on; and it will *create* the layer if
    it does not exist. No (if ...) statement is needed.
    ___


    i must be missing som thing. I need to essentially tblsearch the layer list
    for a certain layer name or any variant (ie "s-gd-iden" or any thing like"
    i-gd-iden-096") and do certain things if anything is there or not. I am
    sure this must sound familiar. Here is the total code, where am I messing
    up? The commented out stuff in the middle is how I used to do it. I am
    trying to accommodate modified layers in a drawing that requires multiple
    scales.
    <snip>
     
    Paul Turvill, Sep 27, 2004
    #2
  3. amjarch

    Walt Engle Guest


    Add the following two lines to your routine:

    (if (not (tblsearch "layer" "S-GD-IEDN"))
    (command "layer" "M" "S-GD-IEDN" "c" "red" "S-GD-IEDN" "L" "continuous"
    "S-GD-IEDN" ""))

    Then you can change the color, the linetype, etc to what you want.
     
    Walt Engle, Sep 27, 2004
    #3
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.