Jump to content

Listing blocks in drawing


Baber62

Recommended Posts

I have found lips routines that will list the blocks used in a drawing, show the number of blocks in a drawing, however, I need a lisp routine to list the xy coordinate of each block that has been inserted in a drawing and preferably write this both to an excel and text file.

Link to comment
Share on other sites

Quickly written & wholly untested:

(defun c:blockinfo ( / e f i s )
   (if 
       (and
           (setq s (ssget "_X" '((0 . "INSERT") (410 . "Model"))))
           (setq f (getfiled "Create CSV File" "" "csv" 1))
           (setq f (open f "w"))
       )
       (progn
           (repeat (setq i (sslength s))
               (setq e (entget (ssname s (setq i (1- i)))))
               (write-line
                   (apply 'strcat
                       (cons (LM:name->effectivename (cdr (assoc 2 e)))
                           (mapcar '(lambda ( x ) (strcat "," (rtos x)))
                               (cdr (assoc 10 e))
                           )
                       )
                   )
                   f
               )
           )
           (close f)
       )
   )
   (princ)
)

;; Block Name -> Effective Block Name  -  Lee Mac
;; blk - [str] Block name

(defun LM:name->effectivename ( blk / rep )
   (if
       (and (wcmatch blk "`**")
           (setq rep
               (cdadr
                   (assoc -3
                       (entget
                           (cdr (assoc 330 (entget (tblobjname "block" blk))))
                          '("AcDbBlockRepBTag")
                       )
                   )
               )
           )
           (setq rep (handent (cdr (assoc 1005 rep))))
       )
       (cdr (assoc 2 (entget rep)))
       blk
   )
)

(princ)

Block Name to Effective Block Name function from here.

Link to comment
Share on other sites

  • 3 months later...
Change 'csv' to 'txt' and the above code should perform as required.

 

Hi Lee Mac

i want to select block before export and i want to take out column A and D

Help me please

Link to comment
Share on other sites

Threads merged.

 

bienda, please only post the same question once.

 

But my question was not answered ������

Edited by bienda
Link to comment
Share on other sites

(defun c:blockinfo ( / e f i s )
   (if (and (setq s (ssget '((0 . "INSERT") (410 . "Model"))))
            (setq f (getfiled "Create File" "" "txt" 1))
            (setq f (open f "w"))
       )
       (progn
           (repeat (setq i (sslength s))
               (princ
                   (apply 'strcat
                       (mapcar '(lambda ( a b ) (strcat (rtos a) b))
                           (cdr (assoc 10 (entget (ssname s (setq i (1- i))))))
                          '("," "\n")
                       )
                   )
                   f
               )
           )
           (close f)
       )
   )
   (princ)
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...