Jump to content

Creating a drawinglist, but how?


MarcoW

Recommended Posts

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    12

  • ReMark

    5

  • chelsea1307

    3

  • MarcoW

    2

Top Posters In This Topic

Posted Images

WOW... I cant even figure out what this code is supposed to be used for... LOL... But it looks like it took a while to create.

Link to comment
Share on other sites

WOW... I cant even figure out what this code is supposed to be used for... LOL... But it looks like it took a while to create.

 

It's used to create a Drawing List, based on extracting attribute information from several instances of a titleblock (or other block), in several drawings at the same time.

 

It uses ObjectDBX to iterate through the drawings, which works "like" a script, except that the drawing isn't actually "opened" so the information is extracted 1000x quicker :twisted:

 

Lee

Link to comment
Share on other sites

cool! Here is a question for ya then.... I use the ACAD - Project Manager to create a list of the drawings from a folder, and extract information from them... I am only really interested in the drawings that have images... Do you know of a better way to create a list, given a folder to look through, of drawings with an output that shows the complete save path and name of each drawing and the complete saved and active path of the image attached to that drawing? The project manager gives me way to much information that I find to be useless, and makes it time consuming to search through and find the little information I am really concerned with...

In simple terms, I would like a list of drawings, that have images attatched, that I can see the saved path of the drawing and the image, and also the active path of the image to compair the saved paths to.

Link to comment
Share on other sites

cool! Here is a question for ya then.... I use the ACAD - Project Manager to create a list of the drawings from a folder, and extract information from them... I am only really interested in the drawings that have images... Do you know of a better way to create a list, given a folder to look through, of drawings with an output that shows the complete save path and name of each drawing and the complete saved and active path of the image attached to that drawing? The project manager gives me way to much information that I find to be useless, and makes it time consuming to search through and find the little information I am really concerned with...

In simple terms, I would like a list of drawings, that have images attatched, that I can see the saved path of the drawing and the image, and also the active path of the image to compair the saved paths to.

 

 

Hmmm... I think this can be done - but I will have to take time to modify the LISP posted in this thread. this may be better in a new thread so that it doesn't get confused.

Link to comment
Share on other sites

Hi Lee,

 

First thing I thought was OMG :shock: !! OMfG... That these kinda things are possible, okay, but how you fix it will be a riddle to me forever, I am afraid. One thing that is clear now, if it were not clear, you have developed great skill in alisp / vlisp.

 

The topic itself got a little bit off topic but thats okay, this forum is of such good quality (did not even notice any bad behaviour or so) that a little bit off topic must be tolerated.

 

For the lisp routine itself: I like the second version more. Maybe you could modify that one a little further; not only select a folder, but select some or maybe only one dwg('s) in that folder. For not all of the dwg's should be taken to the drawing list in my case. Some are not ready, some have no titleblocks...

 

I have some questions;

- What comes in excel, is that sorted in a way?

I mean it would be nice that it does it the same way every time.

- The row labels, are those the TAGS or did you manually name the rows that way ? For I cant find the piece of code where that is done.

 

I will have to play a bit more with it but it looks good allready.

Also, in the meantime, I am figuring out the eattext methode to get a table in acad: there is a way to extract data out of external files, so out of various dwg's.

Link to comment
Share on other sites

First thing I thought was OMG :shock: !! OMfG... That these kinda things are possible, okay, but how you fix it will be a riddle to me forever, I am afraid. One thing that is clear now, if it were not clear, you have developed great skill in alisp / vlisp.

 

Thanks Marco :)

 

