OpenDCL Forums

OpenDCL => Studio/Dialog Editor => Topic started by: andrew on December 14, 2009, 07:38:08 AM

Title: anyway to get the dwg list to display just the filenames?
Post by: andrew on December 14, 2009, 07:38:08 AM
is it possible to get the dwg list function to display only the file names and not the thumbnails?

reason i ask is because i have a few directories with more then 200 dwgs in them and when i select anyone of those directories via my project, the dialog box closes.

i tried using the listbox to avoid the thumbnail views but it doesnt work the same.

any suggestions or possible work around welcomed
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Fred Tomke on December 14, 2009, 07:41:13 AM
Hi, andrew,

Quote from: andrew on December 14, 2009, 07:38:08 AM
i tried using the listbox to avoid the thumbnail views but it doesnt work the same.

Why did it not work?
I just wanted to recommend you to do it like Windows Explorer: toggle between DWG-List and listbox or listview.
Why shouldn't it work?

Fred
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: andrew on December 14, 2009, 08:32:24 AM
Quote from: Fred Tomke on December 14, 2009, 07:41:13 AM
Hi, andrew,

Quote from: andrew on December 14, 2009, 07:38:08 AM
i tried using the listbox to avoid the thumbnail views but it doesnt work the same.

Why did it not work?
I just wanted to recommend you to do it like Windows Explorer: toggle between DWG-List and listbox or listview.
Why shouldn't it work?

Fred

Hi Fred,

I have it working like that, sorta, instead of showing the filename in the dwglist, it shows the filename AND thumbnail.
after testing it further, it appears that the dialog and acad will crash if the directory your are displaying in the dwg list window has more then 1000 dwgs, even then it gives you a "no responding" warning then it comes out of it and displays the dwgs.

when i made a test project using a listbox instead of a dwglist, it was able to diplay the filenames of more then 1000 dwgs and not crash but i just couldnt get the "up a directory" to work.

here are my project files if you want to see how i have it
i know the code is a mess but it works i just wont display more then 1000 dwgs.


critiquing welcomed
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Fred Tomke on December 14, 2009, 09:57:47 AM
Quote from: andrew on December 14, 2009, 08:32:24 AM
when i made a test project using a listbox instead of a dwglist, it was able to diplay the filenames of more then 1000 dwgs and not crash but i just couldnt get the "up a directory" to work.

Unfortunately, you have not send the version with the listbox - as far as I can see it.
Note: you will have to fill the list by your own.

Fred
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: andrew on December 14, 2009, 10:03:13 AM
Quote from: Fred Tomke on December 14, 2009, 09:57:47 AM
Quote from: andrew on December 14, 2009, 08:32:24 AM
when i made a test project using a listbox instead of a dwglist, it was able to diplay the filenames of more then 1000 dwgs and not crash but i just couldnt get the "up a directory" to work.

Unfortunately, you have not send the version with the listbox - as far as I can see it.
Note: you will have to fill the list by your own.

Fred

no i didnt Fred.
I wasnt having much luck with getting it to work so i just abandoned it and went back to my working project and just put in some code to stop the selection of this specific directory from being selected

however if anyone wishes to check out my working project and critique it i welcome all. i would love to improve upon it.

Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Fred Tomke on December 15, 2009, 07:54:59 AM
Hi andrew,

have a look with the attached sample, it should work (note: refreshing the dwgpreview may not work in the current alpha release, but in the stable release).

Fred

EDIT: Replace the function dwgbrowser_fillpreview with the version below to update the preview in the current Alpha release:
If you make the scrollbar working, you wil have a similar way to navigate between the dwg-files.

Code (autolisp) Select

