Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: LISP routine to grab an attribute value from a block (which varies)

  1. #11
    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: LISP routine to grab an attribute value from a block (which varies)

    The problem I have is that the title block name varies (these are typically renamed from job to job) but the attribute tag is always the same, so hence I’d like it to work for all title block names.
    It is really inefficient to select all blocks in a drawing to find one that has a REVISION attribute tag.

    DO you have a list of TITLEBLOCK names or do the names match a wildcard string like "*TITLE*" ?

    P=
    AutomateCAD

  2. #12
    Member
    Join Date
    2017-06
    Posts
    6
    Login to Give a bone
    0

    Default Re: LISP routine to grab an attribute value from a block (which varies)

    Quote Originally Posted by peter View Post
    It is really inefficient to select all blocks in a drawing to find one that has a REVISION attribute tag.

    DO you have a list of TITLEBLOCK names or do the names match a wildcard string like "*TITLE*" ?

    P=
    I don’t think it’s necessary to select every block in a drawing, so inefficiency shouldn’t be an issue.

    There are typically only a limited number of blocks in paperspace, and even more limited to blocks with attributes, one of those being the titleblock.

  3. #13
    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: LISP routine to grab an attribute value from a block (which varies)

    I think this will do for you what you want (get the attribute value from the first instance of the block in a drawing or you can change it to the layout)

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard copyright 2017 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    ;
    ; Abstract: This set of functions are designed to get an attribute textstring from REVISION tagstring in first instance of block
    ; with a tagstring REVISION in a drawing.
    ;___________________________________________________________________________________________________________|
    ;
    ; Command Line Function Header List
    ;___________________________________________________________________________________________________________|
    
    ;* C:TitleBlockValues
    ;* Command Line Function to get a value from a blocks in paperspace(s) and a "REVISION" tagstring 
    
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List 
    ;___________________________________________________________________________________________________________|
    
    ;  Function, Arguments and Description
    
    ;* (AttributeSublists objBlockReference)
    ;* Function to create a list of sublists from a block reference of its attribute tagstring, textstring and handle
    
    ;* (AttributeTextString objSelection strTagString)
    ;* Function to get a textstring value from a block reference and a tagstring
    
    ;* (SelectionSetToList ssSelections)
    ;* Function to convert a lisp selectionset to a list of objects
    
    ;* (TitleBlockValue strBlockname strTagString)
    ;* Function to get a value from the first instance of a block reference
    
    ;$ End HEader
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Command line Function to get an attribute value from a selected block and REVISION tagstring.
    ;___________________________________________________________________________________________________________|
    
    (defun C:TitleBlockValues (/ lstReturn lstSelections objSelection ssSelections strTextString )
     (if (and ;(setq ssSelections  (ssget "X" (list (cons 410 (getvar "ctab")) (cons 66  1)(cons 0  "INSERT"))))
              (setq ssSelections  (ssget "X"  (cons 66  1)(cons 0  "INSERT"))))
              (setq lstSelections (selectionsettolist ssSelections))
         )
      (foreach objSelection lstSelections
       (if (setq strTextString (AttributeTextString objSelection "REVISION"))
        (setq lstReturn (cons strTextString
                              lstReturn
                        )
        )
       )
      )
     )
     (car (reverse lstReturn))
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to create a list of sublists from a block reference of its attribute tagstring, textstring and handle
    ;___________________________________________________________________________________________________________|
    
    (defun AttributeSublists (objBlockReference / lstAttributes objAttribute)
     (if (and (vlax-method-applicable-p objBlockReference "getattributes")
              (setq lstAttributes (vlax-invoke objBlockReference "getattributes"))
         )
      (setq lstOfSublists (mapcar '(lambda (objAttribute)(list (strcase (vla-get-tagstring objAttribute))
                                                               (vla-get-textstring objAttribute)
                                                               (vla-get-handle objAttribute)
                                                         )
                                   ) 
                                   lstAttributes
                          )
      )
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to get a textstring value from a block reference and a tagstring
    ;___________________________________________________________________________________________________________|
    
    (defun AttributeTextString (objSelection strTagString)
     (if (setq lstOfSublists (AttributeSublists objSelection))
      (cadr (assoc (strcase strTagString) lstOfSublists))
     )
    )
    
    
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to convert a lisp selectionset to a list of objects
    ;___________________________________________________________________________________________________________|
    
    (defun SelectionSetToList (ssSelections / entSelection intCount lstObjects objSelection )
     (repeat (setq intCount (sslength ssSelections))
      (and
       (setq intCount (1- intCount))
       (setq entSelection (ssname ssSelections intCount))
       (setq objSelection (vlax-ename->vla-object entSelection))
       (setq lstObjects   (cons objSelection lstObjects))
      )
     )
     lstObjects
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to get a value from the first instance of a block reference
    ;___________________________________________________________________________________________________________|
    
    (defun TitleBlockValue (strBlockname strTagString / entSelection objSelection ssSelections)
     (if (and (setq ssSelections    (ssget "x" (list (cons 2 strBlockName)(cons 66 1))))
              (setq entSelection    (ssname ssSelections 0))
              (setq objSelection    (vlax-ename->vla-object entSelection))
         )
      (AttributeTextString objSelection strTagString)
     )
    )
    
    (princ "!")
    (vl-load-com)
    Attached Files Attached Files
    AutomateCAD

  4. #14
    Woo! Hoo! my 1st post
    Join Date
    2013-09
    Posts
    1
    Login to Give a bone
    0

    Default Re: LISP routine to grab an attribute value from a block (which varies)

    Hi ziele_o2k

    I used your code as part of a lisp program that I'v created. I'm calling it from a foreach loop and calling it twice to retrieve two tags on every layout.

    When I print the results from the variables that get returned it print a lot of "nil" values before it prints the string of the tag that I want.

    Could you please assist me to fix this.

    Thank you,

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 1
    Last Post: 2016-11-03, 03:13 PM
  2. 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
  3. Replies: 9
    Last Post: 2006-07-11, 11:09 PM
  4. Attribute block switching routine
    By jason.cyr13 in forum AutoLISP
    Replies: 10
    Last Post: 2006-03-28, 07:22 PM
  5. how to grab and modify enities within a block
    By clintonc in forum AutoLISP
    Replies: 3
    Last Post: 2004-09-01, 09:30 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
  •