For the lisp routine itself: I like the second version more. Maybe you could modify that one a little further; not only select a folder, but select some or maybe only one dwg('s) in that folder. For not all of the dwg's should be taken to the drawing list in my case. Some are not ready, some have no titleblocks...

 

I don't think it is that easy to have the user select multiple files individual without seriously modifying the LISP. Could you not just make a dummy folder and move the files that are ready into that folder, then back once you have run the LISP?

 

I have some questions;

- What comes in excel, is that sorted in a way?

I mean it would be nice that it does it the same way every time.

- The row labels, are those the TAGS or did you manually name the rows that way ? For I cant find the piece of code where that is done.

 

If you read the instructions in the LISP header, I think all is explained. There is a "settings" panel at the top of the LISP - which you can edit.

 

There, you can change the block name, and also the list of attribute tags that are extracted.

 

The data is written to the Excel file in the order that the files are in the directory, and the tags are written in the order that they appear in the list in the "settings" panel at the top of the LISP.

Link to comment
Share on other sites

  • 11 months later...
I have attempted to make an ObjectDBX version of this code, so that it may be run simultaneously on a whole folder of drawings, let me know if you have any problems.

 

Instructions are printed on the header.

 

; ** ============[ DwgLst.lsp ]============== ** ;
; **                                          ** ;
; **  FUNCTION:                               ** ;
; **  Will Automatically Create a Drawing     ** ;
; **  List based on TitleBlock Attribute      ** ;
; **  Values.                                 ** ;
; **                                          ** ;
; ** ======================================== ** ;
; **                                          ** ;
; **  SYNTAX: DWGLST                          ** ;
; **                                          ** ;
; **  AUTHOR:                                 ** ;
; **  Copyright © 2009, Lee McDonnell         ** ;
; **  Contact Lee Mac:   CADTutor.net         ** ;
; **                     TheSwamp.org         ** ;
; **                                          ** ;
; ** ======================================== ** ;
; **                                          ** ;
; **  RESTRICTIONS:                           ** ;
; **  Machine must be able to run             ** ;
; **  Microsoft Excel.                        ** ;
; **                                          ** ;
; ** ======================================== ** ;
; **                                          ** ;
; **  USAGE:                                  ** ;
; **  Attributes from every instance of a     ** ;
; **  Specified Block are Extracted to        ** ;
; **  Excel.                                  ** ;
; **                                          ** ;
; **  An Excel file may be selected or        ** ;
; **  upon the user hitting Cancel at         ** ;
; **  the prompt, a new Excel file is         ** ;
; **  created.                                ** ;
; **                                          ** ;
; **  Block Name and Attribute Tag List may   ** ;
; **  be Changed in the Settings Panel below. ** ;
; **  Attribute Values will be written to     ** ;
; **  Excel in the order they appear in the   ** ;
; **  list.                                   ** ;
; **                                          ** ;
; ** ======================================== ** ;
; **                                          ** ;
; **  VERSION:                                ** ;
; **  1.0  ~  01.07.2009                      ** ;
; **  2.0  ~  02.07.2009                      ** ;
; **                                          ** ;
; ** ======================================== ** ;
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ;


(defun c:DwgLst  (/  BlkName ValLst *acad
                    Shell fDir Dir dwLst acVer
                    cAtt attLst oLst file xlApp
                    xlShe Ucells xlCells Col Row
                    *error*

                 )

 (vl-load-com)

 (setq

 ;; =-=-=-=-=[ Settings ]=-=-=-=-=- ;;

   BlkName  "titleblock"             ;; { Block Name }

   ValLst '("NUMBER" "DATE" "NAME")  ;; { Attribute Tag List }

 ;; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ;;

 )

 ;; =-=-=-=[ Error Handler ]=-=-=-=- ;;

 (defun *error* (msg)
   (mapcar 'ObjRel
     (list xlApp xlShe UCells xlCells dbx *acad))
   (if
     (not
       (wcmatch
         (strcase msg)
           "*BREAK,*CANCEL*,*EXIT*"))
     (princ
       (strcat
         "\n<< Error: " msg " >>"))
     (princ "\n*Cancel*"))
   (princ))

 ;; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ;;

 (cond ((not (eq 'STR (type BlkName)))
        (princ "\n<< Block Name not a String >>"))
       ((not (vl-consp ValLst))
        (princ "\n<< Attribute Tag List Invalid >>"))
       ((not
          (vl-every
            (function
              (lambda (x)
                (eq 'STR (type x)))) ValLst))
        (princ "\n<< Attribute Tag List Must only Contain Strings >>"))
       (t
         (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))
        (ObjRel 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...")

            (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)) (strcase BlkName)))
                        (progn
                          (foreach Att
                            (append
                              (vlax-safearray->list
                                (vlax-variant-value
                                  (vla-GetAttributes Obj)))
                              (if
                                (not
                                  (vl-catch-all-error-p
                                    (setq cAtt
                                      (vl-catch-all-apply
                                        'vlax-safearray->list
                                          (list
                                            (vlax-variant-value
                                              (vla-getConstantAttributes Obj)))))))
                                cAtt))
                            (if (vl-position
                                  (strcase
                                    (vla-get-TagString Att)) ValLst)
                              (setq attlst
                                (cons
                                  (cons
                                    (vla-get-TagString Att)
                                      (vla-get-TextString Att)) attlst))))
                            (setq olst
                              (cons
                                (mapcar
                                  (function
                                    (lambda (x)
                                      (assoc x attlst))) ValLst) olst) attlst nil))))))
                (princ (strcat "\n<< Error Opening Dwg: " dwg " >>")))
              (princ (chr 46))
              (ObjRel dbx) (setq dbx nil))

            ;; -=-=-=-=-=-=-[ Write to Excel ]-=-=-=-=-=-=- ;;

            (if oLst
              (progn
                (if (setq file (getfiled "Select Excel File" "" "xls" )
                  (progn
                    (setq xlApp (vlax-get-or-create-object "Excel.Application")
                          xlshe (vlax-get-property
                                  (vlax-get
                                    (vla-open
                                      (vlax-get xlApp "Workbooks")
                                      file)
                                    "Sheets")
                                  "Item" 1)
                          Ucells  (vlax-get xlshe "Usedrange")
                          xlCells (vlax-get xlshe "Cells"))
                    (setq Col (- (vlax-get
                                   (vlax-get ucells "Columns")
                                   "Count")
                                 2)
                          row     (1+
                                    (vlax-get
                                      (vlax-get ucells "Rows")
                                      "Count"))))
                  (progn
                    (setq xlApp (vlax-get-or-create-object "Excel.Application")
                          xlshe (vlax-get-property
                                  (vlax-get
                                    (vlax-invoke-method
                                      (vlax-get xlApp "Workbooks")
                                      "Add")
                                    "Sheets")
                                  "Item" 1)
                          xlCells (vlax-get xlshe "Cells") Col 1 row 1)
                    (foreach Tag ValLst
                      (vlax-put-property xlCells "Item" row Col Tag)
                      (setq Col (1+ Col)))
                    (setq Col 1 row 2)))
                (vla-put-visible xlApp :vlax-true)
                (foreach Sht (reverse oLst)
                  (if (< 65536 row)
                    (setq Col (1+ (length ValLst)))
                    (setq Col 1))
                  (foreach Tag Sht
                    (vlax-put-property xlCells "Item" row Col (cdr Tag))
                    (setq Col (1+ Col)))
                  (setq row (1+ row)))
                (gc) (gc)
                (alert "Close Excel File Manually")
                (princ
                  (strcat "\n<< " (rtos (length dwLst) 2 0) " Drawings Processed >>")))
              (princ "\n<< No TitleBlocks Found in Drawing >>")))
          (princ "\n*Cancel*"))
        (mapcar 'ObjRel
          (list xlApp xlShe UCells xlCells dbx *acad))))
 (princ))

