Hi,
I need a lisp code to burst all "blocks with text/attributes inside" in selected area.
That means user should select an area (window selection) and lisp program should be find all blocks with TEXT or ATTRIB inside in selected area and then applys "BURST express tools" command to all these blocks in the selected area by user.
can anybody help me?
Thanks
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
(defun c:bu (/ ss) (if (setq ss (ssget '((0 . "INSERT") (66 . 1)))) (progn (sssetfirst nil ss) (c:burst) ) ) )
I dont get the part where you need to burst the TEXT. How does that work?
Hi Pbejse,
Thanks for your code:
(defun c:bu (/ ss) (if (setq ss (ssget '((0 . "INSERT") (66 . 1)))) ;;(66 . 1): a series of attribute entities is expected to follow the insert (progn (sssetfirst nil ss) ;;Do not call sssetfirst when AutoCAD is in the middle of executing a command. (c:burst) ) ) )
But, this code just works on "Blocks with Attributes". It does not works on "Blocks with TEXT inside".
Thanks,
Hello from France
Do you mean that you have standard Text Entities inside Blocks
and you want to "extract" (Copy) them as standard Text Entities ?
Bye, Pat
Patrice BRAUD
@aqdam1978 wrote:.....
This code just works on "Blocks with Attributes". It does not works on "Blocks with TEXT inside".
Thanks,
I know, Are you wanting to select only blocks with attributes and/or text inside the block? or "you want to "extract" (Copy) them as standard Text Entities" as per Braudpats reply?
EDIT: Quickly written
(defun c:bu (/ blocks ss lst txtd bn n i x) (vl-load-com) (setvar 'pickfirst 1) (setq Blocks (Vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (if (setq ssb (ssadd) lst nil txtd nil ss (ssget "_x" (list '(0 . "INSERT")(cons 410 (getvar 'ctab)))) ) (progn (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))) bn (vla-get-effectivename e) x nil ) (if (cond ((minusp (vlax-get e 'HasAttributes)) T) ((member bn txtd) T) ((not (member bn lst)) (setq bl (vla-item Blocks bn) n -1 ) (vl-some '(lambda (k) (if (member k '("AcDbText" "AcDbMText")) T ) ) (vlax-for itm bl (setq x (cons (vla-get-objectname itm) x)) ) ) ) ) (progn (ssadd (ssname ss i) ssb) (setq lst (Cons bn lst) txtd (cons bn txtd) x nil ) ) ) ) (if (ssname ssb 0) (progn (sssetfirst nil ssb)(c:burst))) )(princ "\nNone Selected") ) (princ) )
HTH
EDIT: a thought occured to me.. If the users are to select on screen why the need for a lisp? and just Burst selected objects? I'm missing something obvious here Abbas 🙂
for this to have some kind of meaning at all. better use
(setq ss (ssget "_x" (list '(0 . "INSERT")(cons 410 (getvar 'ctab)))))
Hello Pbejse
Beautiful routine ---> Bravo !
It works fine on my MAP 2012 32 bits and on my AutoCAD 2014 32 bits on Blocks with Texts inside ...
Please may I ask for a small improvment :
Be able to have a standard AutoCAD selection because your present routine acts on the WHOLE DWG ...
Bye, Pat
Patrice BRAUD
@braudpat wrote:
Hello Pbejse
Beautiful routine ---> Bravo !
It works fine on my MAP 2012 32 bits and on my AutoCAD 2014 32 bits on Blocks with Texts inside ...
Please may I ask for a small improvment :
Be able to have a standard AutoCAD selection because your present routine acts on the WHOLE DWG ...
Bye, Pat
Why thank you patrice, at least you found a good use for this code. like i said there's no point in running this routine if you are to select on screen as you can "see" what block has an attribute and/or text.
But hey, why not? here it is:
Replace this:
(/ blocks ss lst txtd bn n i x) and (setq ssb (ssadd) lst nil txtd nil ss (ssget "_x" (list '(0 . "INSERT")(cons 410 (getvar 'ctab)))) )
With this:
(/ blocks ss lst bn n i x)
and
(setq ssb (ssadd) lst ni ss (ssget "_:L" '((0 . "INSERT"))) )
Declaring the variable txtd as local and a prompt for selection.
Have fun 🙂
Cheers Pat
Hi Pbejse,
Thank you for your code:
(defun c:bu (/ blocks ss lst bn n i x) (vl-load-com) (setvar 'pickfirst 1) (setq Blocks (Vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (if (setq ssb (ssadd) lst ni ss (ssget "_:L" '((0 . "INSERT"))) ) (progn (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))) bn (vla-get-effectivename e) x nil ) (if (cond ((minusp (vlax-get e 'HasAttributes)) T) ((member bn txtd) T) ((not (member bn lst)) (setq bl (vla-item Blocks bn) n -1 ) (vl-some '(lambda (k) (if (member k '("AcDbText" "AcDbMText")) T ) ) (vlax-for itm bl (setq x (cons (vla-get-objectname itm) x)) ) ) ) ) (progn (ssadd (ssname ss i) ssb) (setq lst (Cons bn lst) txtd (cons bn txtd) x nil ) ) ) ) (if (ssname ssb 0) (progn (sssetfirst nil ssb)(c:burst))) )(princ "\nNone Selected") ) (princ) )
you are right, we can see those block and select them one by one!
But I have very big drawing with more than 230 blocks that have *TEXT/ATTRIB inside
and many blocks that has not any text/attrib inside.
So, your code is a big time saving routine for me.
Thanks,
Hi Pbejse,
I have two question:
-why you never used (setq ss nil) in your codes!?
-what happen to "txtd" variable?
because you removed from local variables and you used in 2 location of program:
((member bn txtd) T)
(setq txtd (cons bn txtd))
Thanks,
Abbas
@aqdam1978 wrote:
I have two question:
-why you never used (setq ss nil) in your codes!?
ss variable change for every run. The only time i set a variable to nil regardless if it is declared local is when i include the function cons , that is to avoid compounding the list at every run due to user cancelation [ESC] as i rarely include an error trap on my routine i posts here in the forum.
aqdam1978 wrote:...-what happen to "txtd" variable?
Looking back now. i guess i made a blunder on that one 😄 , [silly me] . I'll modify the code tomorrow. dont have CAD with me right now.
Cheers
Hi Pbejse,
The attached lisp code has many errors!:
(defun c:bu (/ ss) (vl-load-com) (setq Blocks (Vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (defun _TextorAtt (bn e) (vlax-for n (vla-item (Vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) bn) (if (member (vla-get-objectname n) '("AcDbAttribute" "AcDbText" "AcDbMText")) (if (setq ssb (ssadd) x nil lst nil txtd nil ss (ssget "_:L" (list '(0 . "INSERT") (cons 410 (getvar 'Ctab)))) ) (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (if (cond ((minusp (vlax-get e 'HasAttributes)) T) ((member (setq bn (vla-get-effectivename e)) txtd) T) ((not (member bn lst)) (setq bl (vla-item Blocks bn) n -1) (vl-some '(lambda (k) (if (member k '("AcDbText" "AcDbMText")) T)) (vlax-for itm bl (setq x (cons (vla-get-objectname itm) x))) )) ) (setq ssb (ssadd (ssname ss i)) x nil lst (Cons bn lst) txtd (cons bn txtd ))) ) (_TextorAtt bn e) (setq vla-get-effectivename (vlax-ename->vla-object e) (progn (sssetfirst nil ss) (c:burst) ) ) ) (vla-get-objectname (vlax-ename->vla-object (car (nentselp)))) (vlax-for it (vla-item (Vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) bn) (setq a (cons it a))) collection ;|«Visual LISP© Format Options» (78 2 40 2 nil "end of " 75 9 0 0 0 T T nil T) ;*** DO NOT add text below the comment! ***|;
Did you check it yourself?
Thanks,
Abbas
Hi Pbejse,
you code does does not work again!:
(defun c:bu (/ ss) (vl-load-com) (setq Blocks (Vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)) ) ) (defun _TextorAtt (bn e) (vlax-for n (vla-item (Vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)) ) bn ) (if (member (vla-get-objectname n) '("AcDbAttribute" "AcDbText" "AcDbMText") ) (if (setq ssb (ssadd) x nil lst nil txtd nil ss (ssget "_:L" (list '(0 . "INSERT") (cons 410 (getvar 'Ctab))) ) ) (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))) ) (if (cond ((minusp (vlax-get e 'HasAttributes)) T) ((member (setq bn (vla-get-effectivename e)) txtd) T) ((not (member bn lst)) (setq bl (vla-item Blocks bn) n -1 ) (vl-some '(lambda (k) (if (member k '("AcDbText" "AcDbMText")) T ) ) (vlax-for itm bl (setq x (cons (vla-get-objectname itm) x)) ) ) ) ) (setq ssb (ssadd (ssname ss i)) x nil lst (Cons bn lst) txtd (cons bn txtd) ) ) ) (_TextorAtt bn e) (setq vla-get-effectivename (vlax-ename->vla-object e) (progn (sssetfirst nil ss) (c:burst) ) ) ) ) ) ) )
(defun c:bu (/ blocks ss lst bn n i x) (vl-load-com) (setvar 'pickfirst 1) (setq Blocks (Vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) (if (setq ssb (ssadd) lst ni ss (ssget "_:L" '((0 . "INSERT"))) ) (progn (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))) bn (vla-get-effectivename e) x nil ) (if (cond ((minusp (vlax-get e 'HasAttributes)) T) ((member bn txtd) T) ((not (member bn lst)) (setq lst (Cons bn lst) bl (vla-item Blocks bn) n -1 ) (if (vl-some '(lambda (k) (if (member k '("AcDbText" "AcDbMText")) T ) ) (vlax-for itm bl (setq x (cons (vla-get-objectname itm) x)) ) ) (setq txtd (cons bn txtd))) ) ) (progn (ssadd (ssname ss i) ssb) (setq x nil ) ) ) ) (if (ssname ssb 0) (progn (sssetfirst nil ssb)(c:burst))) )(princ "\nNone Selected") ) (princ) )
Tell you what. edit your replies and remove the codes so there wouldnt be any confusion as to what is the latest and greatest.
Apparently i atached the wrong code to start with 😄
Thank you Pbejse,
I just wondering why you did not use "txtd" variable as a local variable?
you are used this variable in 2 line:
((member bn txtd) T)
(setq txtd (cons bn txtd))
Thank you in advance
@aqdam1978 wrote:Thank you Pbejse,
I just wondering why you did not use "txtd" variable as a local variable?
Thank you in advance
Reason for that abbas is when you run the routine the again time within the same cad session it ends at ths line if the block were already process.
((member (setq bn (vla-get-effectivename e)) txtd) T)
and doesnt need to "re-check" if it has a TEXT/MTEXT,<at least that was the plan 🙂 >
HTH