Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Member
NESSEL
Posts: 6
Registered: ‎09-16-2010
Message 1 of 10 (665 Views)
Accepted Solution

DELETE DIMENSIONS INSIDE BLOCKS

665 Views, 9 Replies
12-02-2010 01:29 AM

Hi all,

 

I need a lisp routine which will delete all the dimensions inside selected block or blocks, including nested blocks inside.

 

Can anybody help please?

 

Thanx...

Today is your lucky day..

 

on my way to overcoming my fear of recursive programming, earlier

I happen to be playing around on a code for eradicating unwanted entities oinside a block

 

 

I tweaked it a lttle to fit your neeeds

 

;; Credit to Jummy BergMark ;;
;; For DeleteObjectFromBlock Routine ;;
;; Manusoft for the Recursive Routine ;;
;; Me for tweaking it for you ;;
(defun C:FXB (/ ELST ENAM ESEL BNAM FLST)
(vl-load-com)
(setq Dsdwg (vla-get-activedocument (vlax-get-acad-object)))
(setq ESEL (entsel "\nSelect block: ")
ENAM (car ESEL)
ELST (entget ENAM)
BNAM (cdr (assoc 2 ELST))
FLST nil
)
(fix1 BNAM)
(vl-cmdf "regen")
(prin1)
)
(defun FIX1 (BNAM / BENAM)
(if (not (member BNAM FLST))
(progn
(setq FLST (cons BNAM FLST)
BENAM (tblobjname "block" BNAM)
)
(while (setq BENAM (entnext BENAM))
;(print (entget BENAM))
(if (= (cdr (assoc 0 (entget BENAM))) "INSERT")
(fix1 (cdr (assoc 2 (entget BENAM))))
(if (= (cdr (assoc 0 (entget BENAM))) "DIMENSION")
(progn
(setq Dim2Del (vlax-ename->vla-object BENAM)
blk (vla-ObjectIdToObject
Dsdwg
(vla-get-ownerID Dim2Del)
)
)
(vla-delete Dim2Del)
(vla-get-count blk)
)
)
)
)
)
)
(princ)
)

 Hope this helps

 

*Expert Elite*
pbejse
Posts: 2,515
Registered: ‎11-24-2009
Message 2 of 10 (652 Views)

Re: DELETE DIMENSIONS INSIDE BLOCKS

12-02-2010 03:30 AM in reply to: NESSEL

Today is your lucky day..

 

on my way to overcoming my fear of recursive programming, earlier

I happen to be playing around on a code for eradicating unwanted entities oinside a block

 

 

I tweaked it a lttle to fit your neeeds

 

;;	Credit to Jummy BergMark		;;
;;	For DeleteObjectFromBlock Routine	;;
;;	Manusoft for the Recursive Routine	;;
;;	Me for tweaking it for you		;;


(defun C:FXB (/ ELST ENAM ESEL BNAM FLST)
  (vl-load-com)
  (setq Dsdwg (vla-get-activedocument (vlax-get-acad-object)))
  (setq	ESEL (entsel "\nSelect block: ")
	ENAM (car ESEL)
	ELST (entget ENAM)
	BNAM (cdr (assoc 2 ELST))
	FLST nil
  )
  (fix1 BNAM)
  (vl-cmdf "regen")
  (prin1)
)


(defun FIX1 (BNAM / BENAM)
  (if (not (member BNAM FLST))
    (progn
      (setq FLST  (cons BNAM FLST)
	    BENAM (tblobjname "block" BNAM)
      )
      (while (setq BENAM (entnext BENAM))
					;(print (entget BENAM))
	(if (= (cdr (assoc 0 (entget BENAM))) "INSERT")
	  (fix1 (cdr (assoc 2 (entget BENAM))))
	  (if (= (cdr (assoc 0 (entget BENAM))) "DIMENSION")
	    (progn
	      (setq Dim2Del (vlax-ename->vla-object BENAM)
		    blk	    (vla-ObjectIdToObject
			      Dsdwg
			      (vla-get-ownerID Dim2Del)
			    )
	      )
	      (vla-delete Dim2Del)
	      (vla-get-count blk)
	    )
	  )
	)
      )
    )
  )
  (princ)
)

 Hope this helps

 

Active Member
NESSEL
Posts: 6
Registered: ‎09-16-2010
Message 3 of 10 (636 Views)

Re: DELETE DIMENSIONS INSIDE BLOCKS

12-02-2010 06:03 AM in reply to: pbejse

Hi again,

 

Really my lucky day! :smileyhappy: thank you for your help.

 

Great work :smileyhappy:

Active Member
tkunsman
Posts: 10
Registered: ‎11-24-2010
Message 4 of 10 (592 Views)

Re: DELETE DIMENSIONS INSIDE BLOCKS

12-06-2010 10:56 AM in reply to: pbejse

