Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete text or mtext in a block

7 REPLIES 7
Reply
Message 1 of 8
sudarsann
2279 Views, 7 Replies

Delete text or mtext in a block

Hi,

 

I have many blocks in drawings file. Few blocks are combine with polygon with text.

please guide me how to delete the text and mtext inside the blocks using lisp.

 

Regards

 

 

 

7 REPLIES 7
Message 2 of 8
_Tharwat
in reply to: sudarsann

Try this .

 

(defun c:Deltext(/ ss i sn name blockdefinition namelist)
;;; Tharwat 24. Mar. 2014 ;;;
  (cond (doc)
        (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  )
  (princ "\n Select Blocks to remove texts within ... ")
  (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
      (setq sn (ssname ss (setq i (1- i))))
      (if (not (member (setq name (cdr (assoc 2 (entget sn)))) namelist))
        (progn (setq namelist (cons name namelist))
               (vlax-for x (setq blockdefinition (vla-item (vla-get-blocks doc) name))
                 (if (and (eq :vlax-false (vla-get-isxref blockdefinition))
                          (eq :vlax-false (vla-get-islayout blockdefinition))
                          (wcmatch (vla-get-objectname x) "AcDb*Text")
                     )
                   (if (vlax-write-enabled-p x)
                     (vla-delete x))
                 )
               )
        )
      )
    )
    (princ)
  )
  (if ss
    (vla-regen doc acAllViewports)
  )
  (princ)
)
(vl-load-com)

 

Message 3 of 8
sudarsann
in reply to: sudarsann

Thanks for sending lisp.

but that lisp not working in autocad2004. Is it working in higher version?

 

Regards

Sudarsan

 

Message 4 of 8
hmsilva
in reply to: _Tharwat

Hi Tharwat,
I usually don't declare as a global a variable as "doc", because there may be another one with the same name, but it's only my opinion.
Your code is failing because the variable "doc", if don't exist in the document, the cond function will set the "doc" variable only if already exists, because the conditional function is the variable existence, not the non-existence...

Henrique

EESignature

Message 5 of 8
_Tharwat
in reply to: hmsilva


@hmsilva wrote:

Hi Tharwat,
I usually don't declare as a global a variable as "doc", because there may be another one with the same name, but it's only my opinion.
Your code is failing because the variable "doc", if don't exist in the document, the cond function will set the "doc" variable only if already exists, because the conditional function is the variable existence, not the non-existence...

Henrique


OMG , I have forgotten to add the two brackets before and after the variable in the cond function .Smiley Surprised

 

That is the result of not testing codes before posting sometimes . Smiley Very Happy

 

Thank you Henrique for the correction .

 

(cond (doc)
        ((setq doc (vla-get-activedocument (vlax-get-acad-object))))
  )

 

Message 6 of 8
hmsilva
in reply to: _Tharwat

You're welcome, Tarwat.

But I would use a different condition,

(cond ((not doc)
        (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  )

 The (doc) is testing a function...

 

Henrique

EESignature

Message 7 of 8
_Tharwat
in reply to: hmsilva


@hmsilva wrote:

But I would use a different condition,

(cond ((not doc)
        (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  )

 The (doc) is testing a function...

 

Henrique


If you would go that way , then use IF function instead Smiley Wink

For me I got used to call it the folloing way and I don't know why did I make it that way !

 

(or doc (setq doc .......

 

Message 8 of 8
nk
Explorer
in reply to: _Tharwat

Hello,

 

I am new here on the forum, So  is dont know if i am on the right place now.

 

I see that here is a lisp For deleting all text inside a block.

I need to have somthing similair. I need to find Mtext inside a lot of blocks en convert them to text. I dont want to explode the blocks

 

Is there a way to do this

 

nick

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost