Get User Files Dir. in SpaceClaim
Hi,
I would like to get the user files directory via python script in SpaceClaim. If I use doc_path = GetActiveWindow().Document.Path, I get a different path when I use in Workbench path = GetUserFilesDirectory()
But I want to get the path as for GetUserFilesDirectory() in SpaceClaim. To open SpaceClaim, create a surface or solid, close SpaceClaim, open SpaceClaim again is not an option for my automized python script.
Is there a similar function to get the path as for GetUserFilesDirectory() or a nice workaround?
Thx in advance.
Answers
-
Hi Schlupping! I am not sure but I think someone from @AKD-Scripting-Team should be able to help.
0 -
@SchluppIng Are you launching spaceclaim from workbench page? You know that SpaceClaim can be launched independently, and it does not have any connection with workbench project typically.
What is the goal here?
0 -
@Rajesh Meena yes, I'm launching SpaceClaim from WB.
I use an ACT to create several geometries and static structurals in order to carry out various analyses. When starting SpaceClaim via the Python code, I pass a Python script to create the geometry. This script contains a path to an *.xml file to read in values that are important for creating the geometry.
However, if I have several workbenches open, this *.xml file is overwritten because it is always saved in the same place. If I use the path to the user files directory, the problem should be solved.0 -
I usually pass the user directory to SC from whatever is calling it (e.g. Workbench). For example, in Workbench:
SCcmds = "userfolder = r'{}' ".format(GetUserFilesDirectory()) geometry1.RunScript(SCcmds) geometry1.RunScript(SCscript)
0 -
Thanks for the quick response, but how do I get access to the "userfolder" variable in the SCscript?
0 -
In the above example it will be a variable.
You can also append it to a script template:
TemplateSCscript = os.path.join(installDir, 'myscript.py') UserSCscript = os.path.join(userdirectory, 'local_myscript.py') SCcmds = "userfolder = r'{}'\n".format(GetUserFilesDirectory()) with open(TemplateSCscript,'r') as f: SCcmds += "".join(f.readlines()) with open(UserSCscript,'w') as f: f.write(SCcmds) geometry1.RunScript(UserSCscript)
This method is a bit more roundabout but has the advantage of being able to debug the SC script outside the context of WB.
0 -
Thanks, I thought about the same to append the script file by adding/changing a line in the script, but it's not my favorite soultion.
BTW: If you try to use the code from above, I get the following error in ACT Log:
Code:
SCcmds = "userfolder = r'{}'\n".format(GetUserFilesDirectory())
ExtAPI.Log.WriteMessage(SCcmds)
solidContainer.RunScript(SCcmds)
solidContainer.RunScript(scriptPath)Error:
File "C:\Users\user.name\AppData\Roaming\Ansys\v232\ACT\extensions\TowerCreator\main.py", line 237, in createTower
Exception: The given path's format is not supported.
Traceback (most recent call last):Therefore the it fails to send the SCcmds command/path.
SystemError: The given path's format is not supported0 -
another solution is to define your own environment variable on workbench page before running script and access it in spaceclaim script.
import os os.environ['my_user_path'] = GetUserFilesDirectory() SCcmds = "import os os.environ['my_user_path']" geometry1.RunScript(SCscript)
0