CoCreate User Forum  

Go Back   CoCreate User Forum > Support > Customization
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 04-01-2008, 11:27 PM
Maximus172 Maximus172 is offline
Registered User
 
Join Date: May 2007
Location: France
Posts: 52
List box with specific directory ?

Hello,

I would like to know if it is possible to create a list box, in which I will have all the files in a specific directory.

In fact, instead of complete the "Range" for a variable, I would like to "scan" the directory and increase the list...


I'm not sure to be clear

Thanks
Reply With Quote
  #2  
Old 04-02-2008, 12:49 AM
clausb's Avatar
clausb clausb is offline
Registered User
 
Join Date: Nov 2002
Posts: 1,168
Re: List box with specific directory ?

I'm assuming we're talking about Modeling, not Drafting.

Well, AFAIK, the range can be filled with just about anything, including the results of directory scanning.

Claus
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/
Reply With Quote
  #3  
Old 04-02-2008, 06:22 AM
Maximus172 Maximus172 is offline
Registered User
 
Join Date: May 2007
Location: France
Posts: 52
Re: List box with specific directory ?

Ok

I will try to do that, but do you know how to scan a directory ?

Thanks
Reply With Quote
  #4  
Old 04-02-2008, 06:28 AM
clausb's Avatar
clausb clausb is offline
Registered User
 
Join Date: Nov 2002
Posts: 1,168
Re: List box with specific directory ?

See Common Lisp documentation on (directory) - http://www.lisp.org/HyperSpec/Body/fun_directory.html.

A while back, I wrote sample code which also uses (directory), see
http://www.clausbrod.de/OneSpaceModeling/MacroListDirectory.
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/
Reply With Quote
  #5  
Old 04-02-2008, 10:02 AM
Wolfgang's Avatar
Wolfgang Wolfgang is offline
Registered User
 
Join Date: Nov 2002
Location: ... near Sindelfingen near Stuttgart, Germany
Posts: 754
Re: List box with specific directory ?

