anyway to get the dwg list to display just the filenames?

Started by andrew, December 14, 2009, 07:38:08 AM

Previous topic - Next topic

andrew

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

Fred Tomke

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
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

andrew

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


Kerry


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")
)
Perfection is not optional.
My other home is TheSwamp

Fred Tomke

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
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

andrew

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


andrew

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.


Fred Tomke

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
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Fred Tomke

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
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

andrew

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?

Fred Tomke

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
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

andrew

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?

Fred Tomke

andrew,

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

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

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

sachindkini

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

Fred Tomke

Hi, sachindkini, have you already tried to debug to catch the line, where this error occurs?

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]