Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Attribute block switching routine

  1. #1
    Active Member
    Join Date
    2015-11
    Posts
    86
    Login to Give a bone
    0

    Default Attribute block switching routine

    I have come across a situation at work that requires one attribute block to be switched out for another one. I need to write a routine that will take all of the attribute information in one block and insert it into the other. Both blocks are identical except that one of the attributes is hidden. I have found a simple DXF routine that shows all of the attributes of an object, but it won't show the data for the block.

    I would really appreciate any thoughts or comments. Thanks.

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Attribute block switching routine

    Are you wanting to replace the block with the same location?
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    Active Member
    Join Date
    2015-11
    Posts
    86
    Login to Give a bone
    0

    Default Re: Attribute block switching routine

    The blocks position will not change. It needs to stay where the original block is positioned.

  4. #4
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Attribute block switching routine

    How about just hiding the attributes.
    Attached Files Attached Files

  5. #5
    Active Member
    Join Date
    2015-11
    Posts
    86
    Login to Give a bone
    0

    Default Re: Attribute block switching routine

    The blocks in the drawing are inserted via a lisp routine taking the attribute data from an Excel spreadsheet. There is a column in that spreadsheet that tells the lisp routine which block, either A or B to insert. Both blocks are the same, except that Block B has an attribute that block A doesn't. In order to remain compatible with the spreadsheet, the block_type column must reflect that it is to use block B now instead of A. Otherwise, there will be confusion when someone else exports and re-imports the data because of the wrong block definition. That's why I have to pull the information from block A and reinsert it into block B.

    Single block imports and exports can be done, but they are time consuming and prone to errors. This method would reduce the number of errors and simplify the changing of blocks in a drawing.

  6. #6
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: Attribute block switching routine

    Maybe something like this?

    Code:
    ;;=======================[ ArrtMatch.lsp ]======================= 
    ;;; Author: Copyright© 2006 Charles Alan Butler 
    ;;; Version:  1.1 Mar. 27, 2006
    ;;; Purpose: To update attributes in a block, from a selected
    ;;;          doner block
    ;;; Requirements: -None 
    ;;; Returns: -None
    ;;;==============================================================
    ;;
    (defun c:attrmatch (/ ss obj att attr_list parent)
    
      (defun get_attr_lst (blk / lst)
        (foreach att (vlax-invoke blk 'getattributes)
          (setq lst (cons (cons (vla-get-tagstring att) (vla-get-textstring att)) lst))
        )
      )
    
      (or *doc* (setq *doc* (vla-get-activedocument (vlax-get-acad-object))))
      (prompt "\nSelect a block to copy attributes from.")
      (if (setq ss (ssget "+.:E:S" '((0 . "INSERT") (66 . 1))))
        (progn
          (vla-startundomark *doc*)
          (setq parent (vlax-ename->vla-object (ssname ss 0)))
          (vla-highlight parent :vlax-true)
          (setq attr_list (get_attr_lst parent))
          (while
            (progn (prompt "\nSelect a block to copy attributes from.")
                   (setq ss (ssget "+.:E:S" '((0 . "INSERT") (66 . 1))))
            )
             ;;  update matching attributes
             (setq obj (vlax-ename->vla-object (ssname ss 0)))
             (foreach att (vlax-invoke obj 'getattributes)
               (if (assoc (setq tag (vla-get-tagstring att)) attr_list)
                 (vla-put-textstring att (cdr (assoc tag attr_list)))
               )
             )
          )
        (vla-highlight parent :vlax-false)
        (vla-endundomark *doc*)
        )
      )
      (princ)
    
    )
    (prompt "\nAttribute Match Loaded, Enter AttrMatch to run.")
    (princ)

  7. #7
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Attribute block switching routine

    OK try this one. It will replace multiple blocks and transfer identical tagged attributes between then. It will have problems if you have multiple attributes with the same tag, just like a database would.

    It should do what you want.
    Attached Files Attached Files

  8. #8
    Active Member
    Join Date
    2015-11
    Posts
    86
    Login to Give a bone
    0

    Default Re: Attribute block switching routine

    Thanks for submitting that block of code. That does the trick nicely.

  9. #9
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Attribute block switching routine

    Your welcome

  10. #10
    Active Member
    Join Date
    2015-11
    Posts
    86
    Login to Give a bone
    0

    Default Re: Attribute block switching routine

    Thanks to you as well CAB2k. Your solution also solved the problem.

Page 1 of 2 12 LastLast

Similar Threads

  1. Set file name from block attribute with lisp routine
    By email.dnewton396831 in forum AutoLISP
    Replies: 0
    Last Post: 2013-07-03, 08:51 PM
  2. Replies: 13
    Last Post: 2012-09-18, 07:51 PM
  3. Copy previous Block Attribute Value to next Block Attribute
    By CADfunk MC in forum VBA/COM Interop
    Replies: 8
    Last Post: 2009-02-27, 09:46 PM
  4. Replies: 2
    Last Post: 2007-05-11, 11:25 AM
  5. Replies: 9
    Last Post: 2006-07-11, 11:09 PM

Posting Permissions

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