Add ( ) in attributes

Add ( ) in attributes

Anonymous
Not applicable
2,166 Views
17 Replies
Message 1 of 18

Add ( ) in attributes

Anonymous
Not applicable

hi

someone can help me with this please?

i try to mofidy many existing attributes (but only the selected objects), i want to put every value into ( )

my bloc name is ANCHOR_ANNO and have  6 attributes

 

GUY1

GUY2

GUY3

GROSSEUR

ANCRE

ECRAT

 

some attributes are empty and i want to skip those attributes if posssible

 

thanks a lot

0 Likes
Accepted solutions (4)
2,167 Views
17 Replies
Replies (17)
Message 2 of 18

gdefilo
Advocate
Advocate

Hi jonathan.t.d.1985,

simply use the "find" command with the replace option. Look for the blocks containing the attributes you want to change and substitute the old text string with the new.

Just simple as that!

 

Hope this helps,

Giancarlo

 

0 Likes
Message 3 of 18

Anonymous
Not applicable

i have 200x the ANCHOR_ANNO bloc in my dwg. and i want modify 125 of them only. some of unselected have the same value that many in selection that i want to modify that why i want a lisp or a macro line to modify attributes

 

develop your idea if you can help me with this option 🙂

 

i forgot to specify that selected blocs have a different layer that unselected

0 Likes
Message 4 of 18

gdefilo
Advocate
Advocate

Which is the difference between the blocks to change and the ones not to change?

Only their position?

Do you select them manually? Are they on different layers? What else?

 

Giancarlo

 

0 Likes
Message 5 of 18

Anonymous
Not applicable

Yes the position are always different. this is the most commun difference. but the layer and the color are are different too

 

Capture.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

the ( ) and purple color mean this is an old block replaced by the new (red) and the purple value are obsolete and the red are now effective

 

i can select them by select similar because they are on different layers. that only select the bloc with the layer removed

 

if you need more info let me know

0 Likes
Message 6 of 18

gdefilo
Advocate
Advocate

So, as far as I can understand, you could "isolate" the "purple" layer, or select similar, as you prefer. Then, use the "find" command to substitute the text strings in the selected blocks.

It will do all the job because you can use the "replace all" option.

 

Have a look at this:

 

http://cadsetterout.com/autocad-tutorials/find-and-replace-text/

 

hope you will find it useful,

Giancarlo

Message 7 of 18

devitg
Advisor
Advisor
Please upload a sample dwg
0 Likes
Message 8 of 18

Anonymous
Not applicable

hi

 

i post the sample asked Davitg.

 

it containt a small aera where i have to add new value block in red and identify obselete value in purple and ( ). the ( ) is not placed yet to let you try if you have any idea.

 

many thanks

0 Likes
Message 9 of 18

gdefilo
Advocate
Advocate
Accepted solution

Hi jonathan,

 

in my opinion there's no need to apply a LISP routine or other.

Just go on through these steps:

- select similar blocks "anchor_anno" that are on "removed" layer;

- launch the "find" command;

- in the "find what" box type the text string you want to substitute;

- in the "replace with" box type the same text with ( );

- check "list results";

- check "block attribute value";

- press "find";
- should appear a list of values;

- press "replace all";

- go on with these steps for all the values you have to change.

 

find.jpg

 

I wouldn't do it other way.

Hope this helps,

Giancarlo

 

Message 10 of 18

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

hi

 

i post the sample asked Davitg.

 

it containt a small aera where i have to add new value block in red and identify obselete value in purple and ( ). the ( ) is not placed yet to let you try if you have any idea.

 

many thanks


Hi Jonathan,
perhaps something will do the trick...

 

