Hi, thank you for support. I solved it in this way:
def relinkBtnCmd(self, *args): #get the path specified in the text field using a query basePath = cmds.textField(self.txtFieldFolderLocation, query=True, text=True); index = cmds.textField(self.txtFieldOldFolderLocation, query=True, text=True); # list all file nodes fileNodes = cmds.ls(type="file") # repeat for each node for node in fileNodes: #get the current path currPath = cmds.getAttr(node + '.fileTextureName') #split the path name at the last folder pathSplit = currPath.split(os.sep) #get positon of last '/' '\' filename = pathSplit[-1] # split filename #rel = os.path.relpath(currPath, basePath) rel = os.path.relpath(currPath, index) #combine basePath and filename to create a new path #newPath = "%s/%s" %(basePath, filename) newPath = os.path.join(basePath, rel) # set the path in the texture node cmds.setAttr(node + '.fileTextureName', newPath, type='string') justin...@gmail.com schrieb am Montag, 26. Juli 2021 um 21:55:58 UTC+2: > On Mon, Jul 26, 2021 at 4:19 AM DGFA DAG's GRAPHIC & FOTO ART < > gerom...@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_m...@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/30db4627-6106-42f0-bd76-5a8edf1e0af1n%40googlegroups.com.