(defun dwgbrowser_fillpreview (intItem / strPath intRow strCompleteFile)
  (setq strPath (dwgbrowser_check_path (dcl_ComboBox_GetDir dwgbrowser_browser_dir)))
  (setq intLen (dcl_ListView_GetCount dwgbrowser_browser_lst))
  (foreach intRow '(0 1 2 3 4 5 6 7 8)
    (if (>= (+ intItem (1+ intRow)) intLen)
      (dwgbrowser_invisible (eval (read (strcat "dwgbrowser_browser_dwg" (itoa (1+ intRow))))))
      (progn
        (setq oControl (eval (read (strcat "dwgbrowser_browser_dwg" (itoa (1+ intRow))))))
        (dwgbrowser_visible oControl)
        (if (setq strCompleteFile (findfile (strcat strPath (dcl_ListView_GetItemText dwgbrowser_browser_lst intRow 0) ".dwg")))
          (progn
            (dcl_DWGPreview_LoadDwg oControl strCompleteFile)
            (dcl_Control_Redraw oControl)
          ); progn
          (dcl_DwgPreview_Clear oControl)
        ); if
      ); progn
    ); if
  ); foreach
); dwgbrowser_fillpreview
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: andrew on December 16, 2009, 07:17:15 AM
Thanks Fred for the sample files.
I ran them as a test to see how it works, and even your coding "hangs" while trying to access a directory with more then 1000 files

Title: Re: anyway to get the dwg list to display just the filenames?
Post by: andrew on December 16, 2009, 12:17:30 PM
Fred,
After overlooking your code
im a bit confused on a list view function as i tried to duplicated it from scratch and just get errors maybe you or anyone else thats reading can clarify for me what it is that im not understanding.

(dcl_ListView_FillList od-test_Form1_ListView1 as List of Lists  as ((ItemLabel [as String] {ItemImageIndex [as Integer]} {Column1Label [as String]} {Column1ImageIndex [as Integer]} ...) ...))

a list of lists...
what exactly is a list of lists?

example:
if my lsp code reads a file and puts the contents of that file in a list
the function code i have reads
(dcl_ListView_FillList od-test_Form1_ListView1
      (list filelist)

)

with it this way it only shows the first item of the list and not the others
how do you go about getting the other items to display?




Title: Re: anyway to get the dwg list to display just the filenames?
Post by: BazzaCAD on December 16, 2009, 12:40:03 PM
Quote from: andrew on December 16, 2009, 12:17:30 PM

(dcl_ListView_FillList od-test_Form1_ListView1 as List of Lists  as ((ItemLabel [as String] {ItemImageIndex [as Integer]} {Column1Label [as String]} {Column1ImageIndex [as Integer]} ...) ...))

a list of lists...
what exactly is a list of lists?



Code (autolisp) Select

(list
 (list "Item 1" 1 1 1)
  (list "Item 2" 2 2 2)
  (list "Item 3" 3 3 3)
)
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Kerry on December 16, 2009, 01:00:44 PM

Andrew,
Do you just want to feed the fileList to the ListView ?
ie what do you want the listView to look like ?
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: andrew on December 16, 2009, 01:17:36 PM
Quote from: Kerry Brown on December 16, 2009, 01:00:44 PM

Andrew,
Do you just want to feed the fileList to the ListView ?
ie what do you want the listView to look like ?

yes
thats what i was trying to do but i get errors
example of what i tried:


  (setq dfile "C:\\test.txt")
  (setq fil (open dfile "r")) 
   (while (setq curline (read-line fil)) 
      (setq filelist (cons curline filelist)) 
  ) 
  (close fil) 

  (setq filelist (reverse filelist))

(dcl_ListView_FillList od-test_Form1_ListView1
(list filelist)
)

this list only displays the first item of the list.

using :
(dcl_ListView_FillList od-test_Form1_ListView1
(list
   (list filelist)
)
)
doesnt work
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: andrew on December 16, 2009, 01:18:30 PM
Quote from: BazzaCAD on December 16, 2009, 12:40:03 PM
Quote from: andrew on December 16, 2009, 12:17:30 PM

(dcl_ListView_FillList od-test_Form1_ListView1 as List of Lists  as ((ItemLabel [as String] {ItemImageIndex [as Integer]} {Column1Label [as String]} {Column1ImageIndex [as Integer]} ...) ...))

