Jump to content

Creating a drawinglist, but how?


MarcoW

Recommended Posts

Hi all,

 

I searched, and asked, here and there but never really found what I am looking for. (Hmm sounds like Whitesnake..?) Anyway, it seems to be a problem to create a drawinglist in an easy way. I've read about connecting MS acces to Autocad and vice versa. Or with excel...

 

It doesn't have to be very complicated for I want only to create the list in a one way direction. I do not need to edit the list itself after wich AutoCad edits the drawing. (Was that poor english?)

 

To be hounest: I'm too novice to figure it out myself but maybe with some good input from you, I might come up with something.

 

Two things I have tried: the attout function in Expresstools and the eattext within AutoCad. Both are not very satisfying allthough

"-eattext" would make some sense if I would be able to use it correctly.

 

What should happen: in my example there is 1 .dwg file that contains 5 layouts. Each layout carries 1 titleblock (or stamp if you like) called "titleblock". I need to read out some (not all) attribute values of each titleblock and put it in a list / table / notepadfile / excel sheet / anything that comes out of the printer. Maybe even a sixth layout, called "drawinglist".

 

Ie. "titleblock" has 3 attributes I need to read out:

- Name

- Date

- Number

 

In case of 5 layouts, there must be created a table like:

 

Number Date Name

01 01-06-2009 House A

02 11-06-2009 House B

03 16-06-2009 Building

(The name of the titleblock or the attribute tags ALWAYS stay the same... )

 

Via "-eattext" + "update fields" there is a way to update a drawinglist. AutoCad itself even shows the balloontip for "reload table".

 

All together, there are options enough I guess. But how to put it together so that "with one soft click on te left mousebutton" there is generated an actual and correct drawinglist.

 

Any help or tips are more then welcome !

 

Oh, I know that when using Excel there can be made nice looking sheets, but I am not interested in that kind of thing. First reach the goal and then go for the looks.

 

Maybe a text file can be created (by write-line) which Excel can import?

Link to comment
Share on other sites

  • 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

I have attempted to create a program to create a Drawing List in Excel, containing the attribute values as you specified.

 

Let me know how you get on with it.

 

Upon the prompt, you can either select an Existing Excel File, in which case the data is appended to the existing data in the file.

 

Or, upon clicking cancel to the prompt, a new Excel File is created.

 

Lee

 

; ** ============[ DwgLst.lsp ]============== **;
; **                                          **;
; **  FUNCTION:                               **;
; **  Will Automatically Create a Drawing     **;
; **  List based on TitleBlock Attribute      **;
; **  Values.                                 **;
; **                                          **;
; ** ======================================== **;
; **                                          **;
; **  SYNTAX: DWGLST                          **;
; **                                          **;
; **  AUTHOR:                                 **;
; **  Copyright (c) 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.                                **;
; **                                          **;
; ** ======================================== **;
; **                                          **;
; **  VERSION:                                **;
; **  1.0  ~  01.07.2009                      **;
; **                                          **;
; ** ======================================== **;
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ;


(defun c:DwgLst  (/ *error* ss cAtt attlst
                   oLst xlApp file xlshe
                   UCells xlCells Col row
                   blkName ValLst)
 
 (vl-load-com)

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

 (setq blkName "titleblock")
 (setq ValLst '("NAME" "DATE" "NUMBER"))
 
 (if (setq ss
       (ssget "_X"
         (list (cons 0 "INSERT")
               (cons 2 blkName) (cons 66 1))))         
   (progn
     (foreach Obj
       (mapcar 'vlax-ename->vla-object
         (mapcar 'cadr (ssnamex ss)))
     (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
           (vl-sort attlst
             (function
               (lambda (a b)
                 (< (car a) (car b))))) olst) attlst nil))

     (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)))
     (vla-put-visible xlApp :vlax-true)
     (foreach Sht (reverse oLst)
       (if (< 65536 row)
         (setq Col 4))
       (vlax-put-property xlCells "Item"
         row Col (cdaddr Sht))
         (vlax-put-property xlCells "Item"
           row (1+ Col) (cdar Sht))
           (vlax-put-property xlCells "Item"
             row (+ Col 2) (cdadr Sht))
       (setq row (1+ row)))
     (mapcar 'ObjRel
       (list xlApp xlShe UCells xlCells))
     (gc) (gc)
     (alert "Close Excel File Manually"))
   (princ "\n<< No TitleBlocks Found in Drawing >>"))
 (princ))

