General Mechanical

General Mechanical

How to access the Working Directory of Ansys Mechanical via Python?

    • senior2020design
      Subscriber

      Dear Ansys Student Community Helpers,


      I am using the Ansys 2019 R1 scripting API's for capturing my model in Mechanical and saving it in the user_files of my project. But is there a way to access this folder with python scripting itself?


      I have tried using the normal os.mkdir python coding but that only accesses the directory in which the Ansys software was installed in my operating system. Which is the C drive. 


      I have utilized the dataModel.WorkingDir to access my current directory in Ansys, but it seems that the Ansys API commands does not play well with the normal python mkdir coding.


      Please let me know what I possibilities I have with my idea.


      And please point me in the direction that may help me as well. 


      Thank you, DL

    • Aniket
      Ansys Employee

      Wouldn't the following be useful:


       


      Model.Analyses[0].AnalysisSettings.SolverFilesDirectory 


       


      -Aniket


      Guidelines on the Student Community


      How to access ANSYS help links

    • senior2020design
      Subscriber

      I am sorry I believe my title is misleading. Thank you for your help but it seems this also leads me into the Mechanical directory. 


      by using both:


      Model.Analyses[0].AnalysisSettings.SolverFilesDirectory 


      AND


      ExportScreenToImage.WorkingDir


      I am trying to access the User_files directory in the project name. because I want to automatically create a folder in that directory. 


      The before methods get me into the Project_filesdp0globalMECH


      Thank you


       

    • Aniket
      Ansys Employee

      please check:


      https://ansyshelp.ansys.com/account/Secured?returnurl=/Views/Secured/corp/v195/act_dev/InstalledFunctionLibraries.html


      You should be able to use GetUserFilesDirectory() which works at the workbench level. You should be able to call that function from Mechanical by importing wbjn as explained in the above help link.


       


      -Aniket


      How to access Ansys Online Help Document


      How to show full resolution image


      Guidelines on the Student Community


      How to use Google to search within Ansys Student Community


       

    • senior2020design
      Subscriber

      I am currently trying different solutions with your insight. 


      Once I am able to access the working directory I am going to save images from Mechanical. I am using the Graphics.ModelViewManager.CaptureModelView(int index, "PNG") to capture and save my geometry into the working directory. The problem I am running into is that the API automatically saves it as the name created to the view inside Mechanical's Model View Window. 


      Is there any way to append to the name saved from using the CaptureModelView. 


      For example, the view name is "Open View" and when I use the Graphics.ModelViewManager.CaptureModelView(int index, "PNG") I get the file named


      Open View.PNG in my directory. It there a way to append onto this filename while still using the CaptureModelView()? 

    • Aniket
      Ansys Employee

      senior2020design, Is there any specific reason to use "Graphics.ModelViewManager.CaptureModelView" ? Can you use "Graphics.ExportImage" instead?



      -Aniket


      How to access Ansys Online Help Document


      How to show full resolution image


      Guidelines on the Student Community


      How to use Google to search within Ansys Student Community


       


       

    • senior2020design
      Subscriber

      The issue I am running into with using API Methods that takes in a string filepath such as "Graphics.ExportImage(filePath)" is that the user can save their created Project anywhere on the hard drive. So I do not want to specify a specific filepath to save images because that would confuse users that have saved their Project into a different directory in their hard drive. The "Graphics.ModelViewManager.CaptureModelView" some how finds where the Project was saved and saves the image files into the user_files directory in the Project folder.


      I have Version 2019 R1 and I could not seem to identify the existence of the GetUserFilesDirectory() in the reference guide. 


      Thank you for all the help, please let me know what other options are possible. 

    • Aniket
      Ansys Employee

      but you can always get the filepath string using GetUserFilesDirectory() from the workbench page right? Did you check the link that I gave?


      GetUserFilesDirectory() is a workbench level command so you will be able to execute it from ACT console on Workbench page (not from ACT console in Mechanical).


      The link I gave shows how to run workbench level commands from Mechanical. And "filepath" is literally a string, there should not be any issue to manipulate it and force it to the output of command GetUserFilesDirectory() using basic python commands. 


      -Aniket


      How to access Ansys Online Help Document


      How to show full resolution image


      Guidelines on the Student Community


      How to use Google to search within Ansys Student Community


       

Viewing 7 reply threads
  • You must be logged in to reply to this topic.