a list of lists...
what exactly is a list of lists?



Code (autolisp) Select

(list
 (list "Item 1" 1 1 1)
  (list "Item 2" 2 2 2)
  (list "Item 3" 3 3 3)
)


thats what i thought it was but i get errors when i do that
just wanted to make sure i understood it correctly
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Kerry on December 16, 2009, 02:09:00 PM
Andrew ,
The trick is in how you translate the fileList into a list of lists.
If you JUST want the list in column 1 try something like this :

Code (autolisp) Select
(setq populatelist1 (mapcar '(lambda (x) (list x)) layernamelist))

Code (autolisp) Select


(vl-load-com)
(command "_OPENDCL")

(defun c:doit (/ layernamelist dialogreturn)
 (setq layernamelist '("0"          "Layer1"     "Layer2"
                       "Layer3"     "Layer4"     "Layer5"
                       "Layer6"     "Layer7"     "Layer8"
                       "Layer9"     "Layer10"    "Layer11"
                       "Layer12"
                      )
 )
 (dcl_project_load "kdub_ListView_11.odcl" t)
 ;; Show the main form
 (setq dialogreturn (dcl_form_show kdub_listview_11_main))
 ;;------
 (princ)
)

;|<<OpenDCL Event Handlers>>|;
(defun c:kdub_listview_11_main_oninitialize (/)
 (dcl_listview_addcolumns
   kdub_listview_11_main_listview1
   '(("Layer Name" 0 100) ("Col 2" 0 50) ("Col 3" 0 50))
 )
 (dcl_listview_addstring kdub_listview_11_main_listview1
                         "Item 1\tItem 1-2\tItem 1-3"
 )
)
(defun c:kdub_listview_11_main_textbutton1_onclicked (/)
 (setq populatelist1 (mapcar '(lambda (x) (list x)) layernamelist))
 (dcl_listview_filllist kdub_listview_11_main_listview1
                        populatelist1
 )
)
(princ " << Enter DOIT to run >> \n")
(princ)



if you want more than this, you'll have to start explaining what you want.

Refer the Attachments:
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Fred Tomke on December 16, 2009, 03:53:21 PM
Quote from: andrew on December 16, 2009, 07:17:15 AM
Thanks Fred for the sample files.
I ran them as a test to see how it works, and even your coding "hangs" while trying to access a directory with more then 1000 files

H andrew, I recommend you a closer look to your drawings.

1. Of course it take a while until the files were read out. But you should have noted a text within the listview (see loading.png). Have you seen it?

2. As you can see in my screenshot listing.png that I could list 5705 dwg files. I had to wait 5 seconds for the first time. But i other cases I had to wait 30 seconds (depending on the harddrive speed).

I think that maybe one of your drawings may be corrupt? Can you compress them and send them as email attachment to me?

Fred
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Kerry on December 16, 2009, 03:57:48 PM


I think, somehow, we are all talking about different things :)

I may have missed something.
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: andrew on December 17, 2009, 05:56:54 AM
Quote from: Kerry Brown on December 16, 2009, 03:57:48 PM


I think, somehow, we are all talking about different things :)

I may have missed something.

Kerry,
Thanks for your help
yes we are talking about 2 different things but they are related
i tried your method and it didnt work for me.
im essentially trying to read a test file and file the list with the contents of that text file (i listed the code in a previous post)
the trick is as you said is changing the list into a list of lists

Fred,
Sorry i cannot zip the files and send them.
i was mistaken with the program hanging, i noticed that it does not hang when i select a sub directory, it just doesnt load it because i get this error

Command: ; error: bad argument type: stringp nil
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Fred Tomke on December 17, 2009, 06:48:38 AM
Quote from: andrew on December 17, 2009, 05:56:54 AM
[...]i noticed that it does not hang when i select a sub directory, it just doesnt load it because i get this error

Command: ; error: bad argument type: stringp nil


Then there must be a bug. Can you find out the place where this error occurs?
Maybe the error does not occure with the attached files...

Fred
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: andrew on December 17, 2009, 08:17:07 AM
Fred, ill check it out

appreciate your help

also i got the list of lists working
now i just have to figure out how to get the dwgs and subdirectories to show up in that list

thanks again for all of y'alls help

Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Kerry on December 17, 2009, 02:07:34 PM

andrew,
The list translator I posted was modified from one I use t build compound lists ...

This may be better suited and easier to understand for simple lists.
Code (autolisp) Select


(setq layernamelist '("0"          "Layer1"     "Layer2"
                     "Layer3"     "Layer4"     "Layer5"
                     "Layer6"     "Layer7"     "Layer8"
                     "Layer9"     "Layer10"    "Layer11"
                     "Layer12"
                    )
)

