Results 1 to 7 of 7

Thread: change block elevation to match attribute value

  1. #1
    Member
    Join Date
    2011-05
    Location
    Athens, GR
    Posts
    7
    Login to Give a bone
    0

    Default change block elevation to match attribute value

    Hi everyone,
    I am new to programming Lisp, so I was wandering if someone could help me with a routine that
    changes block elevation to match an attribute value of its own.

    to be more specific:
    I have a block named "SH" representing a point, with attributes A1 (for point number) and A2 (for elevation)
    Its original elevation is 0, and the desirable elevation is the value saved in attribute A2.

    thank you in advance!
    vassilis

  2. #2
    Forum Username Moderator
    Join Date
    2003-08
    Posts
    76
    Login to Give a bone
    0

    Default Re: change block elevation to match attribute value

    plenty of Lisp examples to look at - here is a link to one which you may find interesting

    http://forums.augi.com/showthread.ph...bute+elevation

  3. #3
    Member
    Join Date
    2011-05
    Location
    Athens, GR
    Posts
    7
    Login to Give a bone
    0

    Default Re: change block elevation to match attribute value

    thanks a lot
    my apologies though, I didn't notice there were already the same threads
    I used this one, and helped me fine
    http://forums.augi.com/showthread.php?t=4362
    thanks again!

  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: change block elevation to match attribute value

    Code:
    (defun C:SH1 (/
                 entSelection
                 intCount
                 objAttribute
                 objSelection
                 ssSelections
                 strTextstring
                )
     (if (setq ssSelections (ssget (list (cons 2 "SH"))))
      (repeat (setq intCount (sslength ssSelections))
       (setq intCount     (1- intCount)
             entSelection (ssname ssSelections intCount)
             objSelection (vlax-ename->vla-object entSelection)
       )
       (foreach objAttribute (vlax-invoke objSelection "getattributes")
        (if (= (vla-get-tagstring objAttribute) "A2")
         (if (/= (setq strTextstring (vla-get-textstring objAttribute)) "")
          (progn
           (setq lstInsertion (vlax-get objSelection  "insertionpoint")
                 lstInsertion (list (car lstInsertion)
                                    (cadr lstInsertion)
                                    (atof strTextString)
                              )
           )
           (vlax-put objSelection "insertionpoint" lstInsertion)       
          )
         )
        )
       )
      )
     )
    )
    (vl-load-com)
    Additional Filtering of Attributes

    Code:
    (defun C:SH1 (/
                 entSelection
                 intCount
                 objAttribute
                 objSelection
                 ssSelections
                 strTextstring
                )
     (if (setq ssSelections (ssget (list (cons 2 "SH"))))
      (repeat (setq intCount (sslength ssSelections))
       (setq intCount     (1- intCount)
             entSelection (ssname ssSelections intCount)
             objSelection (vlax-ename->vla-object entSelection)
       )
       (foreach objAttribute (vlax-invoke objSelection "getattributes")
        (if (= (vla-get-tagstring objAttribute) "A2")
         (if (/= (setq strTextstring (strcase (vla-get-textstring objAttribute))) "")
          (progn
             
           (if (vl-string-search "BC " strTextString)
            (setq strTextString (vl-string-subst "" "BC " strTextString))
           )
    
           (setq lstInsertion (vlax-get objSelection  "insertionpoint")
                 lstInsertion (list (car lstInsertion)
                                    (cadr lstInsertion)
                                    (atof strTextString)
                              )
           )
           (vlax-put objSelection "insertionpoint" lstInsertion)       
          )
         )
        )
       )
      )
     )
    )
    (vl-load-com)
    Last edited by peter; 2015-04-03 at 05:09 PM. Reason: Additional Attribute Filtering
    AutomateCAD

  5. #5
    Member
    Join Date
    2011-05
    Location
    Athens, GR
    Posts
    7
    Login to Give a bone
    0

    Default Re: change block elevation to match attribute value

    @ peter
    it is working nice too!
    thank you very much sir

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

    Default Re: change block elevation to match attribute value

    Quote Originally Posted by peter View Post
    Code:
    (defun C:SH1 (/
                 entSelection
                 intCount
                 objAttribute
                 objSelection
                 ssSelections
                 strTextstring
                )
     (if (setq ssSelections (ssget (list (cons 2 "SH"))))
      (repeat (setq intCount (sslength ssSelections))
       (setq intCount     (1- intCount)
             entSelection (ssname ssSelections intCount)
             objSelection (vlax-ename->vla-object entSelection)
       )
       (foreach objAttribute (vlax-invoke objSelection "getattributes")
        (if (= (vla-get-tagstring objAttribute) "A2")
         (if (/= (setq strTextstring (vla-get-textstring objAttribute)) "")
          (progn
           (setq lstInsertion (vlax-get objSelection  "insertionpoint")
                 lstInsertion (list (car lstInsertion)
                                    (cadr lstInsertion)
                                    (atof strTextString)
                              )
           )
           (vlax-put objSelection "insertionpoint" lstInsertion)       
          )
         )
        )
       )
      )
     )
    )
    (vl-load-com)
    Peter,

    This is great code and works perfect. I have a quick question. The block I'm using is a TC BC block that was created years ago. The block does not separate out the BC from the attribute. The users have been typing "BC 53.56". Is there a way to have the LISP ignore the "BC" and the space and then read the attribute. I know the correct way is to create the block with them as separate entities but they have been using this for years and exists in many drawing.

    Thank you in advance,
    Dave

  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: change block elevation to match attribute value

    See additional code above for BC prefix exclusion.

    Peter
    AutomateCAD

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. Replies: 13
    Last Post: 2012-09-18, 07:51 PM
  3. Block-Change Number to Match Attribute Value
    By jjochum in forum AutoLISP
    Replies: 3
    Last Post: 2008-09-01, 05:38 AM
  4. Title Block attribute change
    By jerry.smirl in forum AutoLISP
    Replies: 8
    Last Post: 2008-03-24, 03:22 PM
  5. Replies: 9
    Last Post: 2006-08-24, 11:46 AM

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
  •