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

Zoom Extents Showing "Empty Space", Swap a Block System-Wide

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Anonymous
1357 Views, 8 Replies

Zoom Extents Showing "Empty Space", Swap a Block System-Wide

When I zoom extents it zooms out too far. I can see a small rectangle that looks like text when you zoom out to far, but I can't select it or edit it. 

 

I figured out what it was by following these steps. I typed QTEXT and turned it on. Then I could see the outline of a box. When I open the Attribute Editor I see that the block is WD_WNV which is the vertical wire number block in AutoCAD Electrical. The value of the WIRENO attribute is three spaces. Because it is just spaces you do not see any grips on the block but when you zoom extents, AutoCAD still knows it is there and includes it in the extents.

 

At this point I could just delete the block, or delete the spaces so it is blank. The problem is that we have thousands of drawings that have this block there (because we always copy old designs to start new ones). I am trying to find a solution that will work system-wide, or a command I can run upon opening each drawing that will delete the block.

 

All of these drawings were created in AutoCAD LT, I have no idea how the WD_WNV block made it's way into these drawings. It is interesting that AutoCAD LT 2019 does not see this block when zooming extents, but AutoCAD Electrical 2021 does see it. Also of note, we have one user that zoom extents doesn't see the block in AutoCAD Electrical.

 

I thought that maybe I could run a Find and Replace every time I open a drawing and replace the three spaces with nothing but the command will not replace it if it leaves the text empty.

 

I also thought we could run a Block Swap on startup to replace that block and select the option to discard all old attribute values. However, this would remove any valid vertical wire numbers in AutoCAD Electrical drawings.

 

Does anyone know of a way to edit this block easily on thousands of drawings? Or, is there some LISP we could run on startup to edit the block? Is it possible to exclude a specific layer from consideration of the Zoom Extents (without freezing the layer)? Open to any ideas. Thanks in advance, sorry for the long question. I will attach an example drawing if anyone wants to look at it.

Zoom Problem.png

Zoom Problem2.png

  

Labels (2)
8 REPLIES 8
Message 2 of 9
pbejse
in reply to: Anonymous


@Anonymous wrote:

....

At this point I could just delete the block, or delete the spaces so it is blank. The problem is that we have thousands of drawings that have this block there (because we always copy old designs to start new ones). I am trying to find a solution that will work system-wide, or a command I can run upon opening each drawing that will delete the block.


Here's a short program that you can run  from startup. The code checks all attribute blocks, if and only if ALL of the attribute values evaluates to "" then it will deleted, Any of the values that only have space(s)  "   " will be converted to "" during evaluation.

 

It accepts any number of block names.

(defun _DelBlockWithEmptyAttributes (l)
  (vlax-for layout (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
    (vlax-for i (vla-get-block layout)
      (if (and
	    (vlax-write-enabled-p i)
            (= (vla-get-objectname i) "AcDbBlockReference")
	    (minusp (vlax-get i "HasAttributes"))
	    (member (strcase (vla-get-effectivename i)) l)
	    (vl-every '(lambda (at)
		    (eq (vl-string-trim " " (vla-get-textstring at)) ""))
	       (vlax-invoke i 'GetAttributes)
       		)
	    (vlax-write-enabled-p i)
          )
        (vla-Delete i)
      )
    )
  )
)

You call it like this [ notice all the names are in uppercase ]

(_DelBlockWithEmptyAttributes '("WD_WNV" "PBEBLOCK"))

Or if you want this exclusively to work ONLY with  "WD_WNV" block.

(defun c:DeleteBlankWD_WNV ()
  (vlax-for layout (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
    (vlax-for i (vla-get-block layout)
      (if (and
	    (vlax-write-enabled-p i)
            (= (vla-get-objectname i) "AcDbBlockReference")
	    (minusp (vlax-get i "HasAttributes"))
	    (eq (strcase (vla-get-effectivename i)) "WD_WNV")
	    (vl-every '(lambda (at)
		    (eq (vl-string-trim " " (vla-get-textstring at)) ""))
	       (vlax-invoke i 'GetAttributes)
       		)
	    (vlax-write-enabled-p i)
          )
        (vla-Delete i)
      )
    )
  )
)

command: DeleteBlankWD_WNV

 

Run this on your drawing and tell me how it goes.

HTH

Message 3 of 9
Moshe-A
in reply to: Anonymous

@Anonymous ,

 

You are running AutoCAD LT or full version?

 

Moshe

 

Message 4 of 9
Anonymous
in reply to: Moshe-A

The drawings were originally created in AutoCAD LT. Now we are using AutoCAD Electrical 2021.
Message 5 of 9
Anonymous
in reply to: pbejse

That worked perfectly. Thank you!
Message 6 of 9
pbejse
in reply to: Anonymous


@Anonymous wrote:
That worked perfectly. Thank you!

My pleasure @Anonymous

 

Cheers

 

 

Message 7 of 9
Anonymous
in reply to: pbejse

@pbejse I have a follow up question if you have the time. I found some of our old drawings that have a similar problem. This time it isn't a block, it is just text, and it just has a single space. Would you be able to write something to delete it as well?

Message 8 of 9
pbejse
in reply to: Anonymous

Hi Kamron,

 

I'm sure you are aware a regular purge on the command prompt can also delete empty strings. [ Text/Mtext ]

 

(command "-purge" "e")

 

or thru ssget

 

(if
  (setq ss (ssget "_X" '((0 . "*TEXT") (1 . " ,"))))
   (mapcar '(lambda (x) (entdel (cadr x))) (ssnamex ss))
)

 

For the sake of completeness, we will include that option on the previous code.

 

(defun c:DeleteBlankWD_WNV nil
  (vlax-for layout (vla-get-layouts
		     (vla-get-ActiveDocument (vlax-get-acad-object))
		   )
    (vlax-for i	(vla-get-block layout)
      (cond
	((and
	   (vlax-write-enabled-p i)
	   (member (vla-get-objectname i)
		   '("AcDbMText" "AcDbText" "AcDbBlockReference")
	   )
	   (or
	     (and
	       (vlax-property-available-p i "HasAttributes")
	       (minusp (vlax-get i "HasAttributes"))
	       (eq (strcase (vla-get-effectivename i)) "WD_WNV")
	       (vl-every
		 '(lambda (at)
		    (eq (vl-string-trim " " (vla-get-textstring at)) "")
		  )
		 (vlax-invoke i 'GetAttributes)
	       )
	     )
	     (and
	       (vlax-property-available-p i "TextString")
	       (eq (vl-string-trim " " (vla-get-textstring i)) "")
	     )
	   )
	 )
	 (vla-Delete i)
	)
      )
    )
  )
)

 

Main reason why the code is written in VL  so you may also use this for mulitple drawing files, not just by script but also with  ObjectDBX.

 

HTH

 

Message 9 of 9
Anonymous
in reply to: pbejse

@pbejse I didn't know that purge empty would see the space as empty so that is good to know. I like just including it all in the same code. Thanks again for your help, the code works great!

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report