how can i get block names?

Discussion in 'AutoCAD' started by raffi, May 23, 2004.

  1. raffi

    raffi Guest

    Hi
    please someone tell me how can i get the inserted block names in a
    drawing?
     
    raffi, May 23, 2004
    #1
  2. raffi

    kendresen Guest

    (defun c:blkname ()
    (setq obj (car (entsel "\nPick Block...")))
    (setq bname (cdr (assoc 2 (entget obj))))
    )

    That will allow the user to pick a block to return a name

    (defun c:allblocks ()
    (setq objgroup (ssget "x" '((0 . "INSERT"))))
    (setq count 0)
    (repeat (sslength objgroup)
    (setq obj (ssname objgroup count))
    (setq bname (cdr (assoc 2 (entget obj))))

    <Here is where you do whatever you what to do to each block>

    (setq count (+ 1 count))
    );end while
    );end defun

    note: this will also select xrefs, if you don't want them there is a group code you can use to filter them out but I don't remember what it is...
     
    kendresen, May 23, 2004
    #2
  3. raffi

    raffi Guest

    thanks
    but this routines count all blocks maybe we have several copy
    of a block you now I just need the used block name in a drawing
     
    raffi, May 23, 2004
    #3
  4. raffi

    bob.at Guest

    expanding the code from kendresen you can do the following:

    (defun c:allusedblocks ()
    (setq objgroup (ssget "x" '((0 . "INSERT"))))
    (setq count 0 bllist nil)
    (repeat (sslength objgroup)
    (setq obj (ssname objgroup count))
    (setq bname (cdr (assoc 2 (entget obj))))
    (if (not (member bname bllist))
    (setq bllist (cons bname bllist))
    )
    (setq count (+ 1 count))
    );end while
    bllist
    );end defun

    bob.at
     
    bob.at, May 23, 2004
    #4
  5. raffi

    raffi Guest

    Thanks for the help everyone.
     
    raffi, May 23, 2004
    #5
  6. raffi

    Jim Claypool Guest

    (this will list all blocks defined in the drawing, whether they are used or
    not.

    (defun blkList (/ data name tmp rtn)
    (while (setq data (tblnext "block" (null data)))
    (setq name (cdr (assoc 2 data)))
    (if (not (= 4 (logand 4 (cdr (assoc 70 data)))))
    (setq rtn (cons name rtn))
    )
    )
    (reverse rtn)
    )
     
    Jim Claypool, May 24, 2004
    #6
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.