SOLVED Setting texture paths with plugin on startup

Hi
Im making a tiny plugin that will grab an environment variable from the os and set it as a texture path in the preferences Files -> Paths -> File Assets -> Paths
The plugin prints that the path has been set but the path is not listed in prefs.

import c4d
import os

def PluginMessage(id, data):
	if id == c4d.C4DPL_PROGRAM_STARTED:
		# path = os.environ['RC_TEXTURE_PATHS']
		path = "S:/_3D_Central/Maxon/tex"
		print 'The path to be set {}'.format(path)
		print 'Existing paths {}'.format(c4d.GetGlobalTexturePaths())	
		c4d.SetGlobalTexturePaths([[path, True]])
		print 'New paths {}'.format(c4d.GetGlobalTexturePaths())
		c4d.EventAdd()

When i run the code in a script in the editor, it works and the paths shows in the list in prefs

import c4d
import os

def main():
    #path = os.environ['RC_TEXTURE_PATHS']
    path = "S:/_3D_Central/Maxon/tex"
    print 'The path to be set {}'.format(path)
    print 'Existing paths {}'.format(c4d.GetGlobalTexturePaths())
    c4d.SetGlobalTexturePaths([[path, True]])
    print 'New paths {}'.format(c4d.GetGlobalTexturePaths())

if __name__=='__main__':
    main()
``` Any help appreciated

Regards
Bonsak

Hi @bonsak, I was not able to reproduce your issue, here on R20.026 SP1 both codes are working fine.
In which version of C4D are you?

Thats weird.
Im on R20.030 RB257898 with win 10.0.17134 and nvidia 391.35

The problem is that even thought the variable is defined...

c4d.GetGlobalTexturePaths()
[['S:\\_3D_Central\\Maxon\\tex\\GSG_EMC_Redshift', True]]

...it does not work. C4d will only find textures in that directory if the paths is actaully visible in the list in prefs.

Regards
Bonsak

I did some more testing and the variable is actually not getting set from the plugin. It only works when i run the script version manually after startup.

The strange thing is that when the plugin is executed it prints the result of c4d.GetGlobalTexturePaths(), and that does return the path, but when i run c4d.GetGlobalTexturePaths() in the python console after startup and the plugin is finished running, it returns an empty list "[]". And the list is empty in prefs.
Why is that?

Regards
Bonsak

Hi @bonsak I'm afraid you get another script which overrides it.
Here on a fresh R20.030 RB257898 it's working nicely.

Moreover please consider adding your path only if is not already present and please do not erase all paths (user may already have some setup before).
You can find an example which handles this properly in GitHub: globaltexturepaths.py.

Cheers,
Maxime.

Good for you 🙂
If i implement the script you linked to in my plugin like this:

import c4d
from c4d import storage

import os


def PluginMessage(id, data):
	if id == c4d.C4DPL_PROGRAM_STARTED:

		desktopPath = storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP)
		homePath = storage.GeGetC4DPath(c4d.C4D_PATH_HOME)

		# Gets global texture paths
		paths = c4d.GetGlobalTexturePaths()

		# Checks if the paths already exist in the global paths
		desktopPathFound = False
		homePathFound = False

		for path, enabled in paths:
			if os.path.normpath(path) == os.path.normpath(desktopPath):
				desktopPathFound = True

			if os.path.normpath(path) == os.path.normpath(homePathFound):
				homePathFound = True

		# If paths are not found then add them to the global paths
		if not desktopPathFound:
			paths.append([desktopPath, True])

		if not homePathFound:
			paths.append([homePath, True])

		paths.append(['S:/_3D_Central/Maxon/tex', True])

		# Sets global texture paths
		c4d.SetGlobalTexturePaths(paths)

		# Prints global texture paths
		print(c4d.GetGlobalTexturePaths())

it does print that all three paths are set but none of them are visible in the prefs.
I need to do this from a plugin as it will be used to set renderslaves texture env on the fly from job to job.

Regards
Bonsak

I just tried the plugin on some other machines in the studio and it doesnt show newly set paths in prefs there either.

Regards
Bonsak

Do you have any other plugins installed? Please remove them to test.
As I said it's most likely you get another plugin which overrides the path.

Omg! I had an old version of the plugin defined in the Plugins list in prefs that set the paths to [].
Blush Deluxe!
Sorry for wasting your time. Works perfectly fine.

Regards
Bonsak