vernonlee 发表于 2022-7-5 20:27:03

HELP:LISP to delete all text,

I came across LISP routine to remove dimension & hatches but not text & leader lines.
 
Anyone with such a routine to delete all text & leaders (including within blocks & nested block)
 
Thanks

hanhphuc 发表于 2022-7-5 20:40:25

 
sorry if im not quite understand
 
normally we use to filter selections, ss
then erase, example TEXT , MTEXT

(defun c:TEST1 ( / ss) ; TEXT& MTEXT(setq ss (ssget        "_X"'((0 . "*TEXT")))) ;_ end of setq(command "_erase" ss)(princ))
ie: a bit study some method ssget here,
then you can mod yourself
 
example: filter leader &associated Mtext
can try replace the (setq ss ...) to above code in c:TEST1

(setq ss (ssget        "_:L"        (list '(-4 . "")) ;_ end of list        ) ;_ end of ssget   ) ;_ end of setq
 
 
;example delete entity (without filtering ssget)
TEXT, MTEXT, DIMENSION, etc.. (which dxf index 1)

(defun c:test2 ( / ss)(if(setq ss (ssget "_X" ))(foreach en(vl-remove-if ''((x) (not(cdr (assoc 1 (entget x)))))(acet-ss-to-list ss)) ; express tool(if en (entdel en))(princ)) ));p/s: this method is not good practice, just an alternative reference;filter by ssget is the best practice
 
for nested try similar thread
 
HTH

vernonlee 发表于 2022-7-5 20:51:38

Hi HT. WIll reply in detail when i am back from vacation.
 
Thanks

vernonlee 发表于 2022-7-5 21:01:08

Basically i am looking for something similar to this for text & leader lines.
 
Below is what i found for hatch & dimension
 

(defun c:DIMDEL ( / d l )   (setq d (vla-get-activedocument (vlax-get-acad-object)))   (vlax-for a (vla-get-layers d)       (if (eq :vlax-true (vla-get-lock a))         (progn               (vla-put-lock a :vlax-false)               (setq l (cons a l))         )       )   )   (vlax-for b (vla-get-blocks d)       (if (eq :vlax-false (vla-get-isxref b))         (vlax-for o b               (if (wcmatch (vla-get-objectname o) "AcDb*Dimension*")                   (vla-delete o)               )         )       )   )   (foreach a l (vla-put-lock a :vlax-true))   (vla-regen d acallviewports)   (princ))---------------------------------------------------------------------------------------------------------------------(defun C:HatchDel ()(delete-all-hatch))(defun delete-all-hatch (/ adoc *error*)(defun *error* (msg)   (setvar "MODEMACRO" "")   (princ msg)   (vla-regen aDOC acactiveviewport)   (bg:progress-clear)   (bg:layer-status-restore)   (princ) ) ;_ end of defun (defun _loc-delete-items ()   (if    (= (vla-get-IsXref Blk) :vlax-false)   (progn   (setq count 0)   (if (> (vla-get-count Blk) 100)   (bg:progress-init       (strcat (vla-get-name Blk) " :")       (vla-get-count Blk)   ) ;_ end of bg:progress-init   (progn       (setvar "MODEMACRO" (vla-get-name Blk))   ) ;_ end of progn   ) ;_ end of if   (vlax-for Obj Blk   (if (= (vla-get-ObjectName Obj) "AcDbHatch")         (vl-catch-all-apply 'vla-delete (list Obj))   ) ;_ end of if   ) ;_ end of vlax-for   (bg:progress-clear)   ) ;_ end of progn   ) ;_ end of if ) ;_ end of defun (setq    aDOC       (vla-get-activedocument (vlax-get-acad-object)) ) ;_ end of setq (bg:layer-status-save) (vlax-for Blk (vla-get-Blocks aDOC)   (_loc-delete-items)   ) (bg:layer-status-restore)   (vla-regen aDOC acActiveViewport) (princ)) ;_ end of defun(defun bg:layer-status-restore ()   (foreach item *BG_LAYER_LST*   (if (not (vlax-erased-p (car item)))       (vl-catch-all-apply         '(lambda ()            (vla-put-lock (car item) (cdr (assoc "lock" (cdr item))))            (vla-put-freeze (car item) (cdr (assoc "freeze" (cdr item))))            ) ;_ end of lambda         ) ;_ end of vl-catch-all-apply       ) ;_ end of if   ) ;_ end of foreach   (setq *BG_LAYER_LST* nil)   ) ;_ end of defun (defun bg:layer-status-save ()   (setq *BG_LAYER_LST* nil)   (vlax-for item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))   (setq *BG_LAYER_LST* (cons (list item                                 (cons "freeze" (vla-get-freeze item))                                 (cons "lock" (vla-get-lock item))                                 ) ;_ end of cons                           *BG_LAYER_LST*                           ) ;_ end of cons         ) ;_ end of setq   (vla-put-lock item :vlax-false)   (if (= (vla-get-freeze item) :vlax-true)   (vl-catch-all-apply '(lambda () (vla-put-freeze item :vlax-false))))   ) ;_ end of vlax-for   ) ;_ end of defun(defun bg:progress-init (msg maxlen) ;;; msg - ñîîáùåíèå èëè ïóñòàÿ ñòðîêà ;;; maxlen - ìàêñèìàëüíîå êîëè÷åñòâî (setq *BG:PROGRESS:OM* (getvar "MODEMACRO")) (setq *BG:PROGRESS:MSG* (vl-princ-to-string msg)) (setq *BG:PROGRESS:MAXLEN* maxlen) (setq *BG:PROGRESS:LPS* '-1)(princ) )(defun bg:progress ( currvalue / persent str1 count) (if *BG:PROGRESS:MAXLEN*   (progn (setq persent (fix (/ currvalue 0.01 *BG:PROGRESS:MAXLEN*))) ;;;Êàæäûå 5 % (setq count (fix(* persent 0.2))) (setq str1 "") (if (/= count *BG:PROGRESS:LPS*)   (progn   ;;(setq str1 "")   (repeat persent (setq str1 (strcat str1 "|")))   )   )      ;;; currvalue - òåêóùåå çíà÷åíèå   (setvar "MODEMACRO"             (strcat (vl-princ-to-string *BG:PROGRESS:MSG*)                     " "                     (itoa persent)                     " % "                     str1                     )             )   (setq *BG:PROGRESS:LPS* persent) )   ) )    (defun bg:progress-clear () (setq *BG:PROGRESS:MSG* nil) (setq *BG:PROGRESS:MAXLEN* nil) (setq *BG:PROGRESS:LPS* nil) (setvar "MODEMACRO" (vl-princ-to-string *BG:PROGRESS:OM*)) ;;;(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acactiveviewport) (princ) )

hanhphuc 发表于 2022-7-5 21:08:42

 

(defun c:DIMDEL ( / d l )......(if (wcmatch (vla-get-objectname o) "AcDb*Dimension*")...)
 
Try replace it, just by filtering objectname
a bit study basic & practise, you get benefited

"AcDb*Leader*" ; leader ,mleaderor"AcDb*Text*" ; Text, Mtext

vernonlee 发表于 2022-7-5 21:16:42

 
It worked bro!
 
Errr...how to combine leader,text & dimension together?So that it can run in 1 command.
 
I tried combining the above code with different variation but ended with error.

hanhphuc 发表于 2022-7-5 21:21:35

 
it's ok you can post error code here, members in forum will assist you.
 
how did you combine?
so i just assume your error was due to not separated with commas

"AcDb*Leader*,AcDb*Text*,AcDb*Dimension*"

vernonlee 发表于 2022-7-5 21:27:53

 
hahs ya. I did not include comma among other variations i tried.
 
Thanks dude
页: [1]
查看完整版本: HELP:LISP to delete all text,