Results 1 to 4 of 4

Thread: Block Attribute Update

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    2021-08
    Posts
    23
    Login to Give a bone
    0

    Default Block Attribute Update

    I am trying to create a lisp that will update a title block 'SNP-00A1AH00PW'

    I have a block named "SNP-00A1AH00PW".

    There are 2 specific attributes which I want to change in it.

    The attribute names are...

    TITLE1 & TITLE2

    TITLE1 will = SIP
    TITLE2 will = STAGE_2

    I have currently put together the following. However, this does not seem to work. Any help would be appreciated.
    Code:
    (if ;;retrieve a set of attributed blocks
            (setq s ;; Assign the selection set pointer to variable 's'
                (ssget "_X" ;; Search entire database
                   '(
                        (0 . "INSERT") ;; Block References
                        (66 . 1) ;; Attributed
                        (2 . "SNP-00A1AH00PW") ;; with name SNP-00A1AH00PW
                    )
                ) ;; end SSGET
            ) ;; end SETQ
    
               
                (if (setq x )
                        (setq l
                            (cons
                               '(
                                    ("TITLE1"  . "SIP")
                                    ("TITLE2" .  "STAGE_2")
                                )
                            ) ;; end CONS
                        ) ;; end SETQ
    Last edited by Opie; 2023-09-26 at 03:47 PM. Reason: [code] tags added

  2. #2
    Member
    Join Date
    2021-08
    Posts
    23
    Login to Give a bone
    0

    Default Re: Block Attribute Update

    I have improved on the code but its not quite there, see below.

    Code:
    (defun c:updateblock ("SNP-00A1AH00PW" / ss)
      (setq ss (ssget "_X" '((0 . "INSERT") (2 . "SNP-00A1AH00PW"))))
      (if ss
        (progn
          (setq i 0)
          (while (< i (sslength ss))
            (setq ent (ssname ss i))
            (setq atts (entget ent))
            (foreach att atts
              (if (= "ATTRIB" (cdr (assoc 0 att)))
                (progn
                  ; Update attribute values here
                  ; For example, to update the value of an attribute named "TITLE1" to "20"
                  ; Replace "TITLE1" and "20" with your desired values
                  (cond ((= "TITLE1" (cdr (assoc 2 att))) 
                          (setq att-value "999")
                          (entmod (subst (cons 1 att-value) (assoc 1 att) atts)))
                        ((= "TITLE2" (cdr (assoc 2 att))) 
                          (setq att-value "1.0")
                          (entmod (subst (cons 1 att-value) (assoc 1 att) atts)))
                        )
                )
              )
            )
            (setq i (+ i 1))
          )
        )
      )
    )
    Last edited by Opie; 2023-09-26 at 08:17 PM. Reason: [code] tags added

  3. #3
    Member
    Join Date
    2021-08
    Posts
    23
    Login to Give a bone
    0

    Default Re: Block Attribute Update

    Still not quiet there, see below for the latest rendition.
    Code:
    (defun c:updateblock (block-name / SNP-00A1AH00PW)
      (setq ss (ssget "_X" '((0 . "INSERT") (2 . SNP-00A1AH00PW))))
      (if ss
        (progn
          (setq i 0)
          (while (< i (sslength ss))
            (setq ent (ssname ss i))
            (setq atts (entget ent))
            (foreach att atts
              (if (= "ATTRIB" (cdr (assoc 0 att)))
                (progn
                  ; Update attribute values here
                  ; For example, to update the value of an attribute named "TITLE1" to "20"
                  ; Replace "TITLE1" and "20" with your desired values
                  (cond ((= "TITLE1" (cdr (assoc 2 att))) 
                          (setq att-value "SIP")
                          (entmod (subst (cons 1 att-value) (assoc 1 att) atts)))
                        ((= "TITLE2" (cdr (assoc 2 att))) 
                          (setq att-value "STAGE_2")
                          (entmod (subst (cons 1 att-value) (assoc 1 att) atts)))
                        )
                )
              )
            )
            (setq i (+ i 1))
          )
        )
      )
    )
    Please use [code]tags.
    Last edited by Opie; 2023-09-27 at 01:34 PM. Reason: [code] tags added

  4. #4
    Member
    Join Date
    2015-10
    Location
    Alhambra
    Posts
    27
    Login to Give a bone
    0

    Default Re: Block Attribute Update

    give this a try:
    Code:
    ; updateblock find matching block & update specific attribute values
    ; https://forums.augi.com/showthread.php?177289-Block-Attribute-Update
    (defun c:updateblock (/ blkname tagname1 tagname2 ss i sen atts)
      ; Place Block Name & Attribute Tags & Values here:
      ; For example, to update the value of an attribute named "TITLE1" to "20"
      ; Replace "TITLE1" and "20" with your desired values
      (setq blkname "SNP-00A1AH00PW"
            tagname1 (list "TITLE1" "SIP")
            tagname2 (list "TITLE2" "STAGE_2")
            ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blkname)))
      )
      (if ss
        (progn
          (setq i 0)
          (while (< i (sslength ss))
            (setq sen (entnext (ssname ss i)))                           ; get attributes
            (while sen
             (setq atts (entget sen))    
             (if (/= (cdr(assoc 0 atts)) "SEQEND") 
                  (cond ((= (car tagname1) (cdr (assoc 2 atts))) 
                          (entmod (setq atts(subst (cons 1 (cadr tagname1)) (assoc 1 atts) atts))))
                        ((= (car tagname2) (cdr (assoc 2 atts))) 
                          (entmod (setq atts(subst (cons 1 (cadr tagname2)) (assoc 1 atts) atts))))
                  )
              ) ; if more attributes
              (setq sen (entnext sen))                     ; and search
             ) ; while attributes
            (setq i (+ i 1))
          )
          (alert(strcat"Found & Updated [" (itoa (sslength ss)) "] Blocks Matching name: [" blkname "]"))
        )
        (alert(strcat"Did NOT find any Blocks Matching name: [" blkname "]"))
      )
      (princ)
    )

Similar Threads

  1. Replies: 8
    Last Post: 2018-11-19, 06:05 AM
  2. Update "Prompt" tab in an existing Block Attribute.
    By joelnishan605002 in forum ARX
    Replies: 0
    Last Post: 2014-03-24, 09:04 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: 27
    Last Post: 2006-10-06, 01:04 PM
  5. Replies: 5
    Last Post: 2006-08-11, 01:32 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
  •