From: John Stone (johns_at_ks.uiuc.edu)
Date: Wed Jan 17 2007 - 15:08:24 CST

Hi,

On Wed, Jan 17, 2007 at 03:47:48PM -0500, Axel Kohlmeyer wrote:
> On Wed, 17 Jan 2007, John Stone wrote:
> JS> Hi,
> JS> the problem with your script when run on windows is likely caused
> JS> by spaces in filenames or directories messing up the "split".
> JS> If you're put Tcl packages into a directory (e.g. your "e:/vmdextensions/tcl"
> JS> example below), you can simply use:
> JS> lappend auto_path e:/vmdextensions/tcl
>
> IIRC, for that to work you also have to create a tclIndex
> file for that directory. to do this you have to start a

Indeed, that's why I specified "Tcl packages" and not just scripts, but
I see now that it would have been easy to read right past my choice of
words...

In case people aren't aware of the difference, Tcl packages have a
"package provide" statement and are typically more structured and
reusable pieces of code than plain scripts. The Tcl "source" command
will load either of them, but "package require" will only load packages
that have a pkgIndex.tcl which is generated for
an entire directory using other Tcl commands:
  http://www.tcl.tk/man/tcl8.4/TclCmd/package.htm
  http://www.tcl.tk/man/tcl8.4/TclCmd/pkgMkIndex.htm
  http://wiki.tcl.tk/3388

Cheers,
  John

> tcl console (the VMD command prompt should do, i have no
> windows machine here to test this...) and then execute:
> auto_mkindex e:/vmdextensions/tcl *.tcl
>
> please see the corresponding tcl/tk documentation
> (this is a feature that VMD inherits from tcl/tk).
>
> JS>
> JS> Then use "package require mypackage" and it will automatically be found if
> JS> it is in a subdirectory within your "e:/vmdextensions/tcl".
>
> sorry, but as far as i remember, this is only true for real
> packages. for individual scripts (or the 'proc's included
> in them to be more precise) you can just use the included
> procedures as they will be sourced on demand based
> on the tclIndex file.
>
> cheers,
> axel.
>
> JS>
> JS> I'm not sure what went amiss with the script you posted below, as that could
> JS> also work, so long as you're careful to avoid spaces in filenames etc.
> JS> The script as-written will break if you have any filenames containing spaces.
> JS> Here's a fixed version that should also work with spaces:
> JS>
> JS> foreach ext [glob E:/vmdextensions/tcl/*.tcl] {
> JS> puts "sourcing: $ext"
> JS> source $ext
> JS> }
> JS>
> JS> If you have any errors within the scripts that you're automatically
> JS> sourcing, having that extra "puts" call in there will help you figure
> JS> out if the error is in your vmd.rc file, or rather a problem in one
> JS> of the scripts that you're sourcing. Once you eliminate the problem(s)
> JS> you can simply comment out the puts call.
> JS>
> JS> John Stone
> JS> vmd_at_ks.uiuc.edu
> JS>
> JS> On Wed, Jan 17, 2007 at 09:31:40AM +0800, wurl wrote:
> JS> > hello vmd-l,
> JS> >
> JS> > //i have added the following scripts in the vmd.rc file to load additional scripts :
> JS> >
> JS> > #Load Tcl-extensions
> JS> > foreach ext [split [glob E:/vmdextensions/tcl/*.tcl]]
> JS> > {
> JS> > source $ext
> JS> > }
> JS> > unset ext
> JS> >
> JS> > //after start VMD, it told me errors like:
> JS> >
> JS> > wrong # args: should be "foreach varList list ?varList list ...? command"
> JS> > invalid command name "
> JS> > source $ext
> JS> > "
> JS> > can't unset "ext": no such variable
> JS> >
> JS> > //in linux, it does not make errors, are there any difference between the linux and windows tcl scripts?
> JS> > //my VMD version is 1.8.5, and are there any other way to load additional tcl scripts? what are the default folder //VMD will search for tcl scripts in windows version 1.8.5 ?
> JS> >
> JS> >         
> JS> > Regards!
> JS> >
> JS> >         wurl
> JS> >         wurl04_at_iccas.ac.cn
> JS> >           2007-01-17
> JS>
> JS>
>
> --
> =======================================================================
> Axel Kohlmeyer akohlmey_at_cmm.chem.upenn.edu http://www.cmm.upenn.edu
> Center for Molecular Modeling -- University of Pennsylvania
> Department of Chemistry, 231 S.34th Street, Philadelphia, PA 19104-6323
> tel: 1-215-898-1582, fax: 1-215-573-6233, office-tel: 1-215-898-5425
> =======================================================================
> If you make something idiot-proof, the universe creates a better idiot.

-- 
NIH Resource for Macromolecular Modeling and Bioinformatics
Beckman Institute for Advanced Science and Technology
University of Illinois, 405 N. Mathews Ave, Urbana, IL 61801
Email: johns_at_ks.uiuc.edu                 Phone: 217-244-3349
  WWW: http://www.ks.uiuc.edu/~johns/      Fax: 217-244-6078