;; =-=-=-=-=[ Object Release ]=-=-=-=-= ;;

(defun ObjRel (Obj)
 (and Obj
   (eq 'VLA-OBJECT (type Obj))
     (not (vlax-object-released-p Obj))
       (vl-catch-all-apply
         'vlax-release-object
           (list Obj))))

(vl-load-com)
(princ
 (vl-list->string
   '(10 42 42 32 68 119 103 76 115 116 46 108 115 112 32 98
     121 32 76 101 101 32 77 99 68 111 110 110 101 108 108
     44 32 67 111 112 121 114 105 103 104 116 32 169 32 74
     117 108 121 32 50 48 48 57 32 42 42 10 32 32 32 32 32
     32 32 32 32 32 32 32 45 32 84 121 112 101 32 34 68 87
     71 76 83 84 34 32 116 111 32 73 110 118 111 107 101 32 45)))
(princ)

;|
;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;

                         End of Program Code                          

;;;¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,;
|;

Hi Lee, This program is good for creating a drawing list of many drawings in a folder without open them, but for a specified titleblock only.

At fact, there are many sizes of drawings (A1, A2, A3...) saving in a folder. Titleblocks of these drawings can be difference (titleblock_A1, titleblock_A2, titleblock_A3...) but all attributes are the same. So can you please update this program to read all these titleblocks. Thank you. PP.

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