Jump to content

Layout Tabs From Multiple .DWGs


Freerefill

Recommended Posts

Is there a way to produce a list of layout tabs from a .dwg that you do not have open? My initial idea was to create a new AutoCAD object and link a file, much like one would do when working with an Excel file.. however, doing so opened up a new instance of AutoCAD, which I'd rather avoid.

 

The ability must be there, because ADCENTER will let you drag stuff in, including layout tabs. Is there a way to do this via LISP?

 

Any suggestions will be helpful. ^^

Link to comment
Share on other sites

As an example:

 

;; ObjectDBX Example, by Lee McDonnell
  
(defun ODBX (fname / doc dbx lst flag)
 (vl-load-com)

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

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

 (cond ((and flag
          (vl-catch-all-error-p
            (vl-catch-all-apply 'vla-open
              (list dbx fname))))
        (princ (strcat "\n** Error Opening: " (vl-filename-base fname) " **")))
       (t
        (vlax-for lay (vla-get-Layouts dbx)
          (setq lst (cons (vla-get-name lay) lst)))))    

 (ObjRel (list dbx)) (gc) (gc)

 lst)

;; 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))

(defun c:test ( )
 (odbx (getfiled "select" "" "dwg" 16)))


Link to comment
Share on other sites

Very nice, thank you, Lee ^.^ Took me a few tries to understand what was going on, but I think I've got it. I'll have to look further into ObjectDBX to get a more complete understanding.

 

Again, thank you. ^^

Link to comment
Share on other sites

i dont know how to link to another post so i borowwed this from another post from patric_35.

this will get you going in the right direction

 

 

 
(defun c:lstdwg(/ dirbox Ouvrir_dessin_dbx rep lst fic dbx lay)
 (defun dirbox(/ cdl rep)
   (if (setq cdl (vlax-create-object "Shell.Application"))
     (progn
   (and (setq rep (vlax-invoke cdl 'browseforfolder 0 "Choose a directory" 512 ""))
        (setq rep (vlax-get-property (vlax-get-property rep 'self) 'path))
   )
   (vlax-release-object cdl)
     )
   )
   rep
 )
 (defun Ouvrir_dessin_dbx(dwg / dbx doc lan)
   (vl-load-com) 
   (setq dwg (findfile dwg))
   (vlax-for doc (vla-get-documents (vlax-get-acad-object))
     (and (eq (strcase (vla-get-fullname doc)) (strcase dwg))
   (setq dbx doc lan T)
     )
   )
   (or dbx
     (progn
   (if (< (atoi (substr (getvar "ACADVER") 1 2)) 16)
     (setq dbx (vlax-create-object "ObjectDBX.AxDbDocument"))
     (setq dbx (vlax-create-object (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2))))
   )
   (vla-open dbx dwg)
     )
   )
   (list dbx lan)
 )
 (vl-load-com)
 (if (setq rep (dirbox))
   (if (setq lst (vl-directory-files rep "*.dwg" 1))
     (foreach fic lst
   (if (setq dbx (ouvrir_dessin_dbx (strcat rep "/" fic)))
     (progn
       (princ (strcat "\n Working in " fic))(princ)
       (vlax-for lay (vla-get-layouts (car dbx))
         (princ (strcat "\n\t\tLayout : " (vla-get-name lay)))(princ)
       )
       (or (cadr dbx)(vlax-release-object (car dbx)))
     )
     (princ (strcat "\n Can't read file " fic))
   )
     )
     (alert "No dwg's File")
   )
 )
 (princ)
)

Link to comment
Share on other sites

As an addendum to this question. Is there a vla way to copy a layout? I dont want the command line cop out way. I know how to do that. Any help would be appreciated.

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