Attedit: replacing an argument with a variable

Attedit: replacing an argument with a variable

Anonymous
Not applicable
770 Views
3 Replies
Message 1 of 4

Attedit: replacing an argument with a variable

Anonymous
Not applicable

Ok, so the quick summary: I'm creating a LISP routine that will use the attedit command to delete the contents of 50+ attributes per drawing (several hundred drawings as well). I need it to be able to delete the contents no matter what was there to begin with (which varies from drawing to drawing). My solution is to delete the contents 1 character at a time by using the following code:

 

(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "DESCRIPTION_1" "" "A" "")

(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "DESCRIPTION_1" "" "B" "")

(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "DESCRIPTION_1" "" "C" "")

...and so on...

 

This works wonderfully, but results in a rather long LISP file and since I have to do this for over 50 attributes within the same block (DESCRIPTION_1, DESCRIPTION_2, etc) having to create this LISP routine through copy / paste / edit is going to be painful. I have tried (and failed) several different ways of assigning a variable to "DESCRIPTION_1" so that I can simply change the variable every time that the code needs to move on to the next attribute, but nothing has worked. Below is an example:

 

(setq DESCR 'DESCRIPTION_1)

(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "!DESCR" "" "A" "")

....

(setq DESCR 'DESCRIPTION_2)

(vl-cmdf "._attedit" "_N" "_N" "BLOCK1" "!DESCR" "" "A" "")

....

 

I have tried to remove the quotes around the variable and just about every variation that I can think of or search for and haven't been able to get it to work. Can anyone shed some light on a solution for me aside from having to manually edit each line for 1000 of lines of code?

 

THANKS!

0 Likes
Accepted solutions (1)
771 Views
3 Replies
Replies (3)
Message 2 of 4

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Ok, so the quick summary: I'm creating a LISP routine that will use the attedit command to delete the contents of 50+ attributes per drawing (several hundred drawings as well). I need it to be able to delete the contents no matter what was there to begin with (which varies from drawing to drawing). My solution is to delete the contents 1 character at a time by using the following code:

 ...


Hi arrow2486,

 

something like this, perhaps

 

(vl-load-com)
(defun c:demo (/ attlst i obj s1)
  (if (setq s1 (ssget "_X" '((0 . "INSERT") (2 . "BLOCK1") (66 . 1))))
    (repeat (setq i (sslength s1))
      (setq obj    (vlax-ename->vla-object (ssname s1 (setq i (1- i))))
            attlst nil
            attlst (vlax-invoke obj 'GetAttributes)
      )
      (foreach att attlst
        (if (and (wcmatch (strcase (vla-get-TagString att)) "DESCRIPTION_*")
                 (vlax-write-enabled-p att)
            )
          (vla-put-TextString att "")
        )
      )
    )
  )
  (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 3 of 4

Anonymous
Not applicable

That worked! However as I'm very new to LISP routines and programming, can you (or someone) explain how / why that works so well?

 

THANKS!

0 Likes
Message 4 of 4

hmsilva
Mentor
Mentor

@Anonymous wrote:

That worked! However as I'm very new to LISP routines and programming, can you (or someone) explain how / why that works so well?

 

THANKS!


You're welcome, arrow2486

see if it is easier to understand now

 

(vl-load-com)
(defun c:demo (/ attlst i obj s1)
  ; if select all blocks with attributes and named 'BLOCK1'
  (if (setq s1 (ssget "_X" '((0 . "INSERT") (2 . "BLOCK1") (66 . 1))))
    ; set the index variable 'i' with the selection set length,
    ; and repeat the number of previous selected blocks
    (repeat (setq i (sslength s1))
      ; get the 'i' ename from the selection set,
      ; sets the variable 'i' reduced by 1 in each loop
      ; and transform the entity to a VLA-object
      (setq obj    (vlax-ename->vla-object (ssname s1 (setq i (1- i))))
            ; sets the 'attlst' variable to nil, to ensure that in
            ; the next loop, is setted with the correct attributes only
            attlst nil
            ; sets the 'attlst' variable with the attributes
            ; in the obj block, as a list with VLA-objects
            attlst (vlax-invoke obj 'GetAttributes)
      )
      ; step thru all attributes from the list
      (foreach att attlst
        ; test if TAG is "DESCRIPTION_*"
        (if (and (wcmatch (strcase (vla-get-TagString att)) "DESCRIPTION_*")
                 ; and, test if can be modified
                 (vlax-write-enabled-p att)
            )
          ; if true, put an empty string
          (vla-put-TextString att "")
        )
      )
    )
  )
  (princ)
)


Glad I could help

Henrique

 

EESignature