LIST OF DRAWINGS FROM FOLDER

LIST OF DRAWINGS FROM FOLDER

SAFizzy
Advocate Advocate
5,731 Views
25 Replies
Message 1 of 26

LIST OF DRAWINGS FROM FOLDER

SAFizzy
Advocate
Advocate

Dear All:

I am looking for a lisp to create a table in Auto CAD with List of Drawings, by taking the data (list of all files) from folder.

 

thanks in advance

0 Likes
Accepted solutions (4)
5,732 Views
25 Replies
Replies (25)
Message 2 of 26

roland.r71
Collaborator
Collaborator

Just 1 folder, no subdirectories?

 

edit:

If so: vl-directory-files will get you that list, like:

(vl-directory-files "e:/acadwin" "*.dwg" 1)

 

This will list all drawings inside given path. (using given filter (*.dwg)

The 1 stands for "filenames only".

 

If you do have subdirs, it becomes a bit more complicated.

0 Likes
Message 3 of 26

SAFizzy
Advocate
Advocate

yes just 1 folder

0 Likes
Message 4 of 26

SAFizzy
Advocate
Advocate

sorry,

i didn't get you, can you explain what to do? 

0 Likes
Message 5 of 26

dbhunia
Advisor
Advisor
Accepted solution

Hi

 

Try this......

 

This will ask you to chose the folder......(It will return the files of the folder only not the folder tree....) 

 

Then ask you to chose the "mtext" location where to insert the list of files......

 

Now you can take the list & put those value in your table........(Because your table format is unknown...)  

 

(defun c:GET_FILES ( / sh folder folderobject result text)
(vl-load-com)
(command "cmdecho" 0)
(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
(setq folder (vlax-invoke-method sh 'BrowseForFolder 0 "" 0 ))
(vlax-release-object sh)
(setq folderobject (vlax-get-property folder 'Self))
(setq result (vlax-get-property FolderObject 'Path))
(setq Files_Folder (vl-directory-files result "*.dwg"))
(setq text "")
(if (/= (length Files_Folder) 0)
(repeat (setq N (length Files_Folder))
(setq e (nth (setq N (- N 1)) Files_Folder))
(setq text (strcat text e "\\P"))
)
(princ "\nDoes not containing any *.DWG File.")
)
(if (/= (length Files_Folder) 0)
(command "_.MTEXT" pause pause text "")
)
(command "cmdecho" 1)
(princ)
)

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 6 of 26

SAFizzy
Advocate
Advocate

Excellent,

just small adjustments

1: remove extension

2: list not in proper ascending/descending order

3: add serial number 

4: table of two columns (serial number & file name) and rows according to list

5: scale of table to be confirmed

 

Thanks for your help

0 Likes
Message 7 of 26

roland.r71
Collaborator
Collaborator

what to do?

Create a list of filenames.

Create a table.

Populate the table using the list of filenames.

 

As this requires ActiveX methods (afaik), I can only help you a bit.

I can get the above done, but don't ask about 'customizing', as I know to little about ActiveX methods within acad to do so properly.

 

This is howfar i can get, using the Knowledge Network and some code i found from @_Tharwat (albeit on another forum).

(setq  file_list (vl-directory-files "E:/lisp/testDWG" "*.dwg" 1)
      rows       (length file_list)
      cw         1
      acadObj    (vlax-get-acad-object)
      doc        (vla-get-ActiveDocument acadObj)
      pt         (vlax-3d-point 0 0 0)
      modelSpace (vla-get-ModelSpace doc)
)
(foreach file file_list
   (setq ln (strlen file))
   (if (> ln cw)(setq cw ln))
)
(setq myTable (vla-addtable modelSpace pt rows 1 1 50)
      i       0
      hgt     (if (zerop (cdr (assoc 40 (setq e (entget (tblobjname "STYLE" (getvar 'textstyle)))))))
                 (cdr (assoc 42 e))
                 (cdr (assoc 40 e))
              )
 )
(vla-setcolumnwidth myTable 0 (* hgt cw))
(while (< i (length file_list))
   (vla-settext myTable i 0 (nth i file_list))
   (setq i (1+ i))
)

However, the text size isn't coming from the textstyle, but some kind of table layout.

as the first line is 6 and the rest is 4.5, but the textstyle sayz: 2.5

So i don't have a clue yet how to set those correctly. (if possible)

0 Likes
Message 8 of 26

roland.r71
Collaborator
Collaborator

@SAFizzy wrote:

Excellent,

just small adjustments

1: remove extension

2: list not in proper ascending/descending order

3: add serial number 

4: table of two columns (serial number & file name) and rows according to list

5: scale of table to be confirmed

 

Thanks for your help


1. Learn about string handling functions. (hint: substr can be usefull here)

2. Learn about list manipulation functions. (hint: acad_strlsort will do)

3. Where did that serial just suddenly come from?: Be complete in requests.

4. Look up the table command & learn how to set column numbers.

5. What scale?

 

Keep in mind:

We are here to help you do your work & get things done. NOT to do all the work for you.

(unless you hire somebody) Your questions tell me you a: know nothing about lisp & b: do not intend to ever learn. a) is not a problem. b) IS! (for me at least)

Message 9 of 26

SAFizzy
Advocate
Advocate

sorry to say that, this is not the way to help others, i am new here in this forum & lisp.

I like the answer from  @dbhunia this satisfied me alot

anyway thanks for your try to help me.

0 Likes
Message 10 of 26

dbhunia
Advisor
Advisor
Accepted solution

@SAFizzy wrote:

Excellent,

just small adjustments

1: remove extension

2: list not in proper ascending/descending order

3: add serial number 

4: table of two columns (serial number & file name) and rows according to list

5: scale of table to be confirmed

 

..................

 

Hi

 

Try this .......

 

This will cover the highlighted points .........

 

Rest you have to do your own..........All the rest points can be controlled from properties/Manually.....

 

I am quite busy  to do my things........

 

(defun c:GET_FILES ( / sh folder folderobject result)
(vl-load-com)
(command "cmdecho" 0)
(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
(setq folder (vlax-invoke-method sh 'BrowseForFolder 0 "" 0 ))
(vlax-release-object sh)
(setq folderobject (vlax-get-property folder 'Self))
(setq result (vlax-get-property FolderObject 'Path))
(setq Files_Folder (vl-directory-files result "*.dwg"))

(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
(setq pt (vlax-3d-point 0 0 0))
(setq modelSpace (vla-get-ModelSpace doc))
(setq MyTable (vla-Addtable modelSpace pt (+ (length Files_Folder) 2) 2 10 100))
(vla-ZoomExtents acadObj)
(vla-setText MyTable 0 0 "Drawing File List")
(vla-setText MyTable 1 0 "Serial Number")
(vla-setText MyTable 1 1 "File Name")

(if (/= (length Files_Folder) 0)
(repeat (setq N (length Files_Folder))
(setq e (nth (setq N (- N 1)) Files_Folder))
(setq fsl (strlen e))
(Setq Fsl (- fsl 4))
(setq Fname (substr e 1 fsl))
(vla-setText MyTable (+ N 2) 0 (+ N 1))
(vla-setText MyTable (+ N 2) 1 Fname)
)
(princ "\nDoes not containing any *.DWG File.")
)

(command "cmdecho" 1)
(princ)
)

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 11 of 26

SAFizzy
Advocate
Advocate

thanks bro,

there is something missing, as i am not getting table. 

Its just disappear.

sorry to disturb you 

0 Likes
Message 12 of 26

dbhunia
Advisor
Advisor

Hi

 

I don't know, ..... its tested in AutoCAD 2008........(before 29th October I can not check it in Higher version)

 

Table is creating in "modelSpace".......... Are you in "modelSpace"?????


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 13 of 26

SAFizzy
Advocate
Advocate

yes i am in model space,

but i am using AutoCAD 2015

0 Likes
Message 14 of 26

roland.r71
Collaborator
Collaborator

It works for me. (Using ACAD2018)

0 Likes
Message 15 of 26

Shneuph
Collaborator
Collaborator

I have to agree with @roland.r71  Some people treat this forum like a resource to place orders for free Lisp.  Then they have a habit of getting demanding!  People are here to help each other learn lisp or work through issues they may be having with THEIR code.  Not to write entire subs for people on demand.  I tend to only answer questions when the OP has posted code that they have at least started to write themselves.

 

GOOD:
"I'm having trouble doing xxx with this code.  ::code::  What am I missing? How can I do this?"

 

BAD:
"I want a lisp to blah blah blah....  Good.. now make it do this too.  Bye!"

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 16 of 26

Anonymous
Not applicable

Great. Well working.

 

I have tested it to list out for specific extension of files like pdf's, xls, dwg's or dxf's. Can I use it for specific extensions only?.

 

Advanced Thanks

0 Likes
Message 17 of 26

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

Great. Well working.

 

I have tested it to list out for specific extension of files like pdf's, xls, dwg's or dxf's. Can I use it for specific extensions only?.

 

Advanced Thanks


 

Yes & No.

Yes, you can only define one wildcard. So you can't filter for 2 or 3 different extensions at ones.

No, you can use any wildcard formatted filter. (examples: *.txt : *.* : *.pdf : MyProject-drw????A.dwg etc.)

 

edit:

It will list all files, matching the filter. so *.* gets you a list of all files ( and/or the subdir names) there.

No matter what kind of files it may be.

 

0 Likes
Message 18 of 26

dbhunia
Advisor
Advisor
Accepted solution

Hi,

 

First Thing to do,

 

Table is placing at "0,0,0" .............  Check once at that location......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 19 of 26

SAFizzy
Advocate
Advocate

Thanks, @dbhunia

Yes i got what i am looking for, attached are two images showing list of drawings in folder and table created by lisp.  the only problem in this table is that,  It is too small and not in ascending order.

 

Thanks for help

 


drawings in folder.pngtable created by lisp.png 

0 Likes
Message 20 of 26

dbhunia
Advisor
Advisor
Accepted solution

Hi,

 

For.....

 


@SAFizzy wrote:

Thanks, @dbhunia

Yes i got what i am looking for, attached are two images showing list of drawings in folder and table created by lisp.  the only problem in this table is that,  It is too small and not in ascending order. ................................

 

 

Try this......

 

(defun c:GET_FILES ( / sh folder folderobject result)
(vl-load-com)
(command "cmdecho" 0)
(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
(setq folder (vlax-invoke-method sh 'BrowseForFolder 0 "" 0 ))
(setq MTH (getreal "\nInput the Text Height: "))
(setq WT (getreal "\nWidth of the table: "))
(vlax-release-object sh)
(setq folderobject (vlax-get-property folder 'Self))
(setq result (vlax-get-property FolderObject 'Path))
(setq Files_Folder (vl-directory-files result "*.dwg"))

(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
(setq pt (vlax-3d-point 0 0 0))
(setq modelSpace (vla-get-ModelSpace doc))
(setq MyTable (vla-Addtable modelSpace pt (+ (length Files_Folder) 2) 2 (* MTH 1.3) WT))
(vla-ZoomExtents acadObj)
(vla-setText MyTable 0 0 "Drawing File List")
(vla-setcelltextheight MyTable 0 0 MTH)
(vla-setText MyTable 1 0 "Serial Number")
(vla-setText MyTable 1 1 "File Name")
(acad_strlsort Files_Folder) (if (/= (length Files_Folder) 0) (repeat (setq N (length Files_Folder)) (setq e (nth (setq N (- N 1)) Files_Folder)) (setq fsl (strlen e)) (Setq Fsl (- fsl 4)) (setq Fname (substr e 1 fsl)) (vla-setText MyTable (+ N 2) 0 (+ N 1)) (vla-setText MyTable (+ N 2) 1 Fname) ) (princ "\nDoes not containing any *.DWG File.") ) (setq RN 0) (if (/= (length Files_Folder) 0) (repeat (setq N (+ (length Files_Folder) 1)) (setq RN (+ RN 1)) (vla-setcelltextheight MyTable RN 0 MTH) (vla-setcelltextheight MyTable RN 1 MTH) ) ) (command "cmdecho" 1) (princ) )

 

I had tested this in AutoCAD 2017 & 2018.......its ok.......see the attached image....

 

1.PNG

 

2.PNG

 

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....