(setq ListViewList (mapcar 'list layernamelist) )



returns
(("0") ("Layer1")
       ("Layer2")
       ("Layer3")
       ("Layer4")
       ("Layer5")
       ("Layer6")
       ("Layer7")
       ("Layer8")
       ("Layer9")
       ("Layer10")
       ("Layer11")
       ("Layer12")
)
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Fred Tomke on December 17, 2009, 11:05:19 PM
Quote from: andrew on December 17, 2009, 08:17:07 AM
now i just have to figure out how to get the dwgs and subdirectories to show up in that list

That should be found in the code :)

Code (autolisp) Select

(setq lstDir (vl-directory-files strPath "*" -1)) ;; directories only
(setq lstDwg (vl-directory-files strPath "*.dwg" 1))


Have a look at the OpenDCL dwglist sample. The function for the directory-up-button is much better than mine.

Fred

Fred
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: andrew on December 18, 2009, 06:54:41 AM
your help is appreciated however i think im just gonna have to put this on the back burner for now, what im trying to get it to do, i think is a little more advanced then my current understanding of this odcl coding.

hope everyone has a happy and safe holiday

Title: Re: anyway to get the dwg list to display just the filenames?
Post by: andrew on January 04, 2010, 06:42:54 AM
Fred, I have a strange question to ask you about your code in your dwgbrowser program.

when i run it, if i select a directory that has a dwg opened from that directory, i get an error

Command: ; error: bad argument type: stringp nil

ive tested and retested, and as long as there isnt a dwg opened from that directory, it works.

would you have any clue as to why this happens?
its not just this directory, its any directory that has a dwg opened, it yields an error.

any light you can shed on this is appreciated

running it thru vlide it stops on error on this part
(cadddr (cdr lstDate))

the function is:
(defun dwgbrowser_file_date (strFile / lstDate)
 (setq lstDate (mapcar 'dwgbrowser_check_digit (mapcar 'itoa (vl-file-systime strFile))))
 (strcat (car lstDate) "-" (cadr lstDate) "-" (caddr lstDate) " " (cadddr lstDate) ":" (cadddr (cdr lstDate)))
); dwgbrowser_file_date

i narrowed it down further to this function:
(vl-file-systime strFile)
if the file is open, then this returns nil.

Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Fred Tomke on January 04, 2010, 11:58:53 AM
Hi, that's bad. (vl-file-size ...) is working properly instead!

Have a try with the FileSystem object:

Code (autolisp) Select