(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                          

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

Link to comment
Share on other sites

Lee:

 

I'd consider start charging for code by the character.

 

haha I wish :lol:

 

That would be my dream job Mark...

 

In fact, I'm on my summer break right now, desperately looking for work over the summer months, til I go back to uni in October...

Link to comment
Share on other sites

Have you tried marketing your skills yet?

 

Tbh, I'm not really sure where to start - I was thinking of starting my own website, but that is a task in itself...

 

Lee

Link to comment
Share on other sites

Make up something simple describing what you can do (LISP, macros, VBA, diesel...whatever). Then open the local phone directory. Note every civil, mechanical, architectural, engineering firm and their phone number. Call and ask to speak to the CAD Manager. Ask him/her if they use AutoCAD (we'd like them to right?). Then ask them if they create their own custom LISP routines. We'd like them to say they don't but would love to find someone who could help them. That's where you come in. Then ask them what tasks they want to simplify or automate. Maybe you provide them with a "free" small sample or show them some code you've already written. That hooks them. Now they hire you. You write the code, they test it, it gets a few tweaks, you get a check and you send me 2% off the top for the idea. OK...1%. But that's as low as I'll go. No, wait. 0%. I consider you a friend. When you're rich and famous you'll ring me up and invite me to your mansion on the hill and let me swim in your heated pool. OK?

Link to comment
Share on other sites

Make up something simple describing what you can do (LISP, macros, VBA, diesel...whatever). Then open the local phone directory. Note every civil, mechanical, architectural, engineering firm and their phone number. Call and ask to speak to the CAD Manager. Ask him/her if they use AutoCAD (we'd like them to right?). Then ask them if they create their own custom LISP routines. We'd like them to say they don't but would love to find someone who could help them. That's where you come in. Then ask them what tasks they want to simplify or automate. Maybe you provide them with a "free" small sample or show them some code you've already written. That hooks them. Now they hire you. You write the code, they test it, it gets a few tweaks, you get a check and you send me 2% off the top for the idea. OK...1%. But that's as low as I'll go. No, wait. 0%. I consider you a friend. When you're rich and famous you'll ring me up and invite me to your mansion on the hill and let me swim in your heated pool. OK?

 

He's moving into a Castle and you get to swim in the cold moat.

Link to comment
Share on other sites

Marco, if you were to decide to use ssm it will create drawing list for you

 

Excuse my ignorance, but what is SSM?

 

Make up something simple describing what you can do (LISP, macros, VBA, diesel...whatever). Then open the local phone directory. Note every civil, mechanical, architectural, engineering firm and their phone number. Call and ask to speak to the CAD Manager. Ask him/her if they use AutoCAD (we'd like them to right?). Then ask them if they create their own custom LISP routines. We'd like them to say they don't but would love to find someone who could help them. That's where you come in. Then ask them what tasks they want to simplify or automate. Maybe you provide them with a "free" small sample or show them some code you've already written. That hooks them. Now they hire you. You write the code, they test it, it gets a few tweaks, you get a check and you send me 2% off the top for the idea. OK...1%. But that's as low as I'll go. No, wait. 0%. I consider you a friend. When you're rich and famous you'll ring me up and invite me to your mansion on the hill and let me swim in your heated pool. OK?

 

Excellent idea Mark, I may just do that - I might be a pest to these firms, but if it gets me a job in the end then so be it o:)

 

And, yes, of course you can swim in my heated pool :P

 

Thanks,

 

Lee

Link to comment
Share on other sites

Excuse my ignorance, but what is SSM?

 

 

 

Excellent idea Mark, I may just do that - I might be a pest to these firms, but if it gets me a job in the end then so be it o:)

 

And, yes, of course you can swim in my heated pool :P

 

Thanks,

 

Lee

 

 

Hey Lee,

 

Nice pool.

Lee Mac's Pool.jpg

Link to comment
Share on other sites

If they need convincing Lee just point them in the direction of Cadtutor, your posts here are a worthy C.V.o:)

 

If they don't already know of this site, well shame on them:oops:.

:lol:

( Can I get an invite to the pool too? Just wanna see the machine that is Remark float!):lol::lol:

Link to comment
Share on other sites

If they need convincing Lee just point them in the direction of Cadtutor, your posts here are a worthy C.V.o:)

 

If they don't already know of this site, well shame on them:oops:.

:lol:

( Can I get an invite to the pool too? Just wanna see the machine that is Remark float!):lol::lol:

 

Thanks Rob :)

 

Hopefully I can get a bit of work soon - although, it'll mean that I won't be able to spend as much time on here.... :P

Link to comment
Share on other sites

I use contact cleaner on all my circuits.

 

Pool, moat, pond, whatever it's called I'll swim in it if the water temperature is right. No crocs please.

Link to comment
Share on other sites

I use contact cleaner on all my circuits.

 

Pool, moat, pond, whatever it's called I'll swim in it if the water temperature is right. No crocs please.

 

I can't believe how off-topic this thread has become - a chat thread for sure... (sorry Strix, Tiger, Cad64 and the others ~ ReMark is the culprit :P )

 

Hopefully the LISP will work for Marco :P

Link to comment
Share on other sites

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                          

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

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