CoCreate User Forum  

Go Back   CoCreate User Forum > Support > Customization

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 02-01-2011, 08:33 AM
Dave Nowak Dave Nowak is offline
Registered User
 
Join Date: Apr 2008
Location: Stoughton, Wisconsin USA
Posts: 20
Create a list of files in LISP

This is a LISP question.

I have a dialog menu in Modeling that creates a list of all package files in a working directory and allows the user to load it along with the corresponding annotations file.

It works fine except when I have a file with the file extension in upper case (e.g. PKG), the entry does not appear on the list.

In the code the relevant LISP commands are file-namestring and directory. I am not fluent enough in LISP to come up with a solution.

Is there a way to include the upper case file extensions ? (e.g 12-12345.PKG)

here's the code

PHP Code:
 
;***********************************************************************
;
DIALOGLOAD PACKAGE FILE AND ANNOTATION FROM WORK AREA
;***********************************************************************
(
oli::sd-defdialog 'sto_dia_load_files_from_work_area
  :dialog-title "Load From Work Area"
  :toolbox-button nil  
  :variables
  '
((work_area_file
    
:title "F:\\Me10\\*.pkg"
    
:range ("dummy")
    :
initial-value
      
(let ((pkg_files (mapcar 'file-namestring (directory "F:/Me10/*.pkg"))))
      (oli::sd-set-range '
work_area_file pkg_files)
      )
    :
after-input
      
(if (and (oli::sd-inq-file-status (format nil "F:\\Me10\\~a.mi" (subseq work_area_file 0 (- (length work_area_file4))) :existence) (oli::sd-module-active-"ANNOTATION"))
        (
progn
        
(oli::sd-set-variable-status 'load_mi :enable t)
        (oli::sd-set-variable-status '
load_mi :value t)
        )
        (
oli::sd-set-variable-status 'load_mi :enable nil)
      )
    ) ;; end dir-range
    (load_mi
      :value-type    :boolean
      :title " Load MI"
      :initial-value nil
    )
  ) ; end variables
  :after-initialization
    '
(if (oli::sd-module-active-"ANNOTATION")
      (
oli::sd-set-variable-status 'load_mi :enable t)
      (oli::sd-set-variable-status '
load_mi :enable nil)      
    )
  :
ok-action
    
'(sto_fun_load_files_from_work_area work_area_file load_mi)
) ; end dialog 

Any help is appreciated.
 
Dave Nowak
Reply With Quote
  #2  
Old 02-07-2011, 12:36 PM
Wolfgang's Avatar
Wolfgang Wolfgang is offline
Registered User
 
Join Date: Nov 2002
Location: ... near Sindelfingen near Stuttgart, Germany
Posts: 754
Re: Create a list of files in LISP

append, as well as nconc does concatenate 2 lists to have one at the end.
Code:
(let ((pkg_files (append (mapcar 'file-namestring (directory "F:/Me10/*.pkg"))
                         (mapcar 'file-namestring (directory "F:/Me10/*.PKG"))))))
Code:
(let ((pkg_files (mapcar 'file-namestring (append (directory "F:/Me10/*.pkg")
                                                  (directory "F:/Me10/*.PKG"))))))
Both variants should work (just typed, not tested!). The latter one makes it easier to maintain.. e.g. when you use another function to apply via mapcar

Last edited by Wolfgang; 02-09-2011 at 10:26 AM. Reason: fixed the wrong brackets as mentioned in next post..
Reply With Quote
  #3  
Old 02-09-2011, 06:28 AM
Dave Nowak Dave Nowak is offline
Registered User
 
Join Date: Apr 2008
Location: Stoughton, Wisconsin USA
Posts: 20
Re: Create a list of files in LISP

Thanks for the input Wolfgang
 
Now I do have all the package files in a list, both of your examples work.
Just a slight change to the second example where I move the parentheses for the append.

PHP Code:
(let ((pkg_files (mapcar 'file-namestring (append (directory "F:/Me10/*.pkg")
                                                 (directory "F:/Me10/*.PKG")))))) 
One little issue still remains and that is sorting of the list, the files with the upper case extension appear at the end of the list. I would like the entire list to be sorted by file name.

e.g. Instead of this list
123.pkg
246.pkg
567.pkg
321.PKG
456.PKG
  
I would like this list
123.pkg
246.pkg
321.PKG
456.PKG
567.pkg
 
It seems there is a sort command in LISP but I can not get it to go.

Again any help is appreciated
 
Dave Nowak
Reply With Quote
  #4  
Old 02-09-2011, 10:34 AM
Wolfgang's Avatar
Wolfgang Wolfgang is offline
Registered User
 
Join Date: Nov 2002
Location: ... near Sindelfingen near Stuttgart, Germany
Posts: 754
Re: Create a list of files in LISP

Quote:
Originally Posted by Dave Nowak View Post
Thanks for the input Wolfgang
Now I do have all the package files in a list, both of your examples work.
fine!
Quote:
It seems there is a sort command in LISP but I can not get it to go.
Code:
(sort the-list #'the-sort-function)  ;; returns the sorted list
The sort function decides which of 2 given elements is the 'smaller' one, resp has to be BEFORE the other one in a sorted sequence. This function is called as often as needed to get the list sorted.

example:
Code:
(sort '(5 9 78 6 7 8 9 3 8 4 17) #'<)
Use > instead of < and you get the list the other way around


Code:
(let ((pkg_files (sort (mapcar 'file-namestring 
                               (append (directory "F:/Me10/*.pkg")
                                       (directory "F:/Me10/*.PKG"))) #'string< ))))

Last edited by Wolfgang; 02-09-2011 at 10:41 AM.
Reply With Quote
  #5  
Old 02-09-2011, 11:18 AM
Dave Nowak Dave Nowak is offline
Registered User
 
Join Date: Apr 2008
Location: Stoughton, Wisconsin USA
Posts: 20
Re: Create a list of files in LISP

Thanks Wolfgang

The sort works, below is the complete code for anyone interested.

Code:
 
;***********************************************************************
;DIALOG, LOAD PACKAGE FILE AND ANNOTATION FROM WORK AREA
;***********************************************************************
(oli::sd-defdialog 'sto_dia_load_files_from_work_area
  :dialog-title "Load From Work Area"
  :toolbox-button nil  
  :variables
  '((work_area_file
    :title "F:\\Me10\\*.pkg"
    :range ("dummy")
    :initial-value
      (let ((pkg_files (sort (mapcar 'file-namestring (append (directory "F:/Me10/*.PKG")
                                                              (directory "F:/Me10/*.pkg"))) #'string<)))
      (oli::sd-set-range 'work_area_file pkg_files)
;      (car pkg_files) ;select first in list
      )
    :after-input
      (if (and (oli::sd-inq-file-status (format nil "F:\\Me10\\~a.mi" (subseq work_area_file 0 (- (length work_area_file) 4))) :existence) (oli::sd-module-active-p "ANNOTATION"))
        (progn
        (oli::sd-set-variable-status 'load_mi :enable t)
        (oli::sd-set-variable-status 'load_mi :value t)
        )
        (oli::sd-set-variable-status 'load_mi :enable nil)
      )
    ) ;; end dir-range
    (load_mi
      :value-type    :boolean
      :title " Load MI"
      :initial-value nil
    )
  ) ; end variables
  :after-initialization
    '(if (oli::sd-module-active-p "ANNOTATION")
      (oli::sd-set-variable-status 'load_mi :enable t)
      (oli::sd-set-variable-status 'load_mi :enable nil)      
    )
  :ok-action
    '(sto_fun_load_files_from_work_area work_area_file load_mi)
) ; end dialog
(defun sto_fun_load_files_from_work_area (work_area_file load_mi)
  ;reset session
  (uic_reset_session :yes)
  (if (oli::sd-module-active-p "ANNOTATION")
    (progn
    (oli::sd-switch-application "Annotation")
    (am_drawing_delete :dwg)
    (oli::sd-maximize-vp "Annotation")
    )
  )
  (load_package (format nil "F:\\Me10\\~a" work_area_file))
  (if (and load_mi (oli::sd-module-active-p "ANNOTATION"))
    (progn
    (am_load_drawing :filename (format nil "F:\\Me10\\~a.mi" (subseq work_area_file 0 (- (length work_area_file) 4))))
    )
  )
  (oli::sd-switch-application "SolidDesigner")  
)
Dave Nowak
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 10:15 AM.



Hosted by SureServer    Forums   Modeling FAQ   Macro Site   Vendor/Contractors   Software Resellers   CoCreate   Gallery   Home   Board Members   Regional User Groups  By-Laws  

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
You Rated this Thread: