Jump to content

Recommended Posts

Posted

Hello,

 

I wrote this little routine to automate some drawing clean-up:

 

;Cleaning routine

(defun c:clean()

(command "._audit" "Y")

(command "._purge" "blocks" "A$*" "N")

(command "._purge" "regapps" "*" "N")

(command "._qsave")

(princ)

)

 

and it works well enough, except that the output is a little messy: a complete account of its search through the drawing as it audits, complete list of everything purged. Setting "cmdecho" to 0 doesn't have any effect.

 

Is there a way to suppress all the (petty) details?

 

Many thanks in advance!

Posted

You could try temporarily setting NOMUTT to 1, though I'm not sure if this will affect the Purge output either.

 

By the way, have a read of the Code Posting Guidlines for information on how to format code in your posts.

Posted

No luck with nomutt, but not really a big deal. Thank you for ref'ing me to the posting guidelines!

Posted

Replace the part of purging blocks with the following code .

 

(vl-load-com)
(if (setq ss (ssget "_x" '((0 . "INSERT"))))
 (progn
   (repeat (setq i (sslength ss))
   (setq sn (ssname ss (setq i (1- i))))
   (setq names (cons (cdr (assoc 2 (entget sn))) names))
 )
)
(vlax-for block (vla-get-blocks
                 (vla-get-activedocument (vlax-get-acad-object))
               )
 (if (and (wcmatch (vla-get-name block) "A$*")
          (not (member (vla-get-name block) names))
     )
   (vla-delete block)
 )
)
 )

And don't forget to localize all variables .

 

Good luck :)

Posted

Since you are using a version that still support VBA, may try something like this:

(command "_VBASTMT" "ThisDrawing.PurgeAll")

Posted
Since you are using a version that still support VBA, may try something like this:

(command "_VBASTMT" "ThisDrawing.PurgeAll")

 

No need for VBA for a Purge All:

 

(vla-purgeall (vla-get-activedocument (vlax-get-acad-object)))

 

Might need to be evaluated more than once:

 

(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(repeat 3 (vla-purgeall doc))

Posted

:? (Boggling) Had been putting off getting into Visual Lisp, but I guess there's no time like the present. But I can't find any "vla-" commands in the command reference? (I'm looking at http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-68f9.htm) It's got lots of "vl-" everything, but where do you find "vla-purgeall" (and, I assume, similar commands)?

 

(I actually don't want to purge *everything* out of the drawing, but leave things like layers and linetypes alone: they don't take up much space, and it saves re-loading them.)

Posted
:

 

(I actually don't want to purge *everything* out of the drawing, but leave things like layers and linetypes alone: they don't take up much space, and it saves re-loading them.)

 

Did you try my code in post Number #4 or read it at least ?

Posted
:? (Boggling) Had been putting off getting into Visual Lisp, but I guess there's no time like the present. But I can't find any "vla-" commands in the command reference? (I'm looking at http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-68f9.htm) It's got lots of "vl-" everything, but where do you find "vla-purgeall" (and, I assume, similar commands)?

 

There was never a Visual LISP reference for the ActiveX Properties and Methods functions (i.e. those functions prefixed vla-* ); the only available reference for these functions was the VBA reference found in the acadauto.chm file. Although this reference is written for VBA, the number of function parameters and their data type are almost identical to that used by Visual LISP, so the translation is straightforward.

 

In versions of AutoCAD before 2011, this ActiveX & VBA Reference could be accessed from the Help Documentation present in the Visual LISP IDE (VLIDE) provided with AutoCAD (I've written a few tutorials on the Visual LISP IDE and more information on how to access the help on a function can be found here).

 

However, when the help was migrated online in AutoCAD 2011, this ActiveX & VBA Reference was removed from the VLIDE help alltogether. Thankfully, for those using AutoCAD 2011 onwards, the acadauto.chm file can still be found under C:\Program Files\Common Files\Autodesk Shared

 

Where Visual LISP is concerned, there are several tutorials to be found on AfraLISP:

http://www.afralisp.net/visual-lisp/

 

(I actually don't want to purge *everything* out of the drawing, but leave things like layers and linetypes alone: they don't take up much space, and it saves re-loading them.)

 

In that case, the PurgeAll method may not be the best solution since with this method it is an 'all or nothing' approach - you cannot select individual items or groups of items to purge.

 

Replace the part of purging blocks with the following code .

 

Tharwat, consider the case in which a block is nested.

Posted

Tharwat, consider the case in which a block is nested.

 

Good point , I did forget about the nested Block . :o

Thanks .

Posted

Ok . this code would delete all Blocks that are existed in the drawing completely that their names start with A$*******

(defun c:Test (/ ss i sn names)
;;; Tharwat 09. May. 2012 ;;;
 (if (setq ss (ssget "_x" '((0 . "INSERT"))))
   (progn
     (repeat (setq i (sslength ss))
       (setq sn (ssname ss (setq i (1- i))))
       (if (wcmatch (cdr (assoc 2 (entget sn))) "A$*")
         (vla-delete (vlax-ename->vla-object sn))
       )
       (setq names (cons (cdr (assoc 2 (entget sn))) names))
     )
   )
 )
 (cond ((not acdoc)
        (setq
          acdoc (vla-get-activedocument (vlax-get-acad-object))
        )
       )
 )
 (vlax-for block
                 (vla-get-blocks acdoc)
   (if (eq :vlax-false (vla-get-isXref block))
     (vlax-for x block
       (if (and (eq (vla-get-objectname x) "AcDbBlockReference")
                (wcmatch (vla-get-name x) "A$*")
           )
         (vla-delete x)
       )
     )
   )
 )
 (vlax-for block (vla-get-blocks acdoc)
   (if (and (wcmatch (vla-get-name block) "A$*")
            (not (member (vla-get-name block) names))
       )
     (vla-delete block)
   )
 )
 (vla-regen acdoc AcAllViewports)
 (princ)
)

Posted

Thank you both, Lee Mac & Tharwat! I'm just getting started in LISP, and you've given me a lot to study and learn - much appreciated!

Posted
Thank you both, Lee Mac & Tharwat! I'm just getting started in LISP, and you've given me a lot to study and learn - much appreciated!

 

You're welcome Heduanna :)

 

Did my code work for you as you wanted ?

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...