Jump to content

Moving objects from one layer to another in 50+ drawings


ABuckingham

Recommended Posts

I've been tasked with a rather large monotonous job, and was hoping someone could help me out. I need to move objects from one layer to another using some predictable conditions and don't want to spend a couple days doing it, here's the skinny.

 

Given an object, check to see it the layer it's on ends in -E, so for example FOO-BAR-E

 

In a separate template file called TEMP.DWG, check to see if a layer exists with a -N suffix, and if so move import the layer from the template and move the object to that layer, so if FOO-BAR-N is a layer in the template, bring that layer into the current drawing then move the object from FOO-BAR-E to FOO-BAR-E

 

If there is no layer with the -N suffix, check to see if there is a suffix-less layer in the same template file and if so, move it to that layer so FOO-BAR-E to FOO-BAR

 

If both those don't exist, then just move along to the next object. Rinse and repeat for the next 200 drawings.

 

I'm not fussy about VBA or AutoLISP, and I'm working in AutoCad 2008.

 

Any help would be great. :)

Link to comment
Share on other sites

Everything seems do-able - but I think it would be better that you could input the layer changes into the LISP prior to running it, instead of using a Template File - switching between drawings in LISP is hard enough as it is...

Link to comment
Share on other sites

Thanks Lee I gave it a try and as you said it didn't work. If I wasn't working on learning VBA for Microstation ( :( ) I'd try to whip something together this weekend but this project isn't as urgent as my others.

 

As always, thanks for your help and contributions to the community here.

Link to comment
Share on other sites

Try this instead mate:

 

(I'm learning this ObjectDBX stuff, so its a bit hit and miss...)

 

;; ObjectDBX Tester  by Lee McDonnell (Lee Mac)
;; Credit to Tony Tanzillo for Directory Browser, Tim Willey

(defun c:MacDwg (/ refLst *error* *acad Shell fDir Dir dbx lay Tag)
 (vl-load-com)

 (setq refLst '(

                ("FOO-BAR-E" . "FOO-BAR-N")
                ("FOO-CAR-E" . "FOO-CAR-N")

                )
       )  

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

 (setq *acad (vlax-get-acad-object)
       Shell (vla-getInterfaceObject *acad "Shell.Application")
       fDir (vlax-invoke-method Shell 'BrowseForFolder
              (vla-get-HWND *acad) "Select Directory: " 0))
 (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 "\\")))
     (if (< (atoi (setq acVer (substr (getvar "ACADVER") 1 2))) 16)
       (setq acVer "") (setq acVer (strcat (chr 46) acVer)))
     (setq dbx (vla-getInterfaceObject
                 *acad (strcat "ObjectDBX.AxDbDocument" acVer)))
     (princ "\nProcessing...")
     (foreach dwg (setq dwLst
                    (mapcar
                      (function
                        (lambda (x)
                          (strcat Dir x)))
                      (vl-directory-files Dir "*.dwg" 1)))
       (vla-open dbx dwg)

       (vlax-for Lay (vla-get-layouts dbx)
         (vlax-for Obj (vla-get-Block lay)
           (if (setq Tag (assoc (vla-get-layer Obj) refLst))
             (vla-put-layer Obj (cdr Tag)))))
       
       (vla-saveas dbx dwg)        
       (princ (chr 46)))
     (princ (strcat "\n<< " (rtos (length dwLst) 2 0) " Drawings Processed >>"))))
 
 (ObjRel (list Shell dbx *acad))
 (gc)
 (princ))
           
(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))

Link to comment
Share on other sites

If I wasn't working on learning VBA for Microstation ( :( ) I'd try to whip something together this weekend but this project isn't as urgent as my others.

 

Why are you learning VBA? I thought that was extinct... :P

Link to comment
Share on other sites

Why are you learning VBA? I thought that was extinct... :P

 

I don't think there is a .NET API for Microstation yet. There wasn't when I last checked earlier in this year.

 

Bentley forums will tell us all.

Link to comment
Share on other sites

Hi Mac

 

I have just one remark about your lisp about objectdbx

If a drawing of the directory is already open, it crashes.

 

One example which I used

 (defun Ouvrir_dessin_dbx(dwg / dbx doc lan rel)
   (and (setq dwg (findfile dwg))
     (progn
   (vlax-for doc (vla-get-documents (vlax-get-acad-object))
     (and (eq (strcase (vla-get-fullname doc)) (strcase dwg))
       (setq dbx doc lan T)
     )
   )
   (and (not dbx)
     (setq dbx (vlax-create-object (if (< (setq rel (atoi (getvar "ACADVER"))) 16)
                     "ObjectDBX.AxDbDocument"
                     (strcat "ObjectDBX.AxDbDocument." (itoa rel))
                   )
           )
     )
     (vla-open dbx dwg)
   )
     )
   )
   (list dbx lan)
 )

An example

(Ouvrir_dessin_dbx "c:/test/11.dwg") return (# nil) --> Work with ObjectDbx

(Ouvrir_dessin_dbx "c:/test/11.dwg") return (# T) --> Work with AcadDocument

 

Otherwise, hats, you learn quickly

 

@+

Link to comment
Share on other sites

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