about:
PHP Code:
(sd-defdialog ....
 (
dir-range :range ("dummy")
            :
initial-value
              
(let ((dir-contents (mapcar 'namestring (directory "c:/*.*")))
                (sd-set-range '
dir-range dir-contents)
                (
car dir-contents))) 
The 'trick' is using sd-set-range, which makes a range dynamic at run time.

not tested these lines, only written
Reply With Quote
  #6  
Old 10-15-2008, 04:19 AM
Maximus172 Maximus172 is offline
Registered User
 
Join Date: May 2007
Location: France
Posts: 52
Unhappy Re: List box with specific directory ?

Hello,

I'm back with this post today...I didn't need before, but now...

Quote:
(sd-defdialog ....
(dir-range :range ("dummy")
:initial-value
(let ((dir-contents (mapcar 'namestring (directory "c:/*.*")))
(sd-set-range 'dir-range dir-contents)
(car dir-contents)))
I have problems to create this macro due to my poor knowledge in Lisp language . Could you help me ?

I used these lines, but I have nothing in my listbox...I would like to find all pkg files in a directory...
Reply With Quote
  #7  
Old 10-15-2008, 11:58 AM
Wolfgang's Avatar
Wolfgang Wolfgang is offline
Registered User
 
Join Date: Nov 2002
Location: ... near Sindelfingen near Stuttgart, Germany
Posts: 754
Re: List box with specific directory ?

.. half a year later...

Hi Maximus,

try to create TINY test dialogs when you have a problem. Just with that part you have a problem with. And post this tiny thing completely. This saves time , for me and for you.

The problem you might have had is a parentheses issue. Well that's typical lisp: Either you have 2 parentheses to less or 3 to much or some/one at the wrong place or something in between
PHP Code:
(in-package :my-tools)
(use-
package :oli)
(
sd-defdialog 'dir_as_range
 :variables
  '
((dir-range :range ("dummy")
               :
initial-value
                 
(let ((dir-contents (mapcar 'namestring (directory "d:/*.png"))))
                       (sd-set-range '
dir-range dir-contents)
                       (
car dir-contents))
    ) ;; 
end dir-range
   
) ; end variables
  
) ; end dialog 
compare carefully with your code snippet!

LISP Lost In Stupid Parentheses

PS: please use the [code] BB Code when posting sources, then we can see indenting, too.

Last edited by Wolfgang; 10-15-2008 at 12:02 PM. Reason: bad typo
Reply With Quote
  #8  
Old 10-15-2008, 11:45 PM
clausb's Avatar
clausb clausb is offline
Registered User
 
Join Date: Nov 2002
Posts: 1,168
Re: List box with specific directory ?

Quote:
Originally Posted by Wolfgang View Post
try to create TINY test dialogs when you have a problem.
Truer words have rarely been spoken. Many programming problems which come up in forums like this become blindingly obvious once they are broken down to a few lines of code.

To avoid problems like this, get an editor which matches parentheses and indents Lisp code automatically. With such an editor, you'll be able to detect if there are too many or not enough parentheses just by looking at the physical layout of your code.

For example, your version of the :initial-value form looks roughly like this in Emacs:
Code:
  :initial-value
  (let ((dir-contents (mapcar 'namestring (directory "c:/*.*")))
        (sd-set-range 'dir-range dir-contents)
        (car dir-contents)))
Note how the sd-set-range and car calls line up with the definition of dir-contents, i.e. as if sd-set-range and car were two more local variables! (And indeed, this is how Lisp will try to parse your code.)

And here's Wolfgang's version:
Code:
  :initial-value
   (let ((dir-contents (mapcar 'namestring (directory "d:/*.png"))))
     (sd-set-range 'dir-range dir-contents)
     (car dir-contents)))
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/

Last edited by clausb; 10-16-2008 at 12:06 AM.
Reply With Quote
  #9  
Old 10-16-2008, 03:11 AM
Maximus172 Maximus172 is offline
Registered User
 
Join Date: May 2007
Location: France
Posts: 52
Re: List box with specific directory ?

Thanks for your help. I will take care

I have one problem with this code.

Now, I have a list of all pkg file, but in the active directory, and not in a specific (c:\*.pkg for example).

Last edited by Maximus172; 10-16-2008 at 03:17 AM.
Reply With Quote
  #10  
Old 10-16-2008, 03:25 AM
clausb's Avatar
clausb clausb is offline
Registered User
 
Join Date: Nov 2002
Posts: 1,168
Re: List box with specific directory ?

The local test example that I use works as expected.

What does your current code look like, and which version of CoCreate Modeling do you use?

Claus
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/
Reply With Quote
  #11  
Old 10-16-2008, 04:38 AM
Maximus172 Maximus172 is offline
Registered User
 
Join Date: May 2007
Location: France
Posts: 52
Re: List box with specific directory ?

The version of OSD is 14.50.

I'm confus, it's works..I forgot to specify the good directory.

Can we avoid to have the paths of the files, and show in the listbox just the pkg file ?


Thanks a lot for your help
Reply With Quote
  #12  
Old 10-16-2008, 04:50 AM
clausb's Avatar
clausb clausb is offline
Registered User
 
Join Date: Nov 2002
Posts: 1,168
Re: List box with specific directory ?

The list box displays whatever you feed it. So if you don't want the path to be displayed, feed the list box with just the file names.

Maybe you can also use the special :label syntax for range variables to achieve what you want. See the IKIT documentation on sd-set-range.

Claus
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/
Reply With Quote
  #13  
Old 10-16-2008, 04:56 AM
clausb's Avatar
clausb clausb is offline
Registered User
 
Join Date: Nov 2002
Posts: 1,168
Re: List box with specific directory ?

Here's a code example based on Wolfgang's proposal:

Code:
(in-package :my-tools)
(use-package :oli)

(sd-defdialog 
 'dir_as_range
 :variables
 '((dir-range :range ("dummy")
    :initial-value
    (let ((dir-contents 
           (mapcar #'(lambda(path) 
                       (list (namestring path) :label (file-namestring path)))
                   (directory "c:/temp/*.pkg"))))
      (sd-set-range 'dir-range dir-contents)
      (car dir-contents))
    )))
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/
Reply With Quote
  #14  
Old 10-16-2008, 09:37 AM
Wolfgang's Avatar
Wolfgang Wolfgang is offline
Registered User
 
Join Date: Nov 2002
Location: ... near Sindelfingen near Stuttgart, Germany
Posts: 754
Re: List box with specific directory ?

Quote:
Originally Posted by clausb View Post
...To avoid problems like this, get an editor which matches parentheses and indents Lisp code automatically.
We promote NotePad++ at several places. Language dependent "indent" functionality is the only reason that I'm still using emacs (in parallel to NotePad++) . And the best is that emacs can do this job even on already written code!
Reply With Quote
  #15  
Old 10-16-2008, 09:53 AM
clausb's Avatar
clausb clausb is offline
Registered User
 
Join Date: Nov 2002
Posts: 1,168
Re: List box with specific directory ?

Yup, Notepad++ is a great little editor because it knows how to properly deal with Unicode-encoded text files, and because it can highlight Lisp code. It's just so much better than the editors which come with Windows.

However, for any serious Lisp development, I'd still recommend Emacs. For new users, EmacsW32 ( http://www.ourcomments.org/Emacs/EmacsW32.html ) can be an interesting option, as it tries to make it easier for Windows users to learn Emacs. Other important Emacs versions are XEmacs and, of course, [GNU Emacs.

Claus
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/
Reply With Quote
Reply


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

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 04:59 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.