1 # SPDX-FileCopyrightText: 2020-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
10 platform
= os
.sys
.platform
11 coat3D
= bpy
.context
.scene
.coat3D
13 # Global variable foundExchangeFolder (True / False) guides these steps
14 # 1. Read Exchange_folder.txt, if not success ->
15 # 2. Try to find exchange folder from system hard drive, if not success -->
16 # 3. Leave foundExchangeFolder = False
18 # 1. #################################################################
20 if(platform
== 'win32' or platform
== 'darwin'):
21 DC2Folder
= os
.path
.expanduser("~") + os
.sep
+ 'Documents' + os
.sep
+ '3DC2Blender'
23 DC2Folder
= os
.path
.expanduser("~") + os
.sep
+ '3DC2Blender'
25 exchangeFile
= DC2Folder
+ os
.sep
+ 'Exchange_folder.txt'
27 if(not os
.path
.isdir(DC2Folder
)):
30 if(not os
.path
.isfile(exchangeFile
)):
31 file = open(exchangeFile
, 'w')
34 savedExchangePath
= ''
35 folderPath
= open(exchangeFile
)
37 for line
in folderPath
:
38 savedExchangePath
= line
43 coat3D
.exchangeFolder
= savedExchangePath
44 return True, coat3D
.exchangeFolder
47 # 2. #################################################################
49 if(platform
== 'win32' or platform
== 'darwin'):
50 exchangeFolder
= os
.path
.expanduser("~") + os
.sep
+ 'Documents' + os
.sep
+ 'Applinks' + os
.sep
+ '3D-Coat' + os
.sep
+'Exchange'
52 exchangeFolder
= os
.path
.expanduser("~") + os
.sep
+ '3D-CoatV4' + os
.sep
+ 'Exchange'
53 if not(os
.path
.isdir(exchangeFolder
)):
54 exchangeFolder
= os
.path
.expanduser("~") + os
.sep
+ '3D-CoatV3' + os
.sep
+ 'Exchange'
55 if(os
.path
.isdir(exchangeFolder
)):
56 coat3D
.exchangeFolder
= exchangeFolder
58 Blender_folder
= ("%s%sBlender"%(exchangeFolder
,os
.sep
))
60 if(not(os
.path
.isdir(Blender_folder
))):
61 os
.makedirs(Blender_folder
, mode
= 0o666)
62 Blender_folder1
= os
.path
.join(Blender_folder
,"run.txt")
63 file = open(Blender_folder1
, "w")
66 Blender_folder2
= os
.path
.join(Blender_folder
, "extension.txt")
67 file = open(Blender_folder2
, "w")
71 Blender_folder3
= os
.path
.join(Blender_folder
, "preset.txt")
72 file = open(Blender_folder3
, "w")
73 file.write("Blender Cycles")
76 file = open(exchangeFile
, "w")
77 file.write("%s"%(os
.path
.abspath(coat3D
.exchangeFolder
)))
80 return True, coat3D
.exchangeFolder
85 def updateExchangeFile(newPath
):
87 platform
= os
.sys
.platform
89 if(platform
== 'win32' or platform
== 'darwin'):
90 exchangeFile
= os
.path
.expanduser("~") + os
.sep
+ 'Documents' + os
.sep
+ '3DC2Blender' + os
.sep
+ 'Exchange_folder.txt'
92 exchangeFile
= os
.path
.expanduser("~") + os
.sep
+ '3DC2Blender' + os
.sep
+ 'Exchange_folder.txt'
93 if(os
.path
.isfile(exchangeFile
)):
96 if(os
.path
.isfile(exchangeFile
)):
97 file = open(exchangeFile
, "w")
98 file.write("%s"%(newPath))
101 def loadExchangeFolder():
103 platform
= os
.sys
.platform
104 coat3D
= bpy
.context
.scene
.coat3D
106 if(platform
== 'win32' or platform
== 'darwin'):
107 DC2Folder
= os
.path
.expanduser("~") + os
.sep
+ 'Documents' + os
.sep
+ '3DC2Blender'
109 DC2Folder
= os
.path
.expanduser("~") + os
.sep
+ '3DC2Blender'
111 exchangeFile
= DC2Folder
+ os
.sep
+ 'Exchange_folder.txt'
113 if(not os
.path
.isdir(DC2Folder
)):
116 if(not os
.path
.isfile(exchangeFile
)):
117 file = open(exchangeFile
, 'w')
120 savedExchangePath
= ''
121 folderPath
= open(exchangeFile
)
123 for line
in folderPath
:
124 savedExchangePath
= line
127 coat3D
.exchangeFolder
= savedExchangePath
130 def set_working_folders():
132 platform
= os
.sys
.platform
133 coat3D
= bpy
.context
.scene
.coat3D
135 if(platform
== 'win32' or platform
== 'darwin'):
136 if (coat3D
.defaultfolder
!= '' and os
.path
.isdir(coat3D
.defaultfolder
)):
137 return coat3D
.defaultfolder
139 folder_objects
= os
.path
.expanduser("~") + os
.sep
+ 'Documents' + os
.sep
+ '3DC2Blender' + os
.sep
+ 'ApplinkObjects'
140 if(not(os
.path
.isdir(folder_objects
))):
141 os
.makedirs(folder_objects
, mode
= 0o666)
143 if (coat3D
.defaultfolder
!= '' and os
.path
.isdir(coat3D
.defaultfolder
)):
144 return coat3D
.defaultfolder
146 folder_objects
= os
.path
.expanduser("~") + os
.sep
+ '3DC2Blender' + os
.sep
+ 'ApplinkObjects'
147 if(not(os
.path
.isdir(folder_objects
))):
148 os
.makedirs(folder_objects
, mode
= 0o666)
150 return folder_objects