Jump to content

Recommended Posts

Posted (edited)

 

On 7/26/2011 at 8:42 AM, irneb said:

You're welcome. Here's a mod which should handle nested blocks as well:




(defun c:DelText (/ ss eo blst bcol b)
 ;; Select the block references - all inserts
 (if (ssget "_:L" '((0 . "INSERT")))
   (progn
     (setq ss (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object))))
     (vlax-for eo ss
       (if (not (vl-position (vla-get-EffectiveName eo) blst)) ;Only add it if it's not already added
         (setq blst (cons (vla-get-EffectiveName eo) blst))
       )
     )
     (vla-Delete ss)
   )
 )
 ;; Step through block definitions and erase the text within
 (setq bcol (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object)))
       ss   0
 )
 (while (< ss (length blst))
   (setq b  (vla-Item bcol (nth ss blst)) ;Get block definition
         ss (1+ ss)
   )
   (if (and ;Omit layouts & xrefs dependent blocks
         (eq :vlax-false (vla-get-isxref b))
         (eq :vlax-false (vla-get-islayout b))
       )
     (vlax-for eo b ;Step through all items inside block definition
       (cond
         ((wcmatch (vla-get-ObjectName eo) "AcDbText,AcDbMText") ;Check if it's a text/mtext
          (vla-Delete eo)
         )
         ((and (wcmatch (vla-get-ObjectName eo) "AcDbBlockReference") ;If it's a block, and
               (not (vl-position (vla-get-EffectiveName eo) blst)) ;Not already added to list to be changed
          )
          (setq blst (append blst (list (vla-get-EffectiveName eo)))) ;Append its name to end of list
         )
       )
     )
   )
 )
 (vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acAllViewports)
 (princ)
)
 

 

 

Hi ,


Is there a way to have only specific text chosen and deleted?  My nested block has two text objects. One object has BASE in text and other one has different contents. 

 

I tried below command to search for text "BASE" , but I got too many arguments error

 

((wcmatch (vla-get-ObjectName eo) "AcDbText,AcDbMText" "*BASE*")

 

Reg,

NM

Edited by Niv
Posted

You'll need to change this:

((wcmatch (vla-get-ObjectName eo) "AcDbText,AcDbMText")

 

To:

((and (wcmatch (vla-get-ObjectName eo) "AcDbText,AcDbMText") 
      (wcmatch (strcase (vla-get-textstring eo)) "*BASE*")
 )

 

  • Thanks 1
  • 9 months later...
Posted

Hi,

 

Is there a way to select only the text with more than a certain number of bowels and then delete it? My blocks have a code and the block's name on the exact text. I only want to delete the title and leave the code. 

 

JJ,
TY

  • 2 years later...
Posted
On 7/23/2011 at 7:16 PM, irneb said:

What Lee means is you're stepping through the selection set. Which may contain hundreds (if not thousands) of copies of the same block. Then for each of those copies you go and edit that same block again and again and again ... You only need to edit it once, then all the copies gets updated anyway!

 

Something like this might be a lot more efficient:

(defun c:DelText (/ ss eo blst bcol b)
 ;; Select the block references - all inserts
 (if (ssget "_:L" '((0 . "INSERT")))
   (progn
     (setq ss (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object))))
     (vlax-for eo ss
       (if (not (vl-position (vla-get-EffectiveName eo) blst)) ;Only add it if it's not already added
         (setq blst (cons (vla-get-EffectiveName eo) blst))
       )
     )
     (vla-Delete ss)
   )
 )
 ;; Step through block definitions and erase the text within
 (setq bcol (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))))
 (foreach ss blst ;Reusing ss variable as block name
   (setq b (vla-Item bcol ss)) ;Get block definition
   (if (and ;Omit layouts & xrefs
          (eq :vlax-false (vla-get-isxref b))
          (eq :vlax-false (vla-get-islayout b))
        )
     (vlax-for eo b ;Step through all items inside block definition
       (if (wcmatch (vla-get-ObjectName eo) "AcDbText,AcDbMText") ;Check if it's a text/mtext
         (vla-Delete eo)
       )
     )
   )
 )
 (vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acAllViewports)
 (princ)
)
 

The ssget is only there to get hold of the names of the blocks. Actually this would usually still be less efficient than just going through the entire block collection, especially if there's hundreds of copies of the same block references all over the drawing.

 

BTW, I'm not too certain about the OP's request. Could this also include attributes? If such is the case then you'd need to add ",AcDbAttributeDefinition" into that wcmatch chek in my code. But also you'll need to add a call to AttSync for each block name.

Hi!
How do I set the text height?
For example, I need to delete the text in a block with a height of 2.5 mm. How do I do that?

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...