Process / open dwg in background and do something

Process / open dwg in background and do something

DGRL
Advisor Advisor
2,717 Views
21 Replies
Message 1 of 22

Process / open dwg in background and do something

DGRL
Advisor
Advisor

Dear forum members,

 

I want an lisp that would be able to open a dwg in the background and do some stuff with it

Now I use the code made by Lee Mac but that one does not allow the following

 

;;  - No SelectionSets               (ssget, ssname, ssdel, etc)        ;;
;;  - No Command Calls               (command "_.line" ... etc)         ;;
;;  - No ent* methods                (entget, entmod, entupd, etc)      ;;
;;  - No Access to System Variables  (setvar, getvar, setvariable, etc)

 

Does anyone knows how to open an dwg in the background and then read out the title block? ( attributes)

I already have a lisp that does this but the screen is refreshing whole time ( because of opening and closing the dwg )

If possible I would like to do this in the background

 

See sample code below

This code will open dwg in background change layer color and saves the dwg

Tested it and works perfect

Now what I want is this,

Open in the background an dwg and select title block / read out the att's and write to specific file

 

 

 

Kind regards,

 

 

;;-----------------------=={ ObjectDBX Wrapper }==----------------------;;
;;                                                                      ;;
;;  Evaluates a supplied function on all drawings in a given list or    ;;
;;  selected directory.                                                 ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Arguments:                                                          ;;
;;                                                                      ;;
;;  fun [SYM]                                                           ;;
;;  ---------------------------------                                   ;;
;;  A function requiring a single argument (the VLA Document object),   ;;
;;  and following the 'rules' of ObjectDBX:                             ;;
;;                                                                      ;;
;;  - No SelectionSets               (ssget, ssname, ssdel, etc)        ;;
;;  - No Command Calls               (command "_.line" ... etc)         ;;
;;  - No ent* methods                (entget, entmod, entupd, etc)      ;;
;;  - No Access to System Variables  (setvar, getvar, setvariable, etc) ;;
;;                                                                      ;;
;;  lst [LIST] [Optional]                                               ;;
;;  ---------------------------------                                   ;;
;;  List of DWG Filenames; if nil, BrowseForFolder Dialog is displayed. ;;
;;                                                                      ;;
;;  sav [SYM]                                                           ;;
;;  ---------------------------------                                   ;;
;;  Boolean flag determining whether drawings should be saved following ;;
;;  function evaluation (T=saved, nil=not saved).                       ;;
;;----------------------------------------------------------------------;;
;;  Returns:                                                            ;;
;;                                                                      ;;
;;  List of:                                                            ;;
;;  (                                                                   ;;
;;      (<Drawing Filename> . <Function Result>)                        ;;
;;      (<Drawing Filename> . <Function Result>)                        ;;
;;      ...                                                             ;;
;;      (<Drawing Filename> . <Function Result>)                        ;;
;;  )                                                                   ;;
;;                                                                      ;;
;;  Where:                                                              ;;
;;  <Drawing Filename>                                                  ;;
;;  is the filename of drawing that has been processed.                 ;;
;;                                                                      ;;
;;  <Function Result>                                                   ;;
;;  is the result of evaluating the supplied function on the Document   ;;
;;  Object representing the associated drawing filename.                ;;
;;                                                                      ;;
;;  If an error occurs when evaluating the supplied function the        ;;
;;  Function Result will be nil and the error message will be printed   ;;
;;  to the command-line.                                                ;;
;;----------------------------------------------------------------------;;