that is cool. thanks for sharing! :smileyhappy:

Valued Contributor
jjorovi
Posts: 58
Registered: ‎06-15-2012
Message 5 of 10 (383 Views)

Re: DELETE DIMENSIONS INSIDE BLOCKS

06-15-2012 01:11 PM in reply to: pbejse

There is another way to eliminate the dimensions without selecting the block?

Distinguished Mentor
_Tharwat
Posts: 643
Registered: ‎07-02-2010
Message 6 of 10 (377 Views)

Re: DELETE DIMENSIONS INSIDE BLOCKS

06-15-2012 02:07 PM in reply to: NESSEL

My version with multiple selection set .....

 

(defun c:Test (/ ss i sn name lst)
  (vl-load-com)
;;;        ------ Tharwat 15. June. 2012 -----      ;;;
;;; codes to delete all dimensions entities in the  ;;;
;;;                selected blocks                  ;;;
  (if (not acdoc)
    (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
  )
  (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)))) lst))
        (progn
          (setq lst (cons name lst))
          (vlax-for each (vla-item (vla-get-blocks acdoc) name)
            (if (eq (vla-get-objectname each) "AcDbRotatedDimension")
              (vla-delete each))
          )
        )
      )
    )
    (princ)
  )
  (if ss (vla-regen acdoc AcAllviewports))
  (princ)
)

 

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Valued Contributor
jjorovi
Posts: 58
Registered: ‎06-15-2012
Message 7 of 10 (370 Views)

Re: DELETE DIMENSIONS INSIDE BLOCKS

06-15-2012 05:28 PM in reply to: _Tharwat

The code I'm looking for is more complex.
I need to remove all types of dimensions including the angular dimensions and aligned dimensions, without selecting the blocks.
Also, the dimensions in nested blocks have to be deleted.

Valued Mentor
Ian_Bryant
Posts: 362
Registered: ‎06-02-2005
Message 8 of 10 (353 Views)

Re: DELETE DIMENSIONS INSIDE BLOCKS

06-15-2012 09:31 PM in reply to: jjorovi

Hi,

not sure what you mean by without selecting blocks.

If it means you want to remove dimensions from

all defined blocks, you could try:

 

(defun c:blitz-all-dims ( / tbl ent dlist)
 (while (setq tbl (tblnext "BLOCK" (not tbl)))
  (if (and
        (not (assoc 1 tbl))
        (setq ent (cdr (assoc -2 tbl)))
      )
      (while ent
        (if (= (cdr (assoc 0 (entget ent))) "DIMENSION")
            (setq dlist (cons ent dlist))
        )
        (setq ent (entnext ent))
      )
  )
 )
 (foreach n dlist (vla-delete (vlax-ename->vla-object n)))
 (princ)
)

Ian

 

*Expert Elite*
pbejse
Posts: 2,515
Registered: ‎11-24-2009
Message 9 of 10 (347 Views)

Re: DELETE DIMENSIONS INSIDE BLOCKS

06-15-2012 10:52 PM in reply to: jjorovi

Another

 

(defun c:blitz2  (/ aDoc)
      (vl-load-com)
      (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
      (vlax-for blk (vla-get-blocks aDoc)
      (if
            (and
                  (eq :vlax-false (vla-get-isXref blk))
                  (eq :vlax-false (vla-get-isLayout blk))
                  (not (wcmatch (vla-get-name blk) "`*D*"))
                  )
                 (vlax-for dim blk
                       (if (wcmatch
                                 (vla-get-ObjectName dim)
                                 "AcDb*Dimension")
                             (vla-delete dim))
                       )
                 )
            )
      (vla-regen aDoc acAllViewports)
      (princ)
      )

Valued Contributor
jjorovi
Posts: 58
Registered: ‎06-15-2012
Message 10 of 10 (308 Views)

Re: DELETE DIMENSIONS INSIDE BLOCKS

06-18-2012 08:04 AM in reply to: pbejse
pbejse, you're amazing. This code is exactly what I've been looking for. I added a couple of lines to remove all outside dimensions of the blocks. (defun c:dimdel (/ aDoc BNAM) (vl-load-com) (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for blk (vla-get-blocks aDoc) (if (and (eq :vlax-false (vla-get-isXref blk)) (eq :vlax-false (vla-get-isLayout blk)) (not (wcmatch (vla-get-name blk) "`*D*")) ) (vlax-for dim blk (if (wcmatch (vla-get-ObjectName dim) "AcDb*Dimension") (vla-delete dim)) ) ) ) (FIX1 BNAM) (vla-regen aDoc acAllViewports) (prin1) ) (defun FIX1 (BNAM) (command "erase" (ssget "x" '((0 . "DIMENSION"))) "") (princ) ) Ian, thanks for your help too. Both codes work fine.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.