Results 1 to 3 of 3

Thread: List blocks of the same name and find block insert points

  1. #1
    Member
    Join Date
    2010-04
    Posts
    2
    Login to Give a bone
    0

    Default List blocks of the same name and find block insert points

    Hi friends,

    I wanted to do a different lsp work to count blocks. But I have a problem with listing. Tell me what I want to do;

    I can count the blocks of the same name, find out how many of them are. I want to create a separate selection set for each block so that I can find the block insert point that belongs to each block. I see this insert point with dxf codes. But I have to make a selection set list. Every block counted on the list is first, second, third.

    I will write to the block insert point with the text command. So I need to create a list and find the block insert point for each block.

    Can you help me create a list for selected / counted blocks?


    My counting lisp code :

    ;; Block counting add-on for Autocad.
    ;; According to the block name, the number of blocks in the drawing is determined.
    ;; For the user, the counted block name and the number of blocks are reported.

    (defun c:blkcnt (/ blkselect entitylist blkname blkssget blkcount)



    (setq blkselect (car (entsel "\n Select Block to be counted :"))) ;; <Entity name: 7ff7b7e97b80>
    (setq entitylist (entget blkselect)) ;; Entity listed in all
    (setq blkname (cdr(assoc 2 entitylist))) ;; Block name shown

    (if blkname
    (progn
    (setq blkssget (ssget "X" (list (cons 2 blkname))))
    (if blkssget
    (setq blkcount (sslength blkssget))
    )



    (cond ( (> blkcount 1)
    (alert (strcat "\n Block name : " (strcase blkname) " from " "\n Total :" " " (itoa blkcount) " There are pieces !")) )
    ( (= blkcount 1)O
    (alert (strcat "\n Block name : " (strcase blkname) " Only 1 piece available !")))
    ( t
    (alert (strcat "\n Block name : " (strcase blkname) " No have block with this name !!! ")))
    )
    )
    )

    (princ)
    )


    Sample coding for block insertpoint :

    (setq blkselect (car (entsel "\n Select a block :"))) ;; <Entity name: 7ff7b7e97b80>
    (setq entitylist (entget blkselect)) ;; Entity listed in all
    (setq blkpoint1 (cdr (assoc 10 entitylist)) ) ;; İnsert poit ;; (115.982 59.3608 0.0)
    (setq blkname (cdr(assoc 2 entitylist))) ;; Block name


    ;; To get the insertion point of the block :
    ;; (setq blkpoint (cdr (assoc 10 entitylist)) )

    ;; To get the name of the block :
    ;; (cdr(assoc 2 entitylist))

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: List blocks of the same name and find block insert points

    Hi,

    Something like the following ?
    Code:
    (defun c:blkcnt (/ blkselect entitylist blkname blkssget blkcount dxf_lst ins_lst)
      (if (and (setq blkselect (car (entsel "\n Select Block to be counted :")))
               (setq entitylist (entget blkselect))
               (setq blkname (cdr (assoc 2 entitylist)))
               )
        (if (setq blkssget (ssget "X" (list (cons 2 blkname))))
          (progn
            (setq blkcount (sslength blkssget))
            (cond ((> blkcount 1)
                   (alert (strcat "\n Block name : " (strcase blkname) " from " "\n Total :" " " (itoa blkcount) " There are pieces !")) )
                  ((= blkcount 1)
                   (alert (strcat "\n Block name : " (strcase blkname) " Only 1 piece available !")))
                  )
            (repeat blkcount
              (setq dxf_lst (entget (ssname blkssget (setq blkcount (1- blkcount)))))
              (setq ins_lst (cons (cdr (assoc 10 dxf_lst)) ins_lst))
              )
            )
          (alert (strcat "\n Block name : " (strcase blkname) " No have block with this name !!! "))
          )
        )
      (if ins_lst ins_lst (princ))
      )

  3. #3
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    560
    Login to Give a bone
    0

    Default Re: List blocks of the same name and find block insert points

    If you get ALL blocks save name and insertion point into list. Then Vl-sort list on name, then use a simple compare of each two items in list and can make a new list of each block.

    The list would be like variable name BLK1 BLK2 etc. which can be auto created.

    Code:
    (setq num 1)
    (setq lst (list "a" "b" "c"))
    ("a" "b" "c")
    
    (setq blk (strcat "blk" (rtos num 2 0)))
    "blk1"
    
    (set (read blk) lst)
    
    (princ blk1)
    ("a" "b" "c")

Similar Threads

  1. Replies: 1
    Last Post: 2017-01-15, 12:22 AM
  2. Replies: 0
    Last Post: 2016-10-28, 05:44 PM
  3. Replies: 0
    Last Post: 2013-02-27, 05:40 PM
  4. Redefine block with same name on insert
    By Coolmo in forum Dot Net API
    Replies: 3
    Last Post: 2010-05-13, 11:36 PM
  5. Two Blocks with the same name in the same dwg !
    By costas.vassiliou in forum AutoCAD General
    Replies: 7
    Last Post: 2009-09-11, 01:46 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •