Git Product home page Git Product logo

sikvelsigma / ansys-wb-batch-script Goto Github PK

View Code? Open in Web Editor NEW
37.0 2.0 8.0 88 KB

Python scripts to use in ANSYS Workbench Batch mode. No Python package installation needed. Supports Parametric input/output. Uses only in-build ANSYS tools.

License: MIT License

Python 99.93% Batchfile 0.07%
ansys batch workbench ironpython automation cae no-installation python-script fea-modelling windows

ansys-wb-batch-script's Introduction

ANSYS Workbench - Batch Mode - Python Scripts

Platform - Tested on Windows 7, 10

ANSYS Version - Tested on 19.5 (2019R3); will most likely work on other versions that are not too old

This is a collection of python scripts I made to make my life easier when dealing with ANSYS Workbench Batch mode. It requres no additional python packages whatsoever. Right now there are 4 modules:

  1. WBInterface.py
  2. Logger.py
  3. ExcelFileReader.py
  4. CSVTable.py

Ansys Workbench comes with IronPython 2.7 so to run it from batch mode we only need to write a python script, which will control the flow of the project (run_script.py as an example here) and a .bat file (run.bat as an example here).

  • Module WBInterface.py is the main module which contains a class with all the useful workbench commands. I tried to document it as much as I could. This module is absolutely essential to have.

  • Module Logger.py contains a class which will create a log file in the project directory and write the flow of the project to it. This module is absolutely essential to have.

  • Module ExcelFileReader.py is an adapter class to the COM Excel API. Can be used to read tables from excel files. This module can also be used as a stand-alone with IronPython to read data from Excel. You have to have Excel installed on your machine. Not essential

  • Module CSVTable.py lets us easily import csv file to a list/dict. Not essential.

How to use

First of all, this was all made with running it on a remote machine in mind, when you don't have an ability to install additional software or open apps, but have access to a file system. Second of all, in my work I use a specialised hierarchical software which does not support making changes to already existing files, so there was a need to be able to import modules by their modified names (like WBInterface_100.py for example). That's why there's this weird system with exac() commands implemented to input everything correctly. So, the simplest way to use all of this would be:

  1. Drop modules WBInterface.py and Logger.py into the same folder where your ANSYS WB archive/project currently resides

  2. Drop run_script.py and run.bat there also

  3. Configure .bat file for your machine and run it; format of .bat file:

     "<ansysdir>\v<ver>\Framework\bin\Win64\RunWB2.exe" -B -R "run_script.py"
    

That's it! Easy and simple as I intended. The script will automatically try to find .wbpz file and open it or, failing that, it will try to find a .wbpj file. After the project was opened, the script will try to issue a global Update command for all DPs (Design Points) present in the project. Note: You don't need to delete anything from run_script.py since methods won't raise errors if they don't find anything, but it will be logged to a log file.

Additional functionality

You can also input/output WB parameters with multiple DPs which will managed automatically. All you need to do is to create 2 csv files:

  • .control or _control.csv
  • .input or _input.csv

The first one contain a list of parameters to input and a list of parameters to output. The second one contains values of input parameters with each row being a new DP. Both files support comments (with #). Example of a .control file:

  #Input parameters (type 'no' if no inputs)
  P1,P2,P3
  #Output parameters (type 'no' if no outputs)
  P4,P5

Example of an .input file:

  # p1,p2,p3
  501,50,25
  499,49,24
  500,52,26

This will generate 3 DPs in our project with 3 input and 2 output parameters.

By default in the project directory a log.txt file will be created. Output is written to an output.txt file csv-style and Workbench parametric report is saved to a full_report.txt file. Of course this is all customizable.

You can also use CSVTable.py module or just regular open() to read parameters into a list or dict and use input_by_name() or input_by_DPs() methods of WBInterface.py to set them directly.

Note that I'm not a programmer and I apologize in advance for any inconsistencies/bad practises in my code.

ansys-wb-batch-script's People

Contributors

sikvelsigma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ansys-wb-batch-script's Issues

Nice work!

Hi, I really like this repo! This is really close to my use case and you have greatly inspired me. I have some questions if you don't mind.

I am very interested in how / where you found the documentation on the workbench API from WBInterface. Is it available somewhere? My company has a license, but so far I did not manage to get any way to contact the ANSYS support from them.

Is this considered as breaking ANSYS terms of use?

Ansys-WB-Batch-Script in Linux

Hi, @sikvelsigma, firstly good work because your python script is perfect.

I have a question regarding the system where this script can be used. Is it possible to launch this script in Linux? I understand this script is only for Windows. But it could be adapted to Linux changing the run.bat archive?

Thanks in advance.

Regards,
altranapina

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.