Search 4 blocks in layouts

Discussion in 'AutoCAD' started by Mark, May 4, 2004.

  1. Mark

    Mark Guest

    I know how to search for a block residing within a drawing using functions
    such as "ssget" and "tblsearch" but how do you search for a block that
    is placed in a layout. Im wanting to search for a block in a drawing and to
    tell me
    which layout tab it is residing in. My code searches for the block in the
    drawing and
    if it doesnt find it, do nothing. If it does find it, let me know which
    layout(s) its on
    and do something.
    I have drawings with multiple named layouts and i know the block is in
    either one or several
    of the layouts contained within the drawings because i inserted the block
    there.
    If someone could give me starter for ten and point me in right direction it
    would be appreciated because
    its got me stumped.

    Ta
    Mark
     
    Mark, May 4, 2004
    #1
  2. Include the 410 code with the ssget filter

    (ssget "x" '((0 . "INSERT") (2 . "BlockName") (410 . "LayoutName")))


    --
    Autodesk Discussion Group Facilitator


    <snip>
     
    Jason Piercey, May 4, 2004
    #2
  3. Mark

    PG. Guest

    (defun test (/ ss slen cnt elst)
    (setq ss (ssget "_x" '((0 . "INSERT"))))
    (setq slen (if ls
    (sslength ls)
    nil
    )
    cnt 0
    )
    (while (< cnt slen)
    (setq elst (entget (ssname ls cnt)))
    (foreach it (list
    "\nBlock: "
    (cdr (assoc 2 elst))
    " is in "
    (cdr (assoc 410 elst))

    )
    (princ it)
    )
    (setq cnt (1+ cnt))
    )
    )
     
    PG., May 5, 2004
    #3
  4. Mark

    Jeff Mishler Guest

    Mark,
    While Jason's will allow you to select the block inserts on specific
    layouts, this will get ALL of the inserts with that name and return a list
    with the layout name as a member of the list for each insert found.
    For instance, if the block "TEST" is inserted in "layout1" twice, "layout2"
    once, "layout3" none, and "layout4" twice the var "blklist" would look like
    this: ("layout1" "layout1" "layout2" "layout4" "layout4"), although the
    order may be different based on the creation order of the inserts.

    HTH,
    Jeff

    (setq ss (ssget "x" '((0 . "INSERT")(2 . "YOURBLOCKNAME")))
    count 0)
    (if ss
    (progn
    (repeat (sslength ss)
    (setq blk (entget (ssname ss count)))
    (setq blklist (cons (cdr (assoc 410 blk)) blklist))
    (setq count (1+ count))
    )
    )
    )
     
    Jeff Mishler, May 5, 2004
    #4
  5. Mark

    PG. Guest

    Reposted the code because the last minute change of a variable introduced a
    bug. Its fixed.
    (defun test (/ ss slen cnt elst)
    (setq ss (ssget "_x" '((0 . "INSERT"))))
    (setq slen (if ss (sslength ss) nil)
    cnt 0)
    (while (< cnt slen)
    (setq elst (entget (ssname ss cnt)))
    (foreach it (list
    "\nBlock: "
    (cdr (assoc 2 elst))
    " is in "
    (cdr (assoc 410 elst)))
    (princ it)
    )
    (setq cnt (1+ cnt))
    )
    (princ)
    )
     
    PG., May 5, 2004
    #5
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.