On Mon, Jul 26, 2021 at 4:19 AM DGFA DAG's GRAPHIC & FOTO ART <
gerome....@gmail.com> wrote:

> Hi,
> when I want to change the texture path I struggle on one point.
> Let say the path is now
> project/create/Maya/sourceimages/room/texture.exr
> There could be a deeper sub folder structure like
> project/create/Maya/sourceimages/light/exr/light.exr etc.
>
> How can replace the path just to sourceimages and preserve all after that?
>

You may need to provide some more details about your goal, but this sounds
like it might just be a python string formatting problem.
Assuming you already know how to get and set the texture filepath, and have
the texture path value as a variable:

path = 'project/create/Maya/sourceimages/room/texture.exr'

you should be able to use one of the many possible approaches to extracting
the substring.

First you have to start with some known prefix you want to preserve.

prefix = 'project/create/Maya/sourceimages/'
new_prefix = 'path/to/new/sourceimages/'

You could use some of the built in string methods to replace the prefix:

path.replace(prefix, new_prefix, 1)#
'path/to/new/sourceimages/light/exr/light.exr'

new_prefix + path.partition(prefix)[-1]#
'path/to/new/sourceimages/light/exr/light.exr'

If you want more control over the substitution, such as being able to only
replace it if it actually starts with your prefix,
you could use a regular expression:

import re
re.sub(r'^' + prefix, new_prefix, path)#
'path/to/new/sourceimages/light/exr/light.exr'

re.sub(r'^' + prefix, new_prefix, 'dont_replace/'+path)#
'dont_replace/project/create/Maya/sourceimages/light/exr/light.exr'


Justin


> Justin made a awesome YouTube blog, but I have no clue how to solve
> procedurally this path problem.
>
> Thank you!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/a72d98b3-63cf-465d-abaa-4b99e1951f97n%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/a72d98b3-63cf-465d-abaa-4b99e1951f97n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0Y4Kk_Ho9O50EM%2B0WePGuOC0UdhY4dug4VbtQ5LjFy%2BA%40mail.gmail.com.

Reply via email to