Lisp to change part of attribute value and replace that by another attribute

Lisp to change part of attribute value and replace that by another attribute

f.van.keulen
Contributor Contributor
2,006 Views
5 Replies
Message 1 of 6

Lisp to change part of attribute value and replace that by another attribute

f.van.keulen
Contributor
Contributor

Hello all,

 

I have a problem changing the value of an attribute. I do not want to change the entire attribute name, but delete a part of it, and enter that deleted part for another attribute. For example, I have an attribute "code" with the value "JKL.00.123.45 CH". I would like to remove the "CH" part from this and place it in the "info" attribute. I want this for all blocks with the "accespoint" name in particular. Can someone help me with this? I have no idea how to write a LISP for this. I just can't figure it out. If I have to do all this manually, I will be busy for a very long time.

So to sum it up clearly:
It concerns the block with the name "accespoint".
This has two attributes 1 with the name "info" and 1 with the name "code"
When the attribute code with the piece of text with "CH" is deleted, the rest must remain.
The CH part must be replaced in the "info" attribute.
0 Likes
Accepted solutions (1)
2,007 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant

Post a sample of that block to test.

Post two versions of the block, att state before and after the change.

You may simplify the geometry of block (not atts!) if you consider that sensitive to the public.

0 Likes
Message 3 of 6

f.van.keulen
Contributor
Contributor

Good input. Sorry I didn't do that, the examples are now added as attachments!

0 Likes
Message 4 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution
(defun c:AttChSwap (/ ss i  en)

  (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
    (repeat (setq i (sslength ss))
      (setq en (ssname ss (setq i (1- i))))
      (and (wcmatch (setq st (getpropertyvalue en "code")) "* CH")
	   (getpropertyvalue en "info")
	   (progn
	     (setpropertyvalue en "code" (substr st 1 (- (strlen st) 3)))
	     (setpropertyvalue en "info" "CH")))))
  (princ)
  )
Message 5 of 6

SeeMSixty7
Advisor
Advisor

Just use -ATTEDIT

ATTEDIT will bring up the dialog box.

-ATTEDIT will give you the command line version which will allow you to do what you are asking to do.

Command: -ATTEDIT
Edit attributes one at a time? [Yes/No] <Y>: n
Performing global editing of attribute values.
Edit only attributes visible on screen? [Yes/No] <Y>: n
Drawing must be regenerated afterwards.
Enter block name specification <*>:
Enter attribute tag specification <*>:
Enter attribute value specification <*>:
133 attributes selected.
Enter string to change: CH
Enter new string: NEW

Good luck

Message 6 of 6

f.van.keulen
Contributor
Contributor

Thanks a lot!

0 Likes