Take the attribute of the dynamic block that appear in the current visibility

Take the attribute of the dynamic block that appear in the current visibility

S_S_SS
Advocate Advocate
470 Views
5 Replies
Message 1 of 6

Take the attribute of the dynamic block that appear in the current visibility

S_S_SS
Advocate
Advocate

Hello every one 
i need to extract the attribute vale of the dynamic block in the current visibility 
then make a new layer with this value and put each block on its layer 
I've tried to make something and using lee mac functions about the dynamic block visibility 
but it still extract all the attributes on the block 
can someone help me about that ?? 
kindly see the attachment (DWG of an example and Auto lisp file)
Thanks in advance 

0 Likes
Accepted solutions (2)
471 Views
5 Replies
Replies (5)
Message 2 of 6

komondormrex
Mentor
Mentor
Accepted solution

hey there,

check the following

(defun c:c_vis_att_layer ()
  (if (setq insert_sset (ssget '((0 . "insert") (66 . 1))))
    	(foreach insert (vl-remove-if-not '(lambda (insert) (minusp (vlax-get insert 'isdynamicblock)))
	     			           (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex insert_sset))))
			)
		(if (vl-some '(lambda (dyn_property) (setq dyn_value (vlax-variant-value (vla-get-value dyn_property))) (= "Visibility1" (vla-get-propertyname dyn_property)))
			      (vlax-invoke insert 'getdynamicblockproperties)
		    )
		    (entmod (append (entget (vlax-vla-object->ename insert)) (list (cons 8 (getpropertyvalue (vlax-vla-object->ename insert) dyn_value)))))
		)
	)
  )
  (princ)
)
Message 3 of 6

S_S_SS
Advocate
Advocate

Thanks sir 
it works correctly 
now the dynamic block that i work on it i find more attributes on it in the current visibility 
so can we add another feature that it take the value of the attribute in the current visibility and also it's tag contain "lay" ??

I've tried to make this code but it doesn't work 

(defun c:c_2 ()
  (if (setq insert_sset (ssget '((0 . "insert") (66 . 1))))
      (foreach insert (vl-remove-if-not 
                       '(lambda (insert) 
                          (minusp (vlax-get insert 'isdynamicblock)))
                       (mapcar 'vlax-ename->vla-object 
                               (vl-remove-if 'listp 
                                             (mapcar 'cadr (ssnamex insert_sset))))
                      )
        (if (vl-some 
             '(lambda (dyn_property) 
                (setq dyn_value (vlax-variant-value (vla-get-value dyn_property))) 
                (= "Visibility1" (vla-get-propertyname dyn_property)))
             (vlax-invoke insert 'getdynamicblockproperties)
            )
          ;; Modify the block if the condition is met
          (entmod (append (entget (vlax-vla-object->ename insert)) 
                          (list (cons 8 (getpropertyvalue (vlax-vla-object->ename insert) dyn_value))))
          )
        )

        ;; Process attributes with "lay" in the tag
        (foreach att (vlax-invoke insert 'getattributes)
          (if (and (eq 'STR (type (vla-get-tagstring att))) ;; Check if it has a tag string
                   (wcmatch (strcase (vla-get-tagstring att)) "*LAY*")) ;; Match tag containing "lay"
            (progn
              ;; Get and display the attribute's value
              (setq att_value (vla-get-textstring att))
              (princ (strcat "\nAttribute with 'lay' in tag found: " att_value))
            )
          )
        )
      )
  )
  (princ)
)

 
thanks in advance 

0 Likes
Message 4 of 6

komondormrex
Mentor
Mentor
Accepted solution

check this

 

(defun c:c_2 ()
  (if (setq insert_sset (ssget '((0 . "insert") (66 . 1))))
      (foreach insert (vl-remove-if-not 
                       '(lambda (insert) 
                          (minusp (vlax-get insert 'isdynamicblock)))
                       (mapcar 'vlax-ename->vla-object 
                               (vl-remove-if 'listp 
                                             (mapcar 'cadr (ssnamex insert_sset))))
                      )
        (if (vl-some 
             '(lambda (dyn_property) 
                (setq dyn_value (vlax-variant-value (vla-get-value dyn_property))) 
                (= "Visibility1" (vla-get-propertyname dyn_property)))
             (vlax-invoke insert 'getdynamicblockproperties)
            )
          ;; Modify the block if the condition is met
          (entmod (append (entget (vlax-vla-object->ename insert)) 
                          (list (cons 8 (getpropertyvalue (vlax-vla-object->ename insert) dyn_value))))
          )
        )

        ;; Process attributes with "lay" in the tag

		(foreach att (vlax-invoke insert 'getattributes)
          (if (and
		  		   (wcmatch (strcase (vla-get-tagstring att)) "*LAY*") ;; Match tag containing "lay"
				   (minusp (vlax-get att 'visible))
			  )
            	(progn
            	  ;; Get and display the attribute's value
            	  (setq att_value (vla-get-textstring att))
            	  (princ (strcat "\nAttribute with 'lay' in tag found, value: " att_value))
            	)
          )
        )
      )
  )
  (princ)
)

 

you do not need to check if attributes's tagstring is a string, it is always the string.

Message 5 of 6

S_S_SS
Advocate
Advocate
Thanks for that sir
0 Likes
Message 6 of 6

komondormrex
Mentor
Mentor

your welcome