(defun LM:ODBX ( fun lst sav / *error* app dbx dir doc dwl err rtn vrs )

    (defun *error* ( msg )
        (if (and (= 'vla-object (type dbx)) (not (vlax-object-released-p dbx)))
            (vlax-release-object dbx)
        )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )

    (cond
        (   (not
                (or lst
                    (and (setq dir (LM:browseforfolder "Select Folder of Drawings to Process" nil 512))
                         (setq lst (mapcar '(lambda ( x ) (strcat dir "\\" x)) (vl-directory-files dir "*.dwg" 1)))
                    )
                )
            )
            nil
        )
        (   (progn
                (setq dbx
                    (vl-catch-all-apply 'vla-getinterfaceobject
                        (list (setq app (vlax-get-acad-object))
                            (if (< (setq vrs (atoi (getvar 'acadver))) 16)
                                "objectdbx.axdbdocument" (strcat "objectdbx.axdbdocument." (itoa vrs))
                            )
                        )
                    )
                )
                (or (null dbx) (vl-catch-all-error-p dbx))
            )
            (prompt "\nUnable to interface with ObjectDBX.")
        )
        (   t
            (vlax-for doc (vla-get-documents app)
                (setq dwl (cons (cons (strcase (vla-get-fullname doc)) doc) dwl))
            )
            (foreach dwg lst
                (if (or (setq doc (cdr (assoc (strcase dwg) dwl)))
                        (and (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list dbx dwg))))
                             (setq doc dbx)
                        )
                    )
                    (progn
                        (setq rtn
                            (cons
                                (cons dwg
                                    (if (vl-catch-all-error-p (setq err (vl-catch-all-apply fun (list doc))))
                                        (prompt (strcat "\n" dwg "\t" (vl-catch-all-error-message err)))
                                        err
                                    )
                                )
                                rtn
                            )
                        )
                        (if sava (vla-saveas doc dwg))
                    )
                    (princ (strcat "\nError opening file: " (vl-filename-base dwg) ".dwg"))
                )
            )
            (if (= 'vla-object (type dbx))
                (vlax-release-object dbx)
            )
            (reverse rtn)
        )
    )
)

;;------------------=={ Browse for Folder }==-----------------;;
;;                                                            ;;
;;  Displays a dialog prompting the user to select a folder.  ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  msg - message to display at top of dialog                 ;;
;;  dir - root directory (or nil)                             ;;
;;  flg - bit-coded flag specifying dialog display settings   ;;
;;------------------------------------------------------------;;
;;  Returns:  Selected folder filepath, else nil.             ;;
;;------------------------------------------------------------;;

(defun LM:browseforfolder ( msg dir flg / err fld pth shl slf )
    (setq err
        (vl-catch-all-apply
            (function
                (lambda ( / app hwd )
                    (if (setq app (vlax-get-acad-object)
                              shl (vla-getinterfaceobject app "shell.application")
                              hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
                              fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg flg dir)
                        )
                        (setq slf (vlax-get-property fld 'self)
                              pth (vlax-get-property slf 'path)
                              pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
                        )
                    )
                )
            )
        )
    )
    (if slf (vlax-release-object slf))
    (if fld (vlax-release-object fld))
    (if shl (vlax-release-object shl))
    (if (vl-catch-all-error-p err)
        (prompt (vl-catch-all-error-message err))
        pth
    )
)

(vl-load-com) (princ)

 

(defun c:test ( / lyrName lyrColor)

;write the file
(setq fn (strcat DRSlijst "output.csv")
      fp (open fn "w")
)
;(princ "\n" fp)
(write-line (strcat "datum" dlm "filenaam" dlm "formaat" dlm "rev" dlm "statusO" dlm "statusT" dlm "titel" dlm "dwgprefix") fp)
(close fp)
;-----------

(setq PID (GetAllFiles (vl-string-right-trim "\\" PID1) 1 "*.dwg"))
(setq numFiles (length PID))

(setq ORTHO (GetAllFiles (vl-string-right-trim "\\" ORTHOS1) 1 "*.dwg"))
;(setq ORTHO (GrabAllFiles "P:\\Acad\\P3D\\project templates\\Empty Metric Project\\Orthos\\DWGs" ".dwg"))
(setq ORTHO (vl-remove (strcat ORTHOS1 "Orthographic View Selection 1.dwg") ORTHO))
(setq numFiles (+ numFiles (length ORTHO)))

(setq ISO (GetAllFiles (vl-string-right-trim "\\" ISO1) 1 "*.dwg"))
;(setq ISO (GrabAllFiles "P:\\Acad\\P3D\\project templates\\Empty Metric Project\\Isometric\\TEBULO_A1 ENG\\ProdIsos" ".dwg"))
(setq ISO (vl-remove (strcat ISO1 "IsoSymbolStyles.dwg") ISO))
(setq ISO (vl-remove (strcat ISO1 "Plant3dIsoSymbols.dwg") ISO))
(setq numFiles (+ numFiles (length ISO)))

(setq all (append PID ORTHO ISO))
;(setq msg (strcat "Going to Process " (itoa numFiles) " file(s)"))

 


  (setq lyrName  (strcase "Pipe") ; your layer name
        lyrColor acRed) ; your color

  (foreach x
    (LM:ODBX
      (function
        (lambda ( x / lyr )

          (vlax-for lyr (vla-get-layers x)
            (if (= (strcase (vla-get-name lyr)) lyrName)
              (vla-put-color lyr lyrColor)
            )
          )

 

        ) ; end lambda
      )
      all ; your file list ( you can change this into an path )
      t
    )
    (princ
      (strcat
        "\n--> Drawing: " (car x)
        (if (vl-catch-all-error-p (cdr x))
          (strcat "\n    Error: " (vl-catch-all-error-message (cdr x)))
          "\nSuccessful."
        )
      )
    )
  )
  (princ)
)

 

 

 

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
2,718 Views
21 Replies
Replies (21)
Message 2 of 22

DannyNL
Advisor
Advisor

Don,

 

You'll need to iterate through all the blocks with VL* commands as this is the only way to access objects with ODBX.

What is the name of your title block? And in what format do you want to write the data to your file?

0 Likes
Message 3 of 22

DGRL
Advisor
Advisor

@DannyNL

 

Thanks for the answer

Title block name is "title block" and I want it to be written to CSV

 

This is what I have so far lol

 

(while (setq d (tblnext "BLOCK" (null d)))
      (if (not (member (setq name (cdr (assoc 2 d))) lst))
        (progn
          ;(setq lst (cons name lst))
  (if (= name "Title Block") (setq a name)) ;end if
  
  
  

        ) ;end progn    
      ) ;end if 
    ); end while

 

A is being set but only the name not as <VLA-OBJECT IAcadBlockReference 000000002b51cac8>

Conversion of name to <VLA-OBJECT IAcadBlockReference 000000002b51cac8> would be nice

 

 

 

 

 

Kind regards,

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 4 of 22

DannyNL
Advisor
Advisor
Accepted solution

This code will return a list of the block with attributes in a drawing (x) in the format '((AttribTag1 AttribValue1)(AttribTag2 AttribValue2)....). Only the first block found that matches the name will be processed, all following with the same name will be ignored.

 

Change the block name in the code to the name you need and make sure to process the return list to write it to your file. As Lee Mac's ODBX wrapper only support one argument (the document object), the name of the block needs to be hard coded in this routine.

 

 

Use like this:

 

(setq ValueList (ExtractAttributes x))

(mapcar '(lambda (item) (write-line (strcat (car item) ": " (cadr item)) fileid)) ValueList)

 

(defun ExtractAttributes (EA_Doc / EA_Doc EA_Block EA_SpaceList EA_AttributeList EA_Return)
   (setq EA_BlockName "Title Block")
   (if
      (not (vl-catch-all-error-p (setq EA_Block (vl-catch-all-apply 'vla-item (list (vla-get-Blocks EA_Doc) EA_BlockName)))))
      (progn
         (setq EA_SpaceList (list (vla-get-ModelSpace EA_Doc)))
         (vlax-for EA_Layout (vla-get-Layouts EA_Doc)
            (setq EA_SpaceList (append EA_SpaceList (list (vla-get-Block EA_Layout))))
         )
         (foreach EA_Space EA_SpaceList
            (vlax-for EA_Object EA_Space
               (if
                  (and
                     (= (vla-get-ObjectName EA_Object) "AcDbBlockReference")
                     (= (strcase (vla-get-EffectiveName EA_Object)) (strcase EA_BlockName))
                     (= (vla-get-HasAttributes EA_Object) :vlax-true)
                     (not EA_Return)
                  )
                  (progn
                     (setq EA_AttributeList (vlax-safearray->list (vlax-variant-value (vla-GetAttributes EA_Object))))
                     (foreach EA_Attribute EA_AttributeList
                        (setq EA_Return (append EA_Return (list (list (vla-get-TagString EA_Attribute) (vla-get-TextString EA_Attribute)))))
                     )
                  )
               )
            )
         )        
      )
   )
   EA_Return
)
Message 5 of 22

DGRL
Advisor
Advisor

Dear @DannyNL

 

Thanks for this code

It works fine but I need it to be modified slightly

 

Now this line (setq ValueList (ExtractAttributes x)) will return a list which is fine

Now I need to process this line and filter stuff out

 

 

What I do notice is that out of the 19 dwg's I have in the list only 1 will be processed.

Do you know why this is?

 

Well I fixed the above issue
Now all 19 dwg's are processed

Simply add  (setq ValueList1 (cons ValueList ValueList1))  to the code and done

 

 

Starting to filter out what I need

Wish me luck lol

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 6 of 22

DannyNL
Advisor
Advisor
Accepted solution

It would be easy to add an attribute tag filter list, so only the attribute tags you want will be included in the return list.

This would make it easier and prevent the need to filter the list after processing the drawings.

0 Likes
Message 7 of 22

DGRL
Advisor
Advisor

Dear @DannyNL

 

I added an att filter and it seems to work

There is only one thing left and that is the list that I have now

 

It is very very long so I show a small piece of it

 

(("Weight" "0.000000") ("SH" "1") ("TL" "1"))

 

Now I googled my ass off yesterday and today but I cant find any solution ( if there is any )
I need a small code that will look at the fist one of every entry in the list i.e. Weight / SH / TL ect ect

 

This is the code I have now but it is not working in my favor

 

(foreach att ValueList1
 ;(print att)

 (setq attr (car att))
 ;(if (= attr "Status_O")(alert "done"))
 
(if (= attr "Rev_Date")(setq revdate (cdr att)))
(if (= attr "TEMPLATESIZE")(setq tempsize (cdr att)))
(if (= attr "REV")(setq strrev (cdr att)))
(if (= attr "ISO_REV")(setq strrev (cdr att)))
(if (= attr "STATUS_O")(setq status_o (cdr att)))
(if (= attr "STATUS_T")(setq status_t (cdr att)))
(if (= attr "TITLE")(setq strtitle (cdr att)))
(if (= attr "ISO_TITLE_2")(setq strtitle (cdr att)))
;(setq dwgname (getvar "DWGNAME" )) ;incl extension
;(setq dwgprefix (getvar "dwgprefix"))

(if(= revdate nil)(setq revdate ""))
(if(= tempsize nil)(setq tempsize ""))
(if(= strrev nil)(setq strrev ""))
(if(= status_o nil)(setq status_o ""))
(if(= status_t nil)(setq status_t ""))
(if(= strtitle nil)(setq strtitle ""))


;append to file
(setq fn (strcat DRSlijst "output.csv")
      fp (open fn "a")
)
(prin1 (strcat revdate dlm tempsize dlm strrev dlm status_o dlm status_t dlm strtitle ) fp)
(close fp)

; (mapcar '(lambda (item) (write-line fileid)) ValueList)


  ) ;end foreach att

 

What am I doing wrong?

 

Best regards,

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 8 of 22

DannyNL
Advisor
Advisor
Accepted solution

Hi Don,

 

If you do a CDR on a list like ("Weight" "0.000000") you will get a list back with in this case one element ("0.000000") and not the string "0.000000".

So you need to do a CADR instead.

 

(cdr '("Weight" "0.000000"))   -->  ("0.000000")

(cadr '("Weight" "0.000000")) -->  "0.000000"

0 Likes
Message 9 of 22

DGRL
Advisor
Advisor

HI @DannyNL

Major thanks Sir 🙂
For the variable's I use now Im going to use car
Will update you if it works ( we are @ 99% lol )

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 10 of 22

DGRL
Advisor
Advisor

hi @DannyNL

Using this (mapcar '(lambda (item) (write-line (strcat (car item) ": " (cadr item)) fp)) ValueList) it writes every value to an csv file

 

How can I modify my lisp that the above line will only write specific values?

The lisp seems to work but the output is still an issue

This is what I have

 

( small explanation)

ValueList = the list per dwg

ValueList1 is the complete list of all dwg's processed

 

 

(foreach x
    (LM:ODBX
      (function
        (lambda ( x / lyr )
  
  
  ;(if (= (setq tempsize (ExtractAttributes x "TEMPLATESIZE" )) nil)(setq tempsize "" )(setq tempsize (ExtractAttributes x "TEMPLATESIZE" )))
  
 (setq ValueList (ExtractAttributes x))
 (setq ValueList1 (append ValueList ValueList1))

(foreach att ValueList1
 ;(print att)

 ;(setq attr (car att))
 ;(if (= attr "Status_O")(alert "done"))
 
(if (= att "Rev_Date")(setq revdate (cdr att)))
(if (= att "TEMPLATESIZE")(setq tempsize (cdr att)))
(if (= att "REV")(setq strrev (cdr att)))
(if (= att "ISO_REV")(setq strrev (cdr att)))
(if (= att "Status_O")(setq status_o (cdr att)))
(if (= att "Status_T")(setq status_t (cdr att)))
(if (= att "TITLE")(setq strtitle (cdr att)))
(if (= att "ISO_TITLE_2")(setq strtitle (cdr att)))
(if (= att "dwgname")(setq dwgname (cdr att)))
;(if (= attr "LineNumber")(setq dwgname (cdr att)))

;(setq dwgname (getvar "DWGNAME" )) ;incl extension
;(setq dwgprefix (getvar "dwgprefix"))

;(if(= revdate nil)(setq revdate ""))
;(if(= tempsize nil)(setq tempsize ""))
;(if(= strrev nil)(setq strrev ""))
;(if(= status_o nil)(setq status_o ""))
;(if(= status_t nil)(setq status_t ""))
;(if(= strtitle nil)(setq strtitle ""))
;(if(= dwgname nil)(setq dwgname ""))
;
;
;(if (not (= revdate " ")) (setq revdate (car revdate)))
;(if (not (= tempsize "")) (setq tempsize (car tempsize)))
;(if (not (= strrev "")) (setq strrev (car strrev)))
;(if (not (= status_o "")) (setq STATUS_O (car STATUS_O)))
;(if (not (= status_t "")) (setq STATUS_T (car STATUS_T)))
;(if (not (= strtitle "")) (setq strtitle (car strtitle)))
;(if (not (= dwgname "")) (setq dwgname (car dwgname)))


;append to file
(setq fn (strcat DRSlijst "output.csv")
      fp (open fn "a")
)
;(write-line (strcat revdate dlm dwgname dlm tempsize dlm strrev dlm status_o dlm status_t dlm strtitle) fp)
(mapcar '(lambda (item) (write-line (strcat (car item) ": " (cadr item)) fp)) ValueList)
(close fp)

  ) ;end foreach att  
        ) ; end lambda
      )
      all ; your file list
      t
    )
    (princ
      (strcat
        "\n--> Drawing: " (car x)
        (if (vl-catch-all-error-p (cdr x))
          (strcat "\n    Error: " (vl-catch-all-error-message (cdr x)))
          "\nSuccessful."
        )
      )
    )
  )

 

Hope you can make any soup out of this

Best regards,

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 11 of 22

DannyNL
Advisor
Advisor

Well....soup.....your words not mine Smiley Wink

 

Easiest (not prettiest) way to achieve this in your code is like

 

(setq processlist '("ATTRIB1" "ATTRIB2" "ATTRIB3" ......))
(mapcar '(lambda (item) (if (member (car item) processlist)(write-line (strcat (car item) ": " (cadr item)) fp))) ValueList)

Or as stated before the filtering can already be included and done in the attribute extraction team, so the return list only contains values you would want to write to the file.

Message 12 of 22

DGRL
Advisor
Advisor

Hi @DannyNL

 

Thanks for all the material.

The output we need is like this

 

datum filenaam formaat rev statusO statusT titel dwgprefix
12-9-2017 NEW PID.dwg A1 0 Final Concept Title

P:\ACAD\P3D\PROJECT TEMPLATES\EMPTY METRIC PROJECT\PID DWG\

 

The first line is always printed
The second line is what we need per dwg

The csv file needs to be TAB separated ( already done ) and per dwg 1 line

 

I will see how to archive this

But print / princ / prin1 and write-line always fails with error D:\P3D TEST\TEST PROJECT\Isometric\div\CUT PIECE LIST BOM\ProdIsos\Drawings\ConceptQAZ.dwg       bad argument type: stringp nil

Sometimes

D:\P3D TEST\TEST PROJECT\Isometric\div\CUT PIECE LIST BOM\ProdIsos\Drawings\ConceptQAZ.dwg       bad argument type: stringp ""

or

D:\P3D TEST\TEST PROJECT\Isometric\div\CUT PIECE LIST BOM\ProdIsos\Drawings\ConceptQAZ.dwg       bad argument type: stringp "0"

 

Where it comes from I have no clue

If I process 1 dwg ( valeulist ) then the lisp writes the file

If I process 20 dwg's abopve errors arises

 

 

Happy coding on Thursday 😞

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 13 of 22

DannyNL
Advisor
Advisor

I've cleaned your code a bit and moved the file action outside of your foreach loop.

Code is not tested but try the following:

 

;append to file
(setq fn (strcat DRSlijst "output.csv")
      fp (open fn "a")
)

(foreach x
           (LM:ODBX
              (function
                 (lambda (x / lyr)

                    (setq ValueList (ExtractAttributes x))                   
                    (foreach att ValueList
                       (if (= att "Rev_Date")
                          (setq revdate (cadr att))
                       )
                       (if (= att "TEMPLATESIZE")
                          (setq tempsize (cadr att))
                       )
                       (if (= att "REV")
                          (setq strrev (cadr att))
                       )
                       (if (= att "ISO_REV")
                          (setq strrev (cadr att))
                       )
                       (if (= att "Status_O")
                          (setq status_o (cadr att))
                       )
                       (if (= att "Status_T")
                          (setq status_t (cadr att))
                       )
                       (if (= att "TITLE")
                          (setq strtitle (cadr att))
                       )
                       (if (= att "ISO_TITLE_2")
                          (setq strtitle (cadr att))
                       )
                       (if (= att "dwgname")
                          (setq dwgname (cadr att))
                       )

                       (write-line (strcat revdate dlm dwgname dlm tempsize dlm strrev dlm status_o dlm status_t dlm strtitle) fp)


                    ) 
                 )
              )
              all                       ; your file list
              t
           )
   (princ
      (strcat
         "\n--> Drawing: "
         (car x)
         (if (vl-catch-all-error-p (cdr x))
            (strcat "\n    Error: " (vl-catch-all-error-message (cdr x)))
            "\nSuccessful."
         )
      )
   )
)

(close fp)
0 Likes
Message 14 of 22

DGRL
Advisor
Advisor

@DannyNL

 

Thanks for this

I get the same result as with the old code

But this is what I get back when using your last code


The csv file is empty

No data at all in it

 

The command line gives me the following

 

Command: TEST
D:\P3D TEST\TEST PROJECT\Isometric\div\CUT PIECE LIST BOM\ProdIsos\Drawings\ConceptQAZ.dwg       bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\div\GROUPED WITH CATERGORY TILES\ProdIsos\Drawings\ConceptQAZ.dwg   bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\div\GROUPED WITH INDEPENDENT COLUMNS\ProdIsos\Drawings\ConceptQAZ.dwg       bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\div\SIMPLE BOM\ProdIsos\Drawings\ConceptQAZ.dwg      bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\div\SPOOL BOM\ProdIsos\Drawings\ConceptQAZ.dwg     bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\div\WELD LIST BOM\ProdIsos\Drawings\ConceptQAZ.dwg  bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\_A1 ENG\ProdIsos\Drawings\ConceptQAZ.dwg     bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\_A1 ENG\ProdIsos\Drawings\ISO-QQ TEST.dwg      bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\_A1 ENG\ProdIsos\Drawings\ISO-QQ.dwg bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\_A1 NL\ProdIsos\Drawings\ConceptQAZ.dwg    bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\_A1 NL\ProdIsos\Drawings\ISO-QQ.dwg       bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\_A2 ENG\ProdIsos\Drawings\ConceptQAZ-overflow-1.dwg  bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\_A2 ENG\ProdIsos\Drawings\ConceptQAZ.dwg     bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\_A2 ENG\ProdIsos\Drawings\ISO-QQ.dwg bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\_A2 NL\ProdIsos\Drawings\ConceptQAZ-overflow-1.dwg bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\_A2 NL\ProdIsos\Drawings\ConceptQAZ.dwg    bad argument type: stringp nil
D:\P3D TEST\TEST PROJECT\Isometric\_A2 NL\ProdIsos\Drawings\ISO-QQ.dwg       bad argument type: stringp nil
--> Drawing: D:\P3D TEST\TEST PROJECT\PID DWG\1.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Orthos\DWGs\qq.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\div\CUT PIECE LIST BOM\ProdIsos\Drawings\ConceptQAZ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\div\GROUPED WITH CATERGORY TILES\ProdIsos\Drawings\ConceptQAZ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\div\GROUPED WITH INDEPENDENT COLUMNS\ProdIsos\Drawings\ConceptQAZ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\div\SIMPLE BOM\ProdIsos\Drawings\ConceptQAZ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\div\SPOOL BOM\ProdIsos\Drawings\ConceptQAZ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\div\WELD LIST BOM\ProdIsos\Drawings\ConceptQAZ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\_A1 ENG\ProdIsos\Drawings\ConceptQAZ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\_A1 ENG\ProdIsos\Drawings\ISO-QQ TEST.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\_A1 ENG\ProdIsos\Drawings\ISO-QQ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\_A1 NL\ProdIsos\Drawings\ConceptQAZ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\_A1 NL\ProdIsos\Drawings\ISO-QQ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\_A2 ENG\ProdIsos\Drawings\ConceptQAZ-overflow-1.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\_A2 ENG\ProdIsos\Drawings\ConceptQAZ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\_A2 ENG\ProdIsos\Drawings\ISO-QQ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\_A2 NL\ProdIsos\Drawings\ConceptQAZ-overflow-1.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\_A2 NL\ProdIsos\Drawings\ConceptQAZ.dwg
Successful.
--> Drawing: D:\P3D TEST\TEST PROJECT\Isometric\_A2 NL\ProdIsos\Drawings\ISO-QQ.dwg
Successful.nil
Command:

 

 

What I need to know is where the bad argument type: stringp nil is coming from

Really weird
it is just a list and it does not want to be printed

Below you will find the list generated by your code ( this is 1 dwg )

 

(("Weight" "0.000000") ("SH" "1") ("TL" "1") ("ISO_Revline_0_Approved" "FdB0") ("ISO_Revline_0_Checked" "TL") ("ISO_Revline_0_Drawn" "DG") ("ISO_Revline_0_Description" "Initial issue                                                                                          .") ("ISO_Revline_0_Date" "28/08/17") ("ISO_Revline_0_Rev" "0") ("ISO_Revline_1_Rev" "1") ("ISO_Revline_1_Date" "28/08/17") ("ISO_Revline_1_Description" "Initial issue") ("ISO_Revline_1_Drawn" "DG") ("ISO_Revline_1_Checked" "TL") ("ISO_Revline_1_Approved" "FdB1") ("ISO_Revline_2_Approved" "FdB2") ("ISO_Revline_2_Checked" "TL") ("ISO_Revline_2_Drawn" "DG") ("ISO_Revline_2_Rev" "2") ("ISO_Revline_2_Date" "28/08/17") ("ISO_Revline_2_Description" "Initial issue") ("ISO_Revline_3_Rev" "3") ("ISO_Revline_3_Date" "28/08/17") ("ISO_Revline_3_Description" "Initial issue") ("ISO_Revline_3_Drawn" "DG") ("ISO_Revline_3_Checked" "TL") ("ISO_Revline_3_Approved" "FdB3") ("LineNumber" "QQ") ("ISO_TITLE_1" "Title regel 2                                                              .") ("ISO_TITLE_2" "Title regel 2                                                              .") ("ISO_CLIENT" "XXX") ("ISO_Drawn by" "DG") ("ISO_Creation date" "8/28/2017") ("ISO_Checked by" "DG") ("ISO_Checked date" "8/28/2017") ("ISO_REV" "0") ("ISO_PROJECT_No" "17-00000") ("ISO_PIPESPEC" "PIPESPEC") ("ISO_MEDIUM" "MEDIUM") ("ISO_DESIGN_PRESS" "500") ("ISO_DESIGN_TEMP" "500") ("ISO_OP_PRESS" "500") ("ISO_OP_TEMP" "500") ("ISO_TEST_MEDIUM" "MEDIUM") ("ISO_TEST_PRESS" "500") ("ISO_PED_CAT" "PED CAT") ("ISO_XRAY" "XRAY") ("ISO_PAINT_SPEC" "PAINT") ("ISO_INSUL_TYPE" "INSUL TYPE") ("ISO_INSUL_THK" "INSUL THK") ("ISO_TRACING" "TRACING") ("ISO_NOTE_8" "8. Zet hier uw note") ("ISO_NOTE_7" "7. Zet hier uw note") ("ISO_NOTE_6" "6. Zet hier uw note") ("ISO_NOTE_5" "5. Zet hier uw note") ("ISO_NOTE_4" "4. Zet hier uw note") ("ISO_NOTE_3" "3. Zet hier uw note") ("ISO_NOTE_2" "2. Zet hier uw note") ("ISO_NOTE_1" "1. Zet hier uw note") ("TEMPLATESIZE" "A2") ("ISOFILENAME" "ISO-") ("Status_O" "As build") ("Status_T" "Concept") ("Rev_Date" "9/12/2017"))

 

 

Best regards

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 15 of 22

DannyNL
Advisor
Advisor
Accepted solution

I'm unable to test the code but I've found some problems.

See code below for modifications. It's the same code as you got by PM, but posting it here as well to complete the thread.

 

;append to file
(setq fn (strcat DRSlijst "output.csv")
      fp (open fn "a")
)

(foreach x
           (LM:ODBX
              (function
                 (lambda (x / lyr)

                    (setq ValueList (ExtractAttributes x))                   
                    (foreach att ValueList
                       (if (= (car att) "Rev_Date")
                          (setq revdate (cadr att))
                       )
                       (if (= (car att) "TEMPLATESIZE")
                          (setq tempsize (cadr att))
                       )
                       (if (= (car att) "REV")
                          (setq strrev (cadr att))
                       )
                       (if (= (car att) "ISO_REV")
                          (setq strrev (cadr att))
                       )
                       (if (= (car att) "Status_O")
                          (setq status_o (cadr att))
                       )
                       (if (= (car att) "Status_T")
                          (setq status_t (cadr att))
                       )
                       (if (= (car att) "TITLE")
                          (setq strtitle (cadr att))
                       )
                       (if (= (car att) "ISO_TITLE_2")
                          (setq strtitle (cadr att))
                       )
                       (if (= (car att) "dwgname")
                          (setq dwgname (cadr att))
                       )
                    )

                    (write-line (strcat revdate dlm dwgname dlm tempsize dlm strrev dlm status_o dlm status_t dlm strtitle) fp)
                     
                 )
              )
              all                       ; your file list
              t
           )
   (princ
      (strcat
         "\n--> Drawing: "
         (car x)
         (if (vl-catch-all-error-p (cdr x))
            (strcat "\n    Error: " (vl-catch-all-error-message (cdr x)))
            "\nSuccessful."
         )
      )
   )
)

(close fp)
0 Likes
Message 16 of 22

DGRL
Advisor
Advisor
Accepted solution

Dear @DannyNL 

 

After tweaking it a little we got it to work

 

(foreach x
           (LM:ODBX
              (function
                 (lambda (x / lyr)

                    (setq ValueList (ExtractAttributes x))                  
                    (foreach att ValueList
                       (if (= (car att) "Rev_Date")
                          (setq revdate (cadr att))
                       )
                       (if (= (car att) "TEMPLATESIZE")
                          (setq tempsize (cadr att))
                       )
                       (if (= (car att) "REV")
                          (setq strrev (cadr att))
                       )
                       (if (= (car att) "ISO_REV")
                          (setq strrev (cadr att))
                       )
                       (if (= (car att) "Status_O")
                          (setq status_o (cadr att))
                       )
                       (if (= (car att) "Status_T")
                          (setq status_t (cadr att))
                       )
                       (if (= (car att) "TITLE")
                          (setq strtitle (cadr att))
                       )
                       (if (= (car att) "ISO_TITLE_2")
                          (setq strtitle (cadr att))
                       )
                       ;(if (= att "dwgname")
                       ;   (setq dwgname (cadr att))
                       😉

                      
                    )
   (write-line (strcat revdate dlm tempsize dlm strrev dlm status_o dlm status_t dlm strtitle) fp)     
                 )
              )
              all                       ; your file list
              t
           )
   (princ
      (strcat
         "\n--> Drawing: "
         (car x)
         (if (vl-catch-all-error-p (cdr x))
            (strcat "\n    Error: " (vl-catch-all-error-message (cdr x)))
            "\nSuccessful."
         )
      )
   )
)

(close fp)

 

 

The whole lisp is working as it should

 

Many thanks for the help

 

Best regards,

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 17 of 22

DannyNL
Advisor
Advisor

You're welcome and glad I could help Smiley Happy

0 Likes
Message 18 of 22

DGRL
Advisor
Advisor

Dear @DannyNL

 

 

One wish remaining

 

Is it possible to ad DWGPREFIX in this sequence?

Because  (setq dwgprefix (getvar "dwgprefix") )  will give the dwgprefix of current open dwg and not current processed dwg.

Adding an ATT with an field does not work as fields are not the same as ATTRIBUTES

Hope you know something 🙂

Best regards

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 19 of 22

DannyNL
Advisor
Advisor
Accepted solution

No problem.

 Add these lines to your code.

 

(foreach x
           (LM:ODBX
              (function
                 (lambda (x / lyr)
                    (setq ValueList (ExtractAttributes x))  
                    (setq fullname  (vla-get-Name x))
                    (setq dwgprefix (vl-filename-directory fullname))
                    (setq filename  (strcat (vl-filename-base fullname)(vl-filename-extension fullname)))
.................

Use whichever matches your needs.

If you really only want the folder name aka prefix, you could only use this

 

(setq dwgprefix (vl-filename-directory (vl-get-name x)))

 

Message 20 of 22

DGRL
Advisor
Advisor

@DannyNL 

 

FINISHED
Finally this lisp came to an end

 

It is working perfect ( at the moment only for Plant 3D projects )

 

Current output

 

datum filenaam formaat rev statusO statusT titel dwgprefix
12-9-2017 NEW PID.dwg A1 0 Final Concept Title P:\ACAD\P3D\PROJECT TEMPLATES\EMPTY METRIC PROJECT\PID DWG

 

Thanks Danny I learned a lot from you with this 🙂


Best regards

If this was of any help please kudo and/or Accept as Solution
Kind Regards