Results 1 to 9 of 9

Thread: Get Block Attribute Value, Get Block Location, place Selection Set into another block

  1. #1
    Member
    Join Date
    2014-10
    Posts
    14
    Login to Give a bone
    0

    Post Get Block Attribute Value, Get Block Location, place Selection Set into another block

    Hello AUGI Users –

    I am looking for some help to create a lisp program to grab specific attributed blocks and block position based on ‘Y’ location in a drawing. The attributed information in the selection group for each block would then be placed into another attributed block with headers organized by each block type. The insertion into this block would be by the ‘Y’ location of each block type starting from the bottom of the page to the top.

    The number of each block type can vary from 0 to 12. Anything less than 12 the remaining areas would be left blank. I would also need a way to update the attributed block should block quantities change in the drawing.

    I have attached a sample drawing with block and attribute tag information.


    Thank you in advanced for your help with this.
    Attached Files Attached Files

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

    Default Re: Get Block Attribute Value, Get Block Location, place Selection Set into another block

    Your dwg is a bit too simple, is it meant to be multiple lines ? You need to show more filled in and possibly draw a line from one block to where you want the answer saved.

  3. #3
    Member
    Join Date
    2014-10
    Posts
    14
    Login to Give a bone
    0

    Default Re: Get Block Attribute Value, Get Block Location, place Selection Set into another block

    BIG-AL -

    Thank you for your reply.

    I have updated the drawing to indicate where each block type should go. The yellow table mimics a Excel document used by our company. This table will only be one row.
    Attached Files Attached Files

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

    Default Re: Get Block Attribute Value, Get Block Location, place Selection Set into another block

    Try this

    Code:
    ; Pick blocks get attributes and put in another block
    ; By Alan H Nov 2018
    ; hard coded to suit 
    
    (defun getblk-putblk ( / ss x y k blk lstlst2 att att1 att2)
    (defun do-att (y  attt / k) 
    (setq k 0)
    (foreach att (vlax-invoke (vlax-ename->vla-object (car blk)) 'getattributes)
    (if (= k y) (vla-put-textstring att attt))
    (setq k (+ k 1))
    )
    )
    
    
    (setq blk (entsel "Pick detail block"))
    (alert "Select all blocks for this section \n\npick nothing to leave blank\n\n expects 4 selections")
    (setq L 0)
    (setq lst3 '(1 13 25 37))
    (repeat 4
    (setq N (nth L lst3))
    (if  (/= (setq ss (ssget (list (cons 0 "insert")))) nil)
    (progn
    (setq lst '())
    (repeat (setq x (sslength ss))
    (setq lst2 '())
    (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS (setq x (- X 1)))) 'getattributes)
    (setq lst2 (cons (cadr (vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint att)))) lst2))
    (setq lst2 (cons (vla-get-textstring att) lst2))
    )
    (setq lst (reverse lst))
    (setq lst (cons lst2 lst))     
    )
    (setq lst (vl-sort lst
    '(lambda (x y) 
    (cond
    ((= (cadr x)(cadr y))
    (< (car x)(car y)))
    ((< (cadr x)(cadr y)))
    )
    )
    )
    )
    (setq lst (reverse lst))
    (repeat (setq x (length lst))
    (setq att(nth (setq x (- x 1)) lst))
    (setq att2 (caddr att))
    (do-att N att2)
    (setq N (+ N 1))
    )
    )) ; end while ?
    (setq L (+ L 1))
    )
    (do-att 0 (nth 0 lst2))
    )
    (getblk-putblk)
    Last edited by BIG-AL; 2018-11-16 at 06:27 AM.

  5. #5
    Member
    Join Date
    2014-10
    Posts
    14
    Login to Give a bone
    0

    Default Re: Get Block Attribute Value, Get Block Location, place Selection Set into another block

    BIG AL -

    Thank you for your efforts on this. It is greatly appreciated. I ran some testing on the code you supplied this evening and below is some of what I found.

    The detail block is populating with all the blocks that are select and is populating the correct areas.

    ** The selected items are populating by the data in the attribute in reverse order. Not in the order by the 'Y' coordinate starting from the bottom of the page to the top.
    ** Also if the data in the attributes don't all start with BP, GL, GA, PN it does not place the attribute data of that block in the detail block. The attribute starting value does not always start the same way. The only constants for each type are the block name, attribute name and attribute name in the detail block. These are listed below:

    Glass Block Name = Part_Glassmk
    Attribute Tag = Glass_Tag
    Detail Block = GL_Tag

    Gasket Block Name = Part_Gasketmk
    Attribute Tag = Gasket_Tag
    Detail Block = GA_Tag

    Panel Block Name = Part_Panelmk
    Attribute Tag = Panel_Tag
    Detail Block = PA_Tag

    Please reach out should you need any further information or clarification.

    Thanks,

    Roger

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

    Default Re: Get Block Attribute Value, Get Block Location, place Selection Set into another block

    I knew about the y bit and it can be added, if your happy just picking a group irrespective of block name and get 1st attribute then it can be done its actually easier this way, I just went for the pick all option. The block has like 4 groups so if a group does not exist just select nothing I can check for nothing picked and go on to next group.

  7. #7
    Member
    Join Date
    2014-10
    Posts
    14
    Login to Give a bone
    0

    Default Re: Get Block Attribute Value, Get Block Location, place Selection Set into another block

    Could it be done with a selection set for each of the four blocks types? That way the end user does not have to select each block type. If a block type is not there is just leaves that part of the detail block empty. The less I have to relay on the end user to select everything the better.

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

    Default Re: Get Block Attribute Value, Get Block Location, place Selection Set into another block

    That is what I was suggesting just do 4 simple window picks and the details will fill in correctly. I have a little window of time now so will see if I can change what I did previously.

    Try the code again I changed it.
    Last edited by BIG-AL; 2018-11-16 at 06:28 AM.

  9. #9
    Member
    Join Date
    2014-10
    Posts
    14
    Login to Give a bone
    0

    Default Re: Get Block Attribute Value, Get Block Location, place Selection Set into another block

    I tested the code and the data is populating correctly by selection and elevation.

    Would it be possible to have the program do all the selections so I don't have to relay on the end-user to make the sections? As I think about the program there is a variable forgot to mention. Not all drawings will have all block which means with the user selection the data would not go into the correct areas of the detail block. If the program could link the block name(s) to the attribute tag in the detail block I believe that would eliminate user error and insure proper placement in the detail block. Example below:

    Glass Block Name = Part_Glassmk
    Glass Block Attribute Tag = Glass_Tag
    Detail Block Attribute Tag = GL_Tag

    This would need to happen for the 4 different types of blocks.

Similar Threads

  1. How to change dynamic block attribute default values based on block selected?
    By zeirz109180 in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2013-12-13, 02:20 PM
  2. Block Attribute Table Values Dont' Appear in Block
    By stusic in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2011-12-27, 02:58 PM
  3. Block with Attribute Location
    By ronsarlo in forum AutoCAD General
    Replies: 7
    Last Post: 2009-04-27, 08:31 PM
  4. Change the block source file location in tool palette block?
    By Cadphreak in forum AutoCAD Customization
    Replies: 7
    Last Post: 2007-03-09, 03:18 PM
  5. Block attribute text size is incorrect when the Block is not selected
    By lwhitney.133796 in forum AutoCAD General
    Replies: 3
    Last Post: 2007-02-16, 10:01 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
  •