Jump to content

Recommended Posts

Posted

I want to write a script that will run through a list of drawings and delete a block that has the same name throughout all the drawings. The script is not the problem. Does anyone know of a command that I can use to call out a block and delete it out of a drawing? In order to write the script, I need a command that can be used without window pop-ups. Something like the Erase command, but to my knowledge Erase is not able to call out a specific block to be erased. Anyone know of a command I could use? Or know of a LISP, that is already written, that I could use?

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • AQucsaiJr

    14

  • Lee Mac

    8

  • alanjt

    4

  • NBC

    1

Top Posters In This Topic

Posted

I don't know enough about ObjectDBX to use it yet, so I just stick to scripts because they are very easy to write.

 

I will give this thread a look NBC.

Posted

Give this a shot:

 

;; ObjectDBX Example, by Lee McDonnell
;; Credit to Tony Tanzillo, Tim Willey
  
(defun c:blkdel (/ *error* bNme *acad Shell fDir Dir dwLst dbx)
 (vl-load-com)

 ;; Error Handler

 (defun *error* (e)
   (ObjRel (list Shell dbx *acad))
   (if (not (wcmatch (strcase e) "*BREAK,*CANCEL*,*EXIT*"))
     (princ (strcat "\n<< Error: " e " >>")))
   (princ))

 ;; Get Block Name

 (while
   (progn
     (setq bNme (getstring t "\nSpecify Block Name: "))
     (cond ((not (snvalid bNme))
            (princ "\n** Invalid Block Name **"))
           (t (setq bNme (strcase bNme)) nil))))     

 ;; Get Directory

 (setq *acad (vlax-get-acad-object)
       Shell (vla-getInterfaceObject *acad "Shell.Application")
       fDir (vlax-invoke-method Shell 'BrowseForFolder
              (vla-get-HWND *acad) "Select Directory: " 80))
 (and (eq (type Shell) 'VLA-OBJECT)
      (not (vlax-object-released-p Shell))
      (vl-catch-all-apply 'vlax-release-object (list Shell)))
 (if fDir
   (progn
     (setq Dir
       (vlax-get-property
         (vlax-get-property fDir 'Self) 'Path))
     (if (not (eq "\\" (substr Dir (strlen Dir))))
       (setq Dir (strcat Dir "\\")))
     (princ "\nProcessing...")

     ;; Iterate Drawings
     
     (foreach dwg (setq dwLst
                    (mapcar
                      (function
                        (lambda (x)
                          (strcat Dir x)))
                      (vl-directory-files Dir "*.dwg" 1)))

       (vlax-for doc (vla-get-Documents *acad)
         (and (eq (strcase (vla-get-fullname doc)) (strcase dwg))
              (setq dbx doc)))

       (and (not dbx)
            (setq dbx
              (vlax-create-object
                (if (< (setq acVer (atoi (getvar "ACADVER"))) 16)
                  "ObjectDBX.AxDbDocument"
                  (strcat "ObjectDBX.AxDbDocument." (itoa acVer))))))          

       (if (not (vl-catch-all-error-p
                   (vl-catch-all-apply 'vla-open (list dbx dwg))))
         (progn
           (vlax-for lay (vla-get-Layouts dbx)
             (vlax-for Obj (vla-get-Block lay)
               (if (and (eq (vla-get-ObjectName Obj) "AcDbBlockReference")
                        (eq (strcase (vla-get-Name Obj)) BNme))
                 (if (vl-catch-all-error-p
                       (vl-catch-all-apply 'vla-delete (list Obj)))
                   (princ
                     (strcat "\n** Error Deleting Block in: "
                             (vl-filename-base dwg) " **"))))))
           (vla-saveas dbx dwg))
         (princ (strcat "\n** Error Opening File: " (vl-filename-base dwg) " **")))

       (princ (chr 46)))     
             
     ;; Ending Messages
     
     (princ (strcat "\n<< " (rtos (length dwLst) 2 0) " Drawings Processed >>")))
   (princ "*Cancel*"))

 ;; Garbage Collection
 
 (gc) (ObjRel (list Shell dbx *acad))
 (princ))

;; Release Objects ~ Requires List of Variables
           
(defun ObjRel (lst)
 (mapcar
   (function
     (lambda (x)
       (if (and (eq (type x) 'VLA-OBJECT)
                (not (vlax-object-released-p x)))
         (vl-catch-all-apply
           'vlax-release-object (list x))))) lst))



Posted

Hay lee I see you finally added a donations button to your profile... I still think thats a really good idea.

Ill give this code a try and let you know how it goes.

Posted

I must be missing somthing....

This is a LISP right?

After I call up the program blkdel and give the block name, PDP_EP, I get a browse for folder window. What do I select here? I selected the folder the drawings were in and it reported 51 drawings processed but the block was not removed out of any of the drawings.

Posted
Hay lee I see you finally added a donations button to your profile... I still think thats a really good idea.

 

I'm glad you think so - opinion poll is here.

Posted

Haha I found that link right before you sent it to me.

Posted
I must be missing somthing....

This is a LISP right?

After I call up the program blkdel and give the block name, PDP_EP, I get a browse for folder window. What do I select here? I selected the folder the drawings were in and it reported 51 drawings processed but the block was not removed out of any of the drawings.

 

Yes, this is a LISP :)

 

You select the folder and it should process all the drawings that lie within that folder.

 

I can't see why the block was not removed - it should report back when a block cannot be removed for some reason. Are you sure the block name was correct?

Posted

I will try a few things before giving you results again.

 

P.S. Lee if you do create a website with all the LISPs and programs you have written, please provide me the link. Your LISPs have saved me much time and I would be more than willing to do my small part by donating to be able to gain access to a library of LISPs and programs you have written. CADTutor will always be my primary source of information, but a LISP library would help.

Posted

Got it.... Seems the problem was that if I had a drawing open that was in the list, it would not work. When I ran the LISP from a drawing that was not in the list it worked perfect. Pulled the block out of all 51 drawings within the folder with no errors. I have not inspected every drawing yet but randomly selected a few and they all seemed to be fine... Thanks Lee.

Posted
Yay :)

 

Glad you got it working.

 

Lee

that's pretty slick lee, nice work.

 

AQucsaiJr:

i'm curious though, why do you have so many drawings with blocks you want removed?

Posted

The way we do our project drawings, we have a block that we place on each drawing to denote what stage of the project we are on, i.e. Engineering Package 1, 2, 3, Point to Point(or final check). When we are ready to submit the project as a final issue package we do not need this block anymore, so we just simply delete the block, zip up the folder that contains our drawings, and send it to the client.

 

The block is meant for the field engineers that are installing the equipment we are designing. If the block is on the drawing, it lets them know they are not looking at the completed project yet.

 

Oh to the number of drawings..... We create a schematic drawings for not only every piece of equipment, but also schematic drawings for the way the equipment is to be wired, and how every piece of equipment is to work the way we have designed.

Posted
The way we do our project drawings, we have a block that we place on each drawing to denote what stage of the project we are on, i.e. Engineering Package 1, 2, 3, Point to Point(or final check). When we are ready to submit the project as a final issue package we do not need this block anymore, so we just simply delete the block, zip up the folder that contains our drawings, and send it to the client.

The block is meant for the field engineers that are installing the equipment we are designing. If the block is on the drawing, it lets them know they are not looking at the completed project yet.

 

 

makes sense. like i said, i was just curious :)

Posted
makes sense. like i said, i was just curious :)

 

 

No problem.... The one thing I can not explain is exactly what I do. Not because it is of any high security reasons, but because not even the engineers I work with can explain what we do in less than a books worth of explanation. :?

Posted
No problem.... The one thing I can not explain is exactly what I do. Not because it is of any high security reasons, but because not even the engineers I work with can explain what we do in less than a books worth of explanation. :?

 

good luck at career day with your kids :wink:

Posted
good luck at career day with your kids :wink:

 

Ya right....:?... I have been working here for two years and my wife still has barely any idea what I do... Heck I know what I do but can't explain it very well. Maybe its just me!:D... idk

Posted
Ya right....:?... I have been working here for two years and my wife still has barely any idea what I do... Heck I know what I do but can't explain it very well. Maybe its just me!:D... idk

 

my wife and a friend of hers like to joke about how they have absolutely NO idea what their husbands actually do at work.

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