collect values from attributes and store them into an other attribute

collect values from attributes and store them into an other attribute

Hans_Knol
Advocate Advocate
710 Views
11 Replies
Message 1 of 12

collect values from attributes and store them into an other attribute

Hans_Knol
Advocate
Advocate

Hi, hope someone is able to help,

 

I have some attributes called "Col1" with a Value "1000", "Col2" with the value "1001", "Col3" with the value "1002", "Col4" with the value "1003", "Col5" with the value "1004", "Col6" with the value "1005", "Col7" with the value "1006", "Col8" with the value "1007", "Col9" with the value "1008", "Col10" with the value "1009". All those values must be stored in a hidden block called WD_M in the attribute called "CHAR_H" like "1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009"

Hans Knol
0 Likes
Accepted solutions (1)
711 Views
11 Replies
Replies (11)
Message 2 of 12

pendean
Community Legend
Community Legend
Would the use of a FIELD be what you need?
0 Likes
Message 3 of 12

Hans_Knol
Advocate
Advocate

in case of a new drawing it is a good idea, but in this case we have over 10.000 drawings whats need to be changed

Hans Knol
0 Likes
Message 4 of 12

pendean
Community Legend
Community Legend
@Hans_Knol Can you share a sample DWG file with copies of these blocks (and hidden block) in it?
0 Likes
Message 5 of 12

Hans_Knol
Advocate
Advocate

Here it is, the hidden block is inserted on 0,0

Hans Knol
0 Likes
Message 6 of 12

Moshe-A
Mentor
Mentor

@Hans_Knol  hi,

 

Check this COLX command. block "wd_m" is auto selected.

at select objects: pick your title block (could be any name) only 1 pick to select one is allowed.

that's it, job done!

 

think of another way to hide a block like putting it in freeze layer cause it is very difficult to select yours and see the change.

 

One more thing if i may? a positive\constructive criticism:

when you start a thread try to be a little more detailed, describe the issue so we can understand from first read. consider we do not know what design you do and how your blocks looks. if possible give some text\visual examples and image with before and after. do not wait us to ask for sample drawing. if you do that, surly you'll get a quick solution it's for your own benefit - yes?!  😀

 

enjoy

Moshe

 

 

(vl-load-com)

(defun c:colx (/ _datatags LM:lst-str fetch_attributes_value ; local functions
	         ss0 ss1)
  
 ;; List to String  -  Lee Mac
 ;; Concatenates each string in a supplied list, separated by a given delimiter
 ;; lst - [lst] List of strings to concatenate
 ;; del - [str] Delimiter string to separate each item

 (defun LM:lst->str ( lst del )
    (if (cdr lst)
        (strcat (car lst) del (LM:lst->str (cdr lst) del))
        (car lst)
    )
 ); LM:lst->str

 (setq _datatags (lambda () (LM:lst->str (mapcar (function (lambda (n) (strcat "COL" (itoa n)))) '(1 2 3 4 5 6 7 8 9 10)) ",")))

 (defun fetch_attributes_value ()
  (vl-remove-if
   'not
   (mapcar
     (function
       (lambda (AcDbAttrib)
        (if (wcmatch (strcase (vla-get-tagString AcDbAttrib)) (_datatags))
         (vla-get-textString AcDbAttrib)
	); if  
       ); lambda
     ); function
    (vlax-invoke (vlax-ename->vla-object (ssname ss1 0)) 'GetAttributes)
   ); mapcar
  ); vl-remove
 ); fetch_attributes_value

  
 ; here start c:colx
 (if (and
       (setq ss0 (ssget "_x" '((0 . "insert") (2 . "wd_m") (66 . 1))))
       (setq ss1 (ssget ":s:e+." '((0 . "insert") (66 . 1))))
     )  
  (setpropertyvalue (ssname ss0 0) "char_h" (LM:lst->str (fetch_attributes_value) ","))
 ); if

 (princ) 
); c:colx

 

0 Likes
Message 7 of 12

Hans_Knol
Advocate
Advocate

Thanks Moshe, also for your comments. It almost wats needed, is it possible to select the block where the attributes COL1 - COL10 are in also automaticly 

Hans

Hans Knol
0 Likes
Message 8 of 12

Moshe-A
Mentor
Mentor

@Hans_Knol 

 

Good Morning

 

Yes it could be done but the name of your title block is meaningless (at least on my standards 😀) and i thought you would like to select numeres TB block names. if you make it fix and you will run it and the blocks are not exist you will not know what happend at all - still want to do this?

 

Moshe

 

0 Likes
Message 9 of 12

Hans_Knol
Advocate
Advocate

Hi Moshe, yes I Agree, but in this case I only have this titleblock and it is used in a lot of drawings, so my answer is yes on your question do you want to do this

Hans Knol
0 Likes
Message 10 of 12

Moshe-A
Mentor
Mentor
Accepted solution

OK

 

it's about time you start  'messïng' with autolisp code by your own 🤣

replace line 40 with the following:

 

(setq ss1 (ssget "_x" '((0 . "insert") (2 . "EEKA3-EN") (66 . 1))))

 

work?

 

Moshe

 

0 Likes
Message 11 of 12

Hans_Knol
Advocate
Advocate

I Agree Moshi!

Hans Knol
0 Likes
Message 12 of 12

Moshe-A
Mentor
Mentor

You are agree?

 

here is your first challange in phases 🤣 write autolisp command call it what ever

 

phase 1:

to insert a polygon (i mean POLYGON command) 

the program pauses for user insertion point + radius

 

phase 2:

insert a text in the centrum.

 

phase 3:

add hatch on top (do not mask the text)

 

phase 4:

color each object

 

take a deep breath, i am here to help

 

Moshe

 

0 Likes