Combine specific attributs and stor them into a hidden block

Combine specific attributs and stor them into a hidden block

Hans_Knol
Advocate Advocate
382 Views
4 Replies
Message 1 of 5

Combine specific attributs and stor them into a hidden block

Hans_Knol
Advocate
Advocate

Hello all,

 

I am looking for someone that can create a lisp file that combine some attributes into an attribute named “CHAR_H” specific for that drawing what is in a hidden block called WD_M

The values must get from also a block in the same drawing called “EEKA3-EN”

“PLANOS->PROJNR””/””COL1””,” until “PLANOS->PROJNR””/””COL10”

 

PLANOS->PROJNR           = An attribute of block “EEKA3-EN”

/                                            =text

COL1                                    = An attribute of block “EEKA3-EN”

 ,                                           = text

 

The values must be placed in the hidden block “WD_M” in the attribute “CHAR_H”

If the value of the attribute “PLANOS->PROJNR” is “0101” the new Value of the attribute “CHAR_H” in the hidden block “WD_M” must be

 

0101/0180,0101/0181,0101/0182,0101/0183,0101/0184,0101/0185,0101/0186,0101/0187,0101/0188,0101/0189

 

Hope someone can help

 

Hans Knol
0 Likes
Accepted solutions (1)
383 Views
4 Replies
Replies (4)
Message 2 of 5

scot-65
Advisor
Advisor
Storing user/project specific data that will be drawing file specific
can be achieved using vlax-ldata-put and vlax-ldata-get.

The data can be stored as a LIST (dotted pair or multi-dimensional).
The advantage is the list can be parsed more easily and is of unknown predetermined length.
(setq i 1)
(repeat (length lst)
...
(setq i (1+ i))
)

What happens when there are multiple copies of this "hidden block" in a given drawing file?

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 3 of 5

Sea-Haven
Mentor
Mentor

Col1-Col10 can be done as a repeat making attribute name so shortening code.

 

I would also look at LDATA.

 

Try this

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/combine-specific-attributs-and-stor-them-into-a-hidden-block/td-p/12672211

(defun c:wow ( / ah:getatt bname ss obj atts attname att1 x str1)

(defun ah:getatt (tagname / )
(foreach att atts
  (if (= (vlax-get att 'tagstring) tagname)
    (setq val (vlax-get att 'Textstring))
  )
)
)

(setq bname "EEKA3-EN")

(setq ss (ssget "X" (list (cons 0  "INSERT")(cons 2 bname)(cons 410  "MODEL"))))
(setq obj (vlax-ename->vla-object (ssname ss 0)))
(setq atts (vlax-invoke obj 'Getattributes))

(setq attname  "PLANOS->PROJNR")
(ah:getatt attname)
(setq att1 val)

(setq str1 (strcat val (chr 47)))

(setq x 1 str "")
(repeat 9
  (setq attname (strcat "COL" (rtos x 2 0)))
  (aH:getatt attname)
  (setq str (strcat str str1 val ","))
  (setq x (1+ x))
)

(setq attname (strcat "COL" (rtos x 2 0)))
(aH:getatt attname)
(setq str (strcat str str1 val))

(vlax-ldata-put "Hans" "ATTvalue" str)
; (vlax-ldata-get "Hans" "ATTvalue")

(princ)
)

 

0 Likes
Message 4 of 5

pbejse
Mentor
Mentor
Accepted solution

@Hans_Knol wrote:

 

0101/0180,0101/0181,0101/0182,0101/0183,0101/0184,0101/0185,0101/0186,0101/0187,0101/0188,0101/0189

 


(Defun c:CPA ( / fltr sourceBlock hiddenBlock sourceBlockAttv hiddenBlockAttv projNumber result)
(defun attfunc (ab lst)
(vl-remove-if-not '(lambda (tn) (member (car tn) lst))		     
	  (mapcar '(lambda (at)
		     (list (vla-get-tagstring at) (vla-get-textstring at) at)
		   )
		  (vlax-invoke (vlax-ename->vla-object (ssname ab 0)) 'GetAttributes)
	  )
     )		     
)
(setq fltr (lambda (bn)
	     (ssget "_X"
		    (append '((0 . "INSERT") (66 . 1) (410 . "Model"))
			    (list (cons 2 bn))
		    )
	     )
	   )
)
  (and
	(setq sourceBlock (fltr "EEKA3-EN"))
	(setq hiddenBlock (fltr "WD_M"))	    
	(setq sourceBlockAttv
	   (attfunc sourceBlock  (setq tagSource 
				      '("PLANOS->PROJNR" "COL1" "COL2" "COL3" "COL4"
				      	"COL5" "COL6"  "COL7" "COL8" "COL9" "COL10"))
				     )
		    )
	(setq projNumber (cadr (assoc (Car tagSource) sourceBlockAttv )))
	(setq hiddenBlockAttv  (car (attfunc hiddenBlock '("CHAR_H"))))
	(vla-put-textstring (last hiddenBlockAttv)
		    (setq result (substr (apply 'strcat
			      (mapcar '(lambda (s)
					 (strcat "," projNumber
						 "/" (cadr (assoc s sourceBlockAttv))
					 )
				       )
				      (Cdr tagSource)
			      ) 
			    ) 2 )
	      )
	  )
	)
  (print result)
  (princ)
  )
  

HTH

0 Likes
Message 5 of 5

Hans_Knol
Advocate
Advocate

thanks, this works

Hans Knol
0 Likes