(defun file_getdate (strFile / lstRet oFSObject oFile reaDate intYear intDay is2902 lstMonths intMonth
                               intDay reaTime reaHour intHour reaMinutes intMinutes reaSeconds intSeconds)
  (setq oFSObject (vlax-create-object "Scripting.FileSystemObject"))
  (if (or (null (setq oFile (vl-catch-all-apply 'vlax-invoke-method (list oFSObject "GetFile" strFile))))
  (vl-catch-all-error-p oFile))
    (setq oFile nil
          lstRet '(1900 01 01 00 00 00))
    (progn
      (setq reaDate (vlax-get oFile 'DateLastModified))
      (setq intYear (+ 1900 (fix (/ reaDate 365.25))))
      (setq intDay (fix (- reaDate (* (fix (/ reaDate 365.25)) 365.25))))
      (setq is2902 (= (* 365.25 (fix (/ reaDate 365.25)))
                      (fix (* 365.25 (fix (/ reaDate 365.25))))))

      (setq lstMonths (list (cons 1 31) (cons 2 (if is2902 29 28)) (cons 3 31) (cons 4 30) (cons 5 31) (cons 6 30)
                            (cons 7 31) (cons 8 31) (cons 9 30) (cons 10 31) (cons 11 30) (cons 12 31)))
      (setq intMonth (caar lstMonths))

      (while (and lstMonths (> (- intDay (cdar lstMonths)) 0.0))
        (setq intDay (- intDay (cdar lstMonths))
              intMonth (caadr lstMonths)
              lstMonths (cdr lstMonths))
      ); while

      (setq reaTime (- reaDate (fix reaDate)))
      (setq reaHour (* 24 reaTime))
      (setq intHour (fix reaHour))
      (setq reaMinutes (* 60 (- reaHour intHour)))
      (setq intMinutes (fix reaMinutes))
      (setq reaSeconds (* 60 (- reaMinutes intMinutes)))
      (setq intSeconds (fix reaSeconds))
      (setq lstRet (list intYear intMonth intDay intHour intMinutes intSeconds))
     
      (vlax-release-object oFile)
    ); progn
  ); if
  (vlax-release-object oFSObject)
  lstRet
); file_getdate



Fred
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Fred Tomke on January 05, 2010, 12:12:47 AM
Hello,

I've changed the code a bit. Because there is still a bug with the leapyear and with milliseconds. Maybe others may have a look at both.

Code (autolisp) Select

(defun file_getdate (strFile / lstRet oFSObject oFile reaDate intYear intDay is2902
                                   lstMonths intMonth reaWeek intWeek intDay reaTime
                                   reaHour intHour reaMinutes intMinutes reaSeconds
                                   intSeconds reaMSec intMSec)
  (cond
    ((not (findfile strFile)) (setq lstRet '(1900 01 0 01 00 00 00 00)))
    ((setq lstRet (vl-file-systime strFile)) nil)
    ((not (and (setq oFSObject (vlax-create-object "Scripting.FileSystemObject"))
               (setq oFile (vl-catch-all-apply 'vlax-invoke-method (list oFSObject "GetFile" strFile)))
               (not (vl-catch-all-error-p oFile))))
     (setq lstRet '(1900 01 0 01 00 00 00 00)
           oFile nil))
    (oFile
     (setq reaDate (1- (vlax-get oFile 'DateLastModified)))
     (setq reaWeek (/ (fix reaDate) 7.0))
     (setq intWeek (atoi (rtos (* 7.0 (- reaWeek (fix reaWeek))) 2 0)))
     (setq intYear (+ 1900 (fix (/ reaDate 365.25))))
     (setq intDay (fix (- reaDate (* (fix (/ reaDate 365.25)) 365.25))))
     (setq is2902 (= (* 365.25 (fix (/ reaDate 365.25)))
                     (fix (* 365.25 (fix (/ reaDate 365.25))))))

     (setq lstMonths (list (cons 1 31) (cons 2 (if is2902 29 28)) (cons 3 31) (cons 4 30) (cons 5 31) (cons 6 30)
                           (cons 7 31) (cons 8 31) (cons 9 30) (cons 10 31) (cons 11 30) (cons 12 31)))
     (setq intMonth (caar lstMonths))

     (while (and lstMonths (> (- intDay (cdar lstMonths)) 0.0))
       (setq intDay (- intDay (cdar lstMonths))
             intMonth (caadr lstMonths)
             lstMonths (cdr lstMonths))
     ); while

     (setq reaTime (- reaDate (fix reaDate)))
     (setq reaHour (* 24.0 reaTime))
     (setq intHour (fix reaHour))
     (setq reaMinutes (* 60.0 (- reaHour intHour)))
     (setq intMinutes (fix reaMinutes))
     (setq reaSeconds (* 60.0 (- reaMinutes intMinutes)))
     (setq intSeconds (fix reaSeconds))
     (setq reaMSec (* 1000.0 (- reaSeconds intSeconds)))
     (setq intMSec (fix reaMSec))
     (setq lstRet (list intYear intMonth intWeek intDay intHour intMinutes intSeconds intMSec)))
  ); cond
  (mapcar 'vlax-release-object (vl-remove nil (list oFSObject oFile)))
  lstRet
); file_getdate


Fred
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: andrew on January 06, 2010, 08:19:57 AM
Fred, thanks for the reply.

works good now.

thanks

also.
how did you get the file and directory icons to show up in that list?
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Fred Tomke on January 06, 2010, 08:40:28 AM
Hi, andrew,

doubleclick the listview control in the Z/Tab order pane. There is the imagelist for this control.
An these icons are used in the list for dcl_listview_filllist method.

Fred
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: andrew on January 06, 2010, 09:15:17 AM
Fred,
Thanks for your help again
here is my simple test code.

is there something i need to turn on?
i added my image to the image list however the icon doesnt display



(defun c:dwgbrowser_Form3_OnInitialize (/)
(dcl_ListView_AddColumns dwgbrowser_Form3_ListView1 (list (list "1" 0 100) (list "2" 0 100) ))
(dcl_ListView_FillList
dwgbrowser_Form3_ListView1
 (list
  (list "hello 0 "world" 0)
 )
)
)


i got it working, i dont know what i did to get it working most likely something stupid i missed but i got it working
thanks

p.s. where do you get your icons from?
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Fred Tomke on January 06, 2010, 10:46:17 AM
andrew,

Quote
Code (autolisp) Select
(list "hello 0 "world" 0)

Count the number of "-chars in the line above.  ;)

Fred
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: sachindkini on August 19, 2010, 10:50:12 PM
Quote from: Fred Tomke on December 15, 2009, 07:54:59 AM
Hi andrew,

have a look with the attached sample, it should work (note: refreshing the dwgpreview may not work in the current alpha release, but in the stable release).

Fred

EDIT: Replace the function dwgbrowser_fillpreview with the version below to update the preview in the current Alpha release:
If you make the scrollbar working, you wil have a similar way to navigate between the dwg-files.

Code (autolisp) Select

(defun dwgbrowser_fillpreview (intItem / strPath intRow strCompleteFile)
  (setq strPath (dwgbrowser_check_path (dcl_ComboBox_GetDir dwgbrowser_browser_dir)))
  (setq intLen (dcl_ListView_GetCount dwgbrowser_browser_lst))
  (foreach intRow '(0 1 2 3 4 5 6 7 8)
    (if (>= (+ intItem (1+ intRow)) intLen)
      (dwgbrowser_invisible (eval (read (strcat "dwgbrowser_browser_dwg" (itoa (1+ intRow))))))
      (progn
        (setq oControl (eval (read (strcat "dwgbrowser_browser_dwg" (itoa (1+ intRow))))))
        (dwgbrowser_visible oControl)
        (if (setq strCompleteFile (findfile (strcat strPath (dcl_ListView_GetItemText dwgbrowser_browser_lst intRow 0) ".dwg")))
          (progn
            (dcl_DWGPreview_LoadDwg oControl strCompleteFile)
            (dcl_Control_Redraw oControl)
          ); progn
          (dcl_DwgPreview_Clear oControl)
        ); if
      ); progn
    ); if
  ); foreach
); dwgbrowser_fillpreview

dear sir
some error on program se attched file
Title: Re: anyway to get the dwg list to display just the filenames?
Post by: Fred Tomke on August 23, 2010, 04:57:53 AM
Hi, sachindkini, have you already tried to debug to catch the line, where this error occurs?

Fred