How do I select a block, and use "Cond" based on the name of the selected blokk?

How do I select a block, and use "Cond" based on the name of the selected blokk?

tamas.halasz
Enthusiast Enthusiast
1,238 Views
10 Replies
Message 1 of 11

How do I select a block, and use "Cond" based on the name of the selected blokk?

tamas.halasz
Enthusiast
Enthusiast

Hello. Im trying to copy the contents of text entities into certain row(s) of blocks, and i got it to work, but i'm trying to modify it to be useable with all of our blocks. The code below works, but not in the most optimal way. After selecting the block i have to select it again, and that is the step i'm trying to skip. I'm sure there is a way to work with a block and its name at the same time. I attached a block for testing. Side note: I have no idea what i'm doing 😄 

Any help is appreciated! Thank you! 

 

(defun c:DBATT  (/ st st2 e e2 ss blkname)

(setq blkname (cdr (assoc 2 (entget (car (entsel "\Select a block: "))))))

(cond
  ((= blkname "N1")
(while
(if (and (setq st (car (entsel "\nVĂĄlaszd ki az azonosĂ­tĂłt :")))
          (eq (cdr (assoc 0 (setq e (entget st)))) "TEXT")
          (princ "\nVĂĄlasz ki egy akna blokkot :")
          (setq ss (ssget "_:S" '((0 . "INSERT") (66 . 1))))
          )
   ((lambda (i / sn)
      (while (setq sn (ssname ss (setq i (1+ i))))
        (mapcar
          '(lambda (x)
             (if (eq (strcase (vla-get-tagstring x)) "LOCATION")
               (vla-put-textstring x (cdr (assoc 1 e)))))
          (vlax-invoke
            (vlax-ename->vla-object sn)
            'getattributes))
        ))
     -1)
   )
)

  ) ; end cond 1

  ((= blkname "N2")
(while
(if (and (setq st (car (entsel "\nVĂĄlaszd ki az azonosĂ­tĂłt :")))
          (eq (cdr (assoc 0 (setq e (entget st)))) "TEXT")
          (princ "\nVĂĄlasz ki egy akna blokkot :")
          (setq ss (ssget "_:S" '((0 . "INSERT") (66 . 1))))
          )
   ((lambda (i / sn)
      (while (setq sn (ssname ss (setq i (1+ i))))
        (mapcar
          '(lambda (x)
             (if (eq (strcase (vla-get-tagstring x)) "LOCATION")
               (vla-put-textstring x (cdr (assoc 1 e)))))
          (vlax-invoke
            (vlax-ename->vla-object sn)
            'getattributes))
        ))
     -1)
   )
)
   ) ; end cond 2

) ; end cond stmt
)(vl-load-com)
0 Likes
Accepted solutions (1)
1,239 Views
10 Replies
Replies (10)
Message 2 of 11

ВeekeeCZ
Consultant
Consultant

Lost! 

You select a block, get a name... then what. What differs part N2 from N1. Different att name? 

0 Likes
Message 3 of 11

tamas.halasz
Enthusiast
Enthusiast

N2 has different attribute rows. I think i explained poorly what i'm trying to do. 😐

0 Likes
Message 4 of 11

ВeekeeCZ
Consultant
Consultant

Make a dwg that illustrates a workflow - states before and after (desired outcome) for N1 block and N2 block too. 

0 Likes
Message 5 of 11

tamas.halasz
Enthusiast
Enthusiast

GYAZO GIF  GIF of the action.  I also attach the original code, wich i'm trying to modify. My main goal is to be able to fill different blocks attributes by copying text into it without making a new command for every block.

The thing i cant find a soultion for is how do i get the name of the block i select with the following line?

(setq ss (ssget "_:S" '((0 . "INSERT") (66 . 1))))
(defun c:DBATT  (/ st st2 e e2 ss)
 (while
(if (and (setq st (car (entsel "\nVĂĄlaszd ki az azonosĂ­tĂłt :")))
          (eq (cdr (assoc 0 (setq e (entget st)))) "TEXT")
          (setq st2 (car (entsel "\nVĂĄlaszd ki a tĂ­pust :")))
          (eq (cdr (assoc 0 (setq e2 (entget st2)))) "TEXT")
          (princ "\nVĂĄlasz ki egy DOBOZ_OSZLOP/FALI blokkot :")
          (setq ss (ssget "_:S" '((0 . "INSERT") (66 . 1))))
          )
   ((lambda (i / sn)
      (while (setq sn (ssname ss (setq i (1+ i))))
        (mapcar
          '(lambda (x)
             (if (eq (strcase (vla-get-tagstring x)) "NO.")
               (vla-put-textstring x (cdr (assoc 1 e)))))
          (vlax-invoke
            (vlax-ename->vla-object sn)
            'getattributes))
        ))
     -1)
   )
   ((lambda (i / sn)
      (while (setq sn (ssname ss (setq i (1+ i))))
        (mapcar
          '(lambda (x)
             (if (eq (strcase (vla-get-tagstring x)) "TYPE")
               (vla-put-textstring x (cdr (assoc 1 e2)))))
          (vlax-invoke
            (vlax-ename->vla-object sn)
            'getattributes))
        ))
     -1)
)
 (princ)
 )(vl-load-com)

(defun c:AKATT  (/ st st2 e e2 ss)
 (while
(if (and (setq st (car (entsel "\nVĂĄlaszd ki az azonosĂ­tĂłt :")))
          (eq (cdr (assoc 0 (setq e (entget st)))) "TEXT")
          (princ "\nVĂĄlasz ki egy akna blokkot :")
          (setq ss (ssget "_:S" '((0 . "INSERT") (66 . 1))))
          )
   ((lambda (i / sn)
      (while (setq sn (ssname ss (setq i (1+ i)))) 
        (mapcar
          '(lambda (x)
             (if (eq (strcase (vla-get-tagstring x)) "LOCATION")
               (vla-put-textstring x (cdr (assoc 1 e)))))
          (vlax-invoke
            (vlax-ename->vla-object sn)
            'getattributes))
        ))
     -1)
   )
)
 (princ)
 )(vl-load-com)
0 Likes
Message 6 of 11

ВeekeeCZ
Consultant
Consultant

How would the program know whether selected text serves as "Location", "Type" or "No."? You would have 2 routines, first fills "Locates" to any block... and second, that fill "No" and "Type" also to any selected blocks (if the tag name is preset)?

 

Also would please translate the prompts to english?

 

Let's say you will select block N1. That holds 3 attributes. So you want to be prompted to select 3 texts for each att?

0 Likes
Message 7 of 11

ВeekeeCZ
Consultant
Consultant

Maybe this will help...

 

(defun c:BAttFillAll ( / en bn att txt)

  (while (setq en (ssget "_+.:E:S" '((0 . "INSERT") (66 . 1))))
    (setq en (ssname en 0)
	  bn (cdr (assoc 2 (entget en))))
    (foreach att (mapcar 'vla-get-tagstring (vlax-invoke (vlax-ename->vla-object en) 'getattributes))
      (if (and (setq txt (car (entsel (strcat "\nBlock '" bn "': Select text for " att " <skip>: "))))
	       (= "TEXT" (cdr (assoc 0 (entget txt))))
	       (setq txt (cdr (assoc 1 (entget txt))))
	       )
	(mapcar '(lambda (x)
		   (if (= (vla-get-tagstring x) att)
		     (vla-put-textstring x txt)))
		(vlax-invoke (vlax-ename->vla-object en) 'getattributes)))))
  (princ)
  )
0 Likes
Message 8 of 11

tamas.halasz
Enthusiast
Enthusiast

This row determines which attribute i'm copying into. I want to leave the rest alone. 

(if (eq (strcase (vla-get-tagstring x)) "LOCATION")

cad.jpg

Is it possible to get the name of the block with from this selection set?

(setq ss (ssget "_:S" '((0 . "INSERT") (66 . 1))))
0 Likes
Message 9 of 11

ВeekeeCZ
Consultant
Consultant
(setq ss (ssget "_X" (list '(0 . "INSERT") (assoc (entget (car (entsel "select a block: " )))))))
; or in your case:
(setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blkname))))

It selects all blocks of the given name.

0 Likes
Message 10 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

@tamas.halasz wrote:

....

Is it possible to get the name of the block with from this selection set?

(setq ss (ssget "_:S" '((0 . "INSERT") (66 . 1))))

If it's not a dynamic  Block:

(cdr (assoc 2 (entget (ssname ss 0))))
Kent Cooper, AIA
0 Likes
Message 11 of 11

tamas.halasz
Enthusiast
Enthusiast

should have straight up just ask for this. 🙂 Thank you both for your help. 

0 Likes