(vl-load-com)
(defun c:demo (/ atts i obj ss str)
    (if (setq ss (ssget ":L" '((0 . "INSERT") (66 . 1) (2 . "ANCHOR_ANNO") (62 . 6))))
        (repeat (setq i (sslength ss))
            (setq obj  (vlax-ename->vla-object (ssname ss (setq i (1- i))))
                  atts (vlax-invoke obj "GetAttributes")
            )
            (foreach att atts
                (if (and (/= (setq str (vla-get-textstring att)) "")
                         (not (vl-string-position (ascii "(") str))
                    )
                    (vla-put-textstring att (strcat "(" str ")"))
                )
            )
        )
    )
    (princ)
)

 

 

Hope this helps,
Henrique

EESignature

Message 11 of 18

jdiala
Advocate
Advocate

@Anonymous wrote:

hi

someone can help me with this please?

i try to mofidy many existing attributes (but only the selected objects), i want to put every value into ( )

my bloc name is ANCHOR_ANNO and have  6 attributes

 


If the blocks are already selected, why do you need a lisp routine. Just open the properties dialog box and edit the attributes there.
0 Likes
Message 12 of 18

Anonymous
Not applicable

Because i selected more that 100 blocs and attributes are different for many blocs, into properties dialog box the field attribut are *varies* and i fail to add ( ) without change value

0 Likes
Message 13 of 18

Anonymous
Not applicable

Henrique i have to thanks you again because your lisp work very well! (but i removed the fist line)

 

i never used lisp before and i didn't understand anything about the syntax but i will read tonight about and try to adapt the code to an other bloc. but This bloc have 2 attributes and the first will need only "(" and second attribute will have ")"

 

 

my challenge this w-e will be to find How list or identify attributes in a bloc

 

any tip, comment or document will be accept 🙂

 

 

0 Likes
Message 14 of 18

hmsilva
Mentor
Mentor

@Anonymous wrote:

Henrique i have to thanks you again because your lisp work very well! (but i removed the fist line)

i never used lisp before and i didn't understand anything about the syntax but i will read tonight about and try to adapt the code to an other bloc. but This bloc have 2 attributes and the first will need only "(" and second attribute will have ")"

 

my challenge this w-e will be to find How list or identify attributes in a bloc

any tip, comment or document will be accept 🙂


You're welcome, Jonathan!


The 'demo' will select 'ssget' inserts (0 . "INSERT") with the name (2 . "ANCHOR_ANNO") wite attributes (66 . 1) and color 6 (62 . 6), will exclude locked layers ":L"

Process all selected objects as vla objects, (setq obj  (vlax-ename->vla-object (ssname ss (setq i (1- i))))

get the attributes as list of atributes (vlax-invoke obj "GetAttributes")

test if the atribute textstring is not empty (/= (setq str (vla-get-textstring att)) "")

and test if in atribute textstring dont exist a "(" to not add more then one if a user select the same block twice (not (vl-string-position (ascii "(") str))

if the tests are true, put the parenthesis in the textstring (vla-put-textstring att (strcat "(" str ")"))

 

 

For the other block, is the name the same?

If not, select the block chamging the name, test for the tag,

if first tag (vla-put-textstring att (strcat "(" str ))

if second tag (vla-put-textstring att (strcat  str ")"))

 

To study the functions, open the code in vlide, highlights the function and press the button with a ? it will open the help files in the selected function...

 

EDIT: some sites, AfraLISP   Jeffery P Sanders  Lee Mac

 

Hope this helps,
Henrique

EESignature

Message 15 of 18

Anonymous
Not applicable

Hi Hmsilva

 

i'm new into lisp language i tried to build  a similar code but i failed

 

 

 

i made this code 

 

(defun c:demo (/ i s B)
 
(if (setq s (ssget "_:L" '((0 . "INSERT") (2 . "ANCHOR_ANNO") (66 . 6))))
    (repeat (setq i (sslength s))
      (setq b (ssname s (setq i (1- i))))
      (setpropertyvalue b "POLE_NO" (strcat "(" (getpropertyvalue b "POLE_NO") ")"))
      (setpropertyvalue b "HEIGHT" (strcat "(" (getpropertyvalue b "HEIGHT")))
      (setpropertyvalue b "YEAR_ADDED" (strcat (getpropertyvalue b "YEAR_ADDED") ")"))
    )
  )
  (princ)
)

but i would use your help to ugrade it and add into:

 

(not (vl-string-position (ascii "(") str))

ALSO check in attribute YEAR_ADDED i put ")"  not "("

 

 

i don't want to skip empty attributes in this lisp then i don't need: 

(/= (setq str (vla-get-textstring att)) "")

 

 

Many thanks again!

John

 

 

0 Likes
Message 16 of 18

hmsilva
Mentor
Mentor
Accepted solution

Hi John,

your code have na error in ssget filter list...

 

The group code 66 it's an atribute flag.if 1, the insert have attributes.

(66 . 1)

The groupe code for índex color is 62 and (62 . 6) is for color 6.

 

If you change the filter list

 

(setq s (ssget "_:L" '((0 . "INSERT") (2 . "ANCHOR_ANNO") (66 . 6))))

to

 

 

(setq s (ssget "_:L" '((0 . "INSERT") (2 . "ANCHOR_ANNO") (66 . 1) (62 . 6))))

 

it should select INSERTs with the name ANCHOR_ANNO with attributes, color 6 and not in locked layers.

 

But if the user runs the code more than once in the same INSERT, the code will continue adding parentheses to the text string, regardless the parentheses existence already in the string...
I would suggest to add a test before add a parentheses, i.e.

 

(if (not (wcmatch (setq str (getpropertyvalue b "POLE_NO")) "(*"))
   (setpropertyvalue b "POLE_NO" (strcat "(" str ")"))
)

 

Probably something like this:

 

(defun c:demo (/ b i s str)
   (if (setq s (ssget "_:L" '((0 . "INSERT") (2 . "ANCHOR_ANNO") (66 . 1) (62 . 6))))
      (repeat (setq i (sslength s))
         (setq b (ssname s (setq i (1- i))))
         (if (not (wcmatch (setq str (getpropertyvalue b "POLE_NO")) "(*)"))
            (setpropertyvalue b "POLE_NO" (strcat "(" str ")"))
         )
         (if (not (wcmatch (setq str (getpropertyvalue b "HEIGHT")) "(*"))
            (setpropertyvalue b "HEIGHT" (strcat "(" str))
         )
         (if (not (wcmatch (setq str (getpropertyvalue b "YEAR_ADDED")) "*)"))
            (setpropertyvalue b "YEAR_ADDED" (strcat str ")"))
         )
      )
   )
   (princ)
)

Untested....

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 17 of 18

Anonymous
Not applicable

thanks so much for your help!

 

i applied your idea of test but i used and other option

 

[code]

(if (not (vl-string-search "(P" (getpropertyvalue b "POLE_NO")))
(progn
(setpropertyvalue b "POLE_NO" (strcat "(" (getpropertyvalue b "POLE_NO") ")"))
(setpropertyvalue b "HEIGHT" (strcat "(" (getpropertyvalue b "HEIGHT")))
(setpropertyvalue b "YEAR_ADDED" (strcat (getpropertyvalue b "YEAR_ADDED") ")"))
);progn
);if

[code]

Message 18 of 18

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

thanks so much for your help!

 

i applied your idea of test but i used and other option

 

[code]

(if (not (vl-string-search "(P" (getpropertyvalue b "POLE_NO")))
(progn
(setpropertyvalue b "POLE_NO" (strcat "(" (getpropertyvalue b "POLE_NO") ")"))
(setpropertyvalue b "HEIGHT" (strcat "(" (getpropertyvalue b "HEIGHT")))
(setpropertyvalue b "YEAR_ADDED" (strcat (getpropertyvalue b "YEAR_ADDED") ")"))
);progn
);if

[code]


If 'POLE_NO' text value will always start with P, then it's a good test...

 

Henrique

EESignature