Autolisp for open multiple drawings which list in a excel spreedsheet

Autolisp for open multiple drawings which list in a excel spreedsheet

Bin2009
Advocate Advocate
453 Views
5 Replies
Message 1 of 6

Autolisp for open multiple drawings which list in a excel spreedsheet

Bin2009
Advocate
Advocate

Hello,

My work need to open over ten different reference files, which located in different folders, I saved the drawing paths in an excel spreadsheet,  is any lisp can help automatic open the files based on the paths in excel? I am getting tired about go to diriment folder s to open the drawing manually.

Thanks in advance!

Bin

0 Likes
454 Views
5 Replies
Replies (5)
Message 2 of 6

devitg
Advisor
Advisor

@Bin2009 What will you do at each dwg. 

0 Likes
Message 3 of 6

Sea-Haven
Mentor
Mentor

A couple of suggestions, use a script made by lsip or Excel.

 

Hmmmm Bricscad example macro inside Excel. Bricscad is open.

 

 

 

Sub test()
  Dim acadApp As Object
  Dim acadDoc As Object
    Set acadApp = GetObject(, "BricsCadApp.AcadApplication")
      Set acadDoc = acadApp.Documents.Open("D:/acadtemp/Alan-2020.dwg")
  End Sub

 

 

 

 

0 Likes
Message 4 of 6

paullimapa
Mentor
Mentor

The following OpnCsvDwg.lsp code works only if the Excel file is a CSV file and the only data contained in each row is the drawing file location that includes the entire path (see sample csv file attached):

; opncsvdwg selects csv, read list of dwgs, checks if dwgs can be located & not read-only then opens them
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autolisp-for-open-multiple-drawings-which-list-in-a-excel/m-p/12692969
(defun c:opncsvdwg (/ data dwg dwg_openp openFile TextFileData)
 (vl-load-com)
 ;;;--- dwg_openp function
; checks to see if file is open already by another program
; returns T if file is opened or read-only 
; https://forums.augi.com/showthread.php?6102-Detect-Read-Only-file-attribute&highlight=open
; Usage:
; (dwg_openp (strcat(getvar"dwgprefix")(getvar"dwgname")))
; Returns:
; T
(defun dwg_openp (file-arg / file)
 (cond 
  ((setq file (open file-arg "a"))
        (close file)
  )
 )
 (not file)
) ; defun
 (if(setq TextFileData (getfiled "Select File With List of Drawing Names" (getvar 'dwgprefix) "csv" 16))
  (progn
   (setq openFile (open TextFileData "r"))
   (while (setq dwg (read-line openFile))
    (if (findfile dwg)
     (if(dwg_openp dwg)
        (princ(strcat"\nDrawing Already Opened: [" dwg "]."))
        (setq data (cons dwg data)) ; save into data list
     )
     (princ(strcat"\nDrawing Not Found: [" dwg "]..."))
    ) ; if
   ) ; while
   ; open each dwg in data list 
   (if data
    (foreach itm (reverse data)
     (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) itm))
    )
    (princ"\nNo Drawings Available to Open.")
   ); if
  ) ; progn
 ) ; if
 (princ)
) ; defun

paullimapa_0-1712562546321.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 6

Sea-Haven
Mentor
Mentor

If csv has multiple columns then say make sure column A has the file name can convert the csv to a list and use (car for the file name, this would make it more global a single column still works. 

 

For me read direct from Excel. Big hint Bin2009 need a sample excel file to play with, need to see what is in excel file.

 

If can find time will add select range in Excel and open the dwgs, as a Excel macro.

 

 

0 Likes
Message 6 of 6

ec-cad
Collaborator
Collaborator

If using Lisp and reading a drawing path from a CSV, I suggest using "/" to seperate folders, rather than single "\".

Lisp needs "\\" or a single "/" for folders.

ECCAD

0 Likes