Author Topic: Get list of Layouts from Drawing without Opening  (Read 3970 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Get list of Layouts from Drawing without Opening
« on: October 24, 2018, 01:36:09 PM »
Hey, I am wondering if anyone knows how to get a list of layout tabs from a drawing without opening it?

I know I can open it and then get the list, but this takes a long time and what I am working on needs to get the layouts from a bunch of drawings. The programming language I am working with XOJO, so I could use LISP and just open a blank drawing or if someone knows how to program AutoCAD from XOJO, that would work better. Additionally, if anyone just knows of a program that can do this, then that would work as well.

ChrisCarlson

  • Guest
Re: Get list of Layouts from Drawing without Opening
« Reply #1 on: October 24, 2018, 01:43:50 PM »
You'll have to open it somehow, all of the information is contained within the dwg. Have you looked at the ACAD core console?

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Get list of Layouts from Drawing without Opening
« Reply #2 on: October 24, 2018, 01:46:03 PM »
I have it is still too slow, I know some people on here have ways of using ObjectDBX or something (I forget the name) to make some minor changes to drawings without opening them, I was wondering if the same technique might be possible to be used to read the layouts in the drawing.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Get list of Layouts from Drawing without Opening
« Reply #3 on: October 24, 2018, 01:48:56 PM »
Using ObjectDBX -
Code - Auto/Visual Lisp: [Select]
  1. (defun getdrawinglayouts ( dwg / doc idx rtn )
  2.     (if (setq doc (LM:getdocumentobject dwg))
  3.         (progn
  4.             (vlax-for lyt (vla-get-layouts doc)
  5.                 (setq rtn (cons (vla-get-name lyt) rtn)
  6.                       idx (cons (vla-get-taborder lyt) idx)
  7.                 )
  8.             )
  9.             (vlax-release-object doc)
  10.             (mapcar '(lambda ( n ) (nth n rtn)) (vl-sort-i idx '<))
  11.         )
  12.     )
  13. )
  14.  
  15. ;; Get Document Object  -  Lee Mac
  16. ;; Retrieves the VLA Document Object for the supplied filename.
  17. ;; The Document Object may be present in the Documents collection, or obtained through ObjectDBX.
  18. ;; It is the callers responsibility to release such object.
  19.  
  20. (defun LM:getdocumentobject ( dwg / app dbx dwl err vrs )
  21.     (cond
  22.         (   (not (setq dwg (findfile dwg))) nil)
  23.         (   (cdr
  24.                 (assoc (strcase dwg)
  25.                     (vlax-for doc (vla-get-documents (setq app (vlax-get-acad-object)))
  26.                         (setq dwl (cons (cons (strcase (vla-get-fullname doc)) doc) dwl))
  27.                     )
  28.                 )
  29.             )
  30.         )
  31.         (   (progn
  32.                 (setq dbx
  33.                     (vl-catch-all-apply 'vla-getinterfaceobject
  34.                         (list app
  35.                             (if (< (setq vrs (atoi (getvar 'acadver))) 16)
  36.                                 "objectdbx.axdbdocument"
  37.                                 (strcat "objectdbx.axdbdocument." (itoa vrs))
  38.                             )
  39.                         )
  40.                     )
  41.                 )
  42.                 (or (null dbx) (vl-catch-all-error-p dbx))
  43.             )
  44.             (prompt "\nUnable to interface with ObjectDBX.")
  45.         )
  46.         (   (vl-catch-all-error-p (setq err (vl-catch-all-apply 'vla-open (list dbx dwg))))
  47.             (prompt (strcat "\n" (vl-catch-all-error-message err)))
  48.         )
  49.         (   dbx   )
  50.     )
  51. )
  52.  

Example:
Code - Auto/Visual Lisp: [Select]
  1. _$ (getdrawinglayouts "C:\\MyDrawing.dwg")
  2. ("Model" "Layout1" "Layout2" "Layout3" "Layout4" "Layout5" "Layout6")

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Get list of Layouts from Drawing without Opening
« Reply #4 on: October 24, 2018, 02:02:19 PM »
Lee, I think our company uses more of your code than mine....LOL, not really, but there is a lot intertwined with mine. This looks perfect, now to test and integrate it.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Get list of Layouts from Drawing without Opening
« Reply #5 on: October 24, 2018, 02:22:06 PM »
Lee, I think our company uses more of your code than mine...

Let me know where to send the invoice :lol:

You're welcome Chris, hope it works for you.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Get list of Layouts from Drawing without Opening
« Reply #6 on: October 24, 2018, 02:25:10 PM »
It looks like it will, but so far it is looking like it won't work in AcCoreConsole, so I will have to use it in the full version of AutoCAD, which is doable, just not as transparent to the user this way.