Executing a script within a script
-
On 30/07/2018 at 12:31, xxxxxxxx wrote:
Hi everyone,
I'm trying to figure out how I can make this bit of code work to open an existing script within a different script?
import c4d from c4d import gui import os def main('C:\Users\Benjamin\AppData\Roaming\MAXON\CINEMA 4D R18_62A5E681\library\scripts est1.py') : fl = open('C:\Users\Benjamin\AppData\Roaming\MAXON\CINEMA 4D R18_62A5E681\library\scripts est1.py', 'rb') code = compile(fl.read(), 'C:\Users\Benjamin\AppData\Roaming\MAXON\CINEMA 4D R18_62A5E681\library\scripts est1.py', 'exec') scope = {'__file__': 'C:\Users\Benjamin\AppData\Roaming\MAXON\CINEMA 4D R18_62A5E681\library\scripts est1.py', '__name__': '__main__'} exec code in scope if __name__=='__main__': main()
-
On 31/07/2018 at 02:40, xxxxxxxx wrote:
Hi,
To execute a script from a file one can use execfile().
Note the user library directory can be retrieved calling c4d.storage.GeGetC4DPath(c4d.C4D_PATH_LIBRARY_USER).
-
On 31/07/2018 at 19:55, xxxxxxxx wrote:
Thanks Yannick
That worked well. I ended up using this
execfile(c4d.storage.GeGetC4DPath(c4d.C4D_PATH_LIBRARY_USER)+os.sep+"scripts"+os.sep+"VolumetricSwitch.py")