Import Layouts from Template

Discussion in 'AutoCAD' started by Matt W, Jan 28, 2005.

  1. Matt W

    Matt W Guest

    Can you import layouts from a DWT or DWG using VBA?
    Nothing is jumping out at me at the moment.

    Thanks in advance!
     
    Matt W, Jan 28, 2005
    #1
  2. Matt W

    Jeff Mishler Guest

    Think "ObjectDBX"......and copyobjects
     
    Jeff Mishler, Jan 28, 2005
    #2
  3. Matt W

    Matt W Guest

    I'm thinking...

    Hmmmm....


    Maybe it's because it's Friday but I'm drawing a blank.
    Gotta snippet o' code I could take a peek at??
     
    Matt W, Jan 28, 2005
    #3
  4. Matt W

    Jeff Mishler Guest

    Well, I do have this that I did in VLisp. You should be able to convert it
    to VBA :)

    ;| Import layouts from a user entered file (dwg, dwt, etc.)

    Jeff Mishler, Dec. 9, 2003
    |;

    (defun imp_layouts (source / *acad* doc l_import odbx Doctest
    path lays l_list)
    (vl-load-com)
    (setq *acad* (vlax-get-acad-object)
    doc (vla-get-activedocument *acad*))
    ;;**** Check if source file is open
    (vlax-for oDoc (vla-get-documents *acad*)
    (if (= (vla-get-fullname oDoc) source)
    (setq Doctest t)))
    (if (and (not Doctest) (findfile source))
    (progn ;; Ensure that ObjectDBX is available
    (if (> (atoi (getvar "AcadVer")) 15)
    (setq oDBX (vla-GetInterfaceObject
    *acad* "ObjectDBX.AxDbDocument.16"))
    (progn
    (if (not (vl-registry-read
    "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument\\CLSID"))
    (startapp "regsvr32.exe"
    (strcat "/s \"" (findfile "axdb15.dll") "\""))
    );;if
    (setq oDBX (vla-GetInterfaceObject
    *acad* "ObjectDBX.AxDbDocument"))
    );;progn
    );;if
    (vla-open oDBX source);; "opens" source for our use
    (setq lays (vla-get-layouts oDBX));; source layout table
    (if (> (vla-get-count lays) 1);;ensure there are layouts to import
    (progn
    (vlax-for x lays ;; cycle thru table & check if name
    ;; exists in this drawing, omit if so
    (if (not (or (= "Model" (vla-get-name x))
    (member (vla-get-name x) (layoutlist))))
    (setq l_list (append (list x) l_list ))
    );if
    );for
    (setvar "ctab" "Model")
    (foreach x (layoutlist)
    (cond ((= x "Layout1")(vla-delete (vla-item (vla-get-layouts doc)
    x)))
    ((= x "Layout2")(vla-delete (vla-item (vla-get-layouts doc) x)))
    )
    )
    (if l_list
    (progn
    (setq l_import (vlax-safearray-fill
    (vlax-make-safearray vlax-vbObject
    (cons 0 (- (length l_list) 1))
    ) l_list)
    );; create safearray for use in ActiveX method
    (vla-copyobjects oDBX l_import (vla-get-layouts doc))
    (princ (strcat "\nLayouts imported successfully: "
    (itoa (length l_list))))
    ;;import the layouts
    );progn
    (princ "\No new layouts to import from the source drawing...")
    );if
    );progn
    (princ "\nSorry, no layouts found in source drawing, try again.")
    );if
    (vlax-release-object oDBX);; we're done with it
    );progn
    (progn
    (if doctest
    (princ "\nYou tried to use a file in use by Autocad, please close it and
    try again....")
    (princ "\nSource file not found, please try again....")
    );;if
    );;progn
    );if
    (princ);; exit quietly
     
    Jeff Mishler, Jan 28, 2005
    #4
  5. Matt W

    Matt W Guest

    Oh boy... vlisp.

    Thanks, Jeff. I'll see what I can do with this.

    --
    I support two teams: The Red Sox and whoever beats the Yankees.

     
    Matt W, Jan 28, 2005
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.