[Sidefx-houdini-list] execute external python script

Francois-Xavier Boussard b.fx at free.fr
Thu Dec 13 03:07:10 EST 2007


Hi Dries,

I will give a go to the split() function as soon as i can (bit busy right now).

Thanks :)
Francois

Selon Dries Desmet <dries at urga.be>:

> Hi Francois,
>
> slicing a string is even esier in python:
> pfile[-3:] is equivalent to what you're doing, and then you don't need
> to calculate the lenght of the string.
>
> Better still is to use the split() method for string to avoid having
> problems with extension that are 4 character or basenames that have a dot:
> ext = pfile.split(".")[-1]
> which essentially means: split the string into a list of strings using
> "." as a separator and take the last element of that list.
>
> D.
>
>
>
> Francois-Xavier Boussard wrote:
> > I had tryed pattern='*.py' but didn't filter anything for me
> (houdini9.0.794,
> > debian Amd64).
> >
> > Also i've some issues with the path behavior when picking files twice from
> the
> > same directory. You have to change level and then come back in the
> directory in
> > order to refresh the path. Sometimes end up with
> > "/home/fx/scripts/././././././blabla.py" but that didn't generate an error.
> >
> > Here the small code i end up with. It work fine from the shelf.
> >
> > pfile = hou.expandString(hou.ui.selectFile(pattern='*.py'))
> > l = len(pfile)
> > ext = pfile[l-3:l]
> > if pfile != "":
> >     if ext == ".py":
> >         execfile(pfile)
> >     else:
> >         message = "Wrong extension: expect .py"
> >         hou.ui.displayMessage(str(message))
> >
> >
> > thanks
> > francois
> >
> > Selon Graham Thompson <gthompson at sidefx.com>:
> >
> >
> >> You can just use the pattern argument to set the filter type.
> >>
> >> hou.ui.selectFile(pattern='*.py')
> >>
> >> Francois-Xavier Boussard wrote:
> >>
> >>> Thanks, many !
> >>>
> >>> Maybe, on day, a filter for the .py files:
> >>> hou.ui.selectFile(file_type=hou.fileType.Py)
> >>>
> >>> thanks
> >>> François
> >>>
> >>>
> >>> Selon Graham Thompson <gthompson at sidefx.com>:
> >>>
> >>>
> >>>
> >>>> You can use hou.expandString() on your file path returned by
> >>>> selectFile.  That will allow you to run execfile on it.
> >>>>
> >>>> path = hou.expandString(hou.ui.selectFile())
> >>>>
> >>>>
> >>>> As for setting an Hscript variable as a result of a python command, you
> >>>> could do something like
> >>>>
> >>>> set foo = `pythonexprs('hou.ui.selectFile()')`
> >>>>
> >>>>
> >>>> Houdini 9.0 does not currently have a python equivalent to things such
> >>>> as $script_value so what you are doing is probably
> >>>> the best you can for now.
> >>>>
> >>>>
> >>>> Francois-Xavier Boussard wrote:
> >>>>
> >>>>
> >>>>> Hello,
> >>>>>
> >>>>> I'm looking after an easy way to run python script from arbitrary
> >>>>>
> >>>>>
> >>>> directories on
> >>>>
> >>>>
> >>>>> disk. I mean to pick it with a file selector UI.
> >>>>>
> >>>>> Sound simple, i end up with an hscript callback button from an hda...
> Is
> >>>>>
> >> it
> >>
> >>>>> possible to do that from a shelf ?
> >>>>>
> >>>>> Menu File-> Run Script: only allow hscript, why ?
> >>>>>
> >>>>> A shelf tool with a python script hou.ui.selectFile() return unexpanded
> >>>>>
> >>>>>
> >>>> variable
> >>>>
> >>>>
> >>>>> as $HOME (linux) that are wrong with execfile(). Is there a way to
> expand
> >>>>>
> >>>>>
> >>>> those
> >>>>
> >>>>
> >>>>> variable with the houdini python tools ?
> >>>>>
> >>>>> A shelf tool with an hscript. How do i pass the result of an
> >>>>>
> >>>>>
> >>>> hou.ui.selecFile()
> >>>>
> >>>>
> >>>>> to an hscript variable ?
> >>>>>   set foo = `run('python -c
> >>>>>
> >>>>>
> >>>> "hou.ui.selectFile(file_type=hou.fileType.Any)"')
> >>>>
> >>>>
> >>>>>   echo $foo
> >>>>> return blank
> >>>>>
> >>>>> An HDA with a file button and a callback script:
> >>>>> how to access the $script_value from a python script ?
> >>>>> It works with a hscript callback:
> >>>>>   python -c "execfile('${script_value}')"
> >>>>> It is not that nice, using an hda plus hscript...
> >>>>>
> >>>>> Did i miss an obvious way to do it ?
> >>>>>
> >>>>> thanks
> >>>>> francois
> >>>>>
> >>>>>
> >>>>>
> >>>>> _______________________________________________
> >>>>> Sidefx-houdini-list mailing list
> >>>>> Sidefx-houdini-list at sidefx.com
> >>>>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>>>>
> >>>>>
> >>>>>
> >>>> _______________________________________________
> >>>> Sidefx-houdini-list mailing list
> >>>> Sidefx-houdini-list at sidefx.com
> >>>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>>>
> >>>>
> >>>>
> >>> _______________________________________________
> >>> Sidefx-houdini-list mailing list
> >>> Sidefx-houdini-list at sidefx.com
> >>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>>
> >>>
> >> --
> >> Graham Thompson
> >> Character Tool Developer
> >>
> >> Side Effects Software
> >> gthompson at sidefx.com
> >> (416) 504-9876 x217
> >>
> >> _______________________________________________
> >> Sidefx-houdini-list mailing list
> >> Sidefx-houdini-list at sidefx.com
> >> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>
> >>
> >
> >
> > _______________________________________________
> > Sidefx-houdini-list mailing list
> > Sidefx-houdini-list at sidefx.com
> > https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >
>
>
> --
>
> Urga
> Engelstraat 167
> 9040 Gent
> www.urga.be <http://www.urga.be>
> tel: 09 357 58 32
>
> <http://www.urga.be>
>
> _______________________________________________
> Sidefx-houdini-list mailing list
> Sidefx-houdini-list at sidefx.com
> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
>





More information about the Sidefx-houdini-list mailing list