selecting single block out of several

Discussion in 'AutoCAD' started by Stewart, Nov 30, 2004.

  1. Stewart

    Stewart Guest

    Ok I am well past any "real" lisp knowledge that I have but I have been able
    to get it to do almost what I want with the exception that currently I need
    a different block name for each line of my bill of material instead of being
    able to only update the block I pick, not the last instance of it in the
    database I realize that down towards the bottom where the (ssget "x"... is
    where my problem is but I am overlooking something probably fairly obvious
    but when I try to filter with either the -1 name or the 5 flag then it does
    not work anymore. Here is the code for the whole lisp. basically what
    happens is when you either copy or insert from the in house menu it is
    supposed to force you to update the BOM afterwards to keep it accurate but I
    do not want to have 10 instance of graphically the same block with different
    names if possible.

    Start code

    (defun c:bomdata ( / p1 b a n)


    (setq old_blk "")
    (initget 1)
    (setq old_blk_sel(entget (entlast)))
    ;;(setq old_blk(entget (car old_blk_sel)))
    (setq old_blk(cdr(assoc 2 old_blk_sel)))
    (setq old_blk(cdr(assoc 2 old_blk_sel)))

    (setq d old_blk)

    (setq b (cons 2 d))
    ;construct a dotted pair - code 2 is for blocks

    (setq a (ssget "X" (list b)))
    ;filter for the block name

    (setq n (sslength a))
    ;count the number of blocks

    (setq blk_lst "")
    (initget 1)
    (setq blk_lst_sel(entsel "\nSelect Bill of Material Line: "))
    (setq blk_lst1(entget (car blk_lst_sel)))
    (setq blk_lst2(cdr(assoc 2 blk_lst1)))

    (setq block_lst (list blk_lst2))


    ;;THIS IS WHERE YOU WOULD PUT THE ATTRIBUTE TAG NAMES THAT YOU WOULD WANT
    TO MODIFY
    ;;IF THE HAVE A SEMICOLON IN FRONT OF THE LINE IT WON'T BE MODIFIED
    ;;IF YOU WANT TO DELETE TEXT ALREADY IN THE ATTRIB PUT NOTHING BETWEEN THE
    QUOTES
    ;;ATTRIBS
    (setq rev_lst
    (list
    (cons "QUANTITY" (itoa n))
    )
    )

    ;;
    ;;CREATE LIST OF ATTRIBUTES AND VALUES
    ;;
    (defun get_attribs (tb_name / ATTRIB_LIST ATT_CAR ATT_CDR ENT_LST TBLOCK
    TBLOCK_ENT)

    ;;Here is where I believe the trouble is

    (setq tblock (ssget "x" (list (cons 0 "INSERT") (cons 2 tb_name))))


    (cond ((/= nil tblock)
    (setq tblock_ent (entnext (ssname tblock 0)))
    (setq ent_lst (entget tblock_ent))
    (while (and (/= nil tblock_ent)(/= "SEQEND" (cdr(assoc 0
    ent_lst))))
    (cond ((= "ATTRIB" (cdr (assoc 0 ent_lst)))
    (setq att_tag (cdr (assoc 2 ent_lst)))
    (if (= nil attrib_list)
    (setq attrib_list (list (cons att_tag ent_lst)))
    (setq attrib_list (append attrib_list (list (cons
    att_tag ent_lst))))
    )
    )
    )
    (setq tblock_ent(entnext tblock_ent))
    (setq ent_lst(entget tblock_ent))
    )
    )
    )
    attrib_list
    )


    ;;
    ;;GET AFTER IT
    ;;
    (foreach memb1 block_lst
    (setq attrib_list (get_attribs memb1))
    (foreach memb2 attrib_list
    (setq att_val (assoc (car memb2) rev_lst))
    (cond ((/= nil att_val)
    (setq ent_lst (cdr memb2))
    (setq value(cdr att_val))

    (setq ent_lst (subst (cons 1 value) (assoc 1 ent_lst) ent_lst))
    (entmod ent_lst)
    )
    )
    )
    )
    (command "REGEN")
    )


    End code
     
    Stewart, Nov 30, 2004
    #1
  2. Stewart

    ECCAD Guest

    Trouble may be in:
    (setq tblock_ent (entnext (ssname tblock 0)))
    Looks like you are getting the 'same' entity,
    with (ssname tblock 0), try a counter, and foreach
    entity in the selection set (tblock), get that particular
    entity.
    i.e.
    (setq c 0)
    (setq sslen (sslength tblock))
    (repeat sslen
    (setq tblock_ent (entnext (ssname tblock c)))
    .............
    (setq c (+ c 1))
    ); repeat

    Bob
     
    ECCAD, Nov 30, 2004
    #2
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.