├── LICENSE ├── README.md ├── environment.yml └── opennesspy.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Jonas Kjærnli 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Basic example on how to use openness with Python using Pythonnet 2 | 3 | 4 | ## More examples on how to use Openness with Python: 5 | https://github.com/Maroder1/Openness_examples_python 6 | 7 | 8 | 9 | 10 | ## Installation of TIA Openness 11 | 12 | 1. Install TIA v15.1 professional, make sure openness is checked [default] 13 | [Link to TIA v15.1 trail](https://support.industry.siemens.com/cs/ww/en/view/109761045) 14 | 2. Right clik "My computer" -> Manage -> System tools -> Local users and groups - > Groups-> Double click “Siemens TIA Openness” and add your username 15 | 3. Edit the file path in the example file to match your installation of Siemens.Engineering.dll 16 | 4. [Download and install Python](www.python.org) 17 | 18 | 19 | ## Option 1, running directly (not recommended) 20 | 21 | 1. in the windows search bar type "command prompt" to open Command Promt (CMD) 22 | 2. Install pythonnet by typing: *pip install pythonnet* 23 | 3. Browse to the location of the example file and type: *Python opennesspy.py* 24 | 25 | 26 | ## Option 2, running in a Virtual environment(in this example using Miniconda (Anaconda)) 27 | 28 | 1. [Download Miniconda](https://docs.conda.io/en/latest/miniconda.html) 29 | 2. Open Command Prompt (CMD) 30 | 3. Create a new environment by typing: *conda create --name opennesspy python=3.7* 31 | 4. Actiavte the environment: *conda activate opennesspy* 32 | 5. Install pythonnet by typing: *pip install pythonnet* Note: installing using *conda install* didnt work. 33 | 6. Browse to the location of the example file and type: *Python opennesspy.py* 34 | 7. To leave the environment type *conda deactiave* 35 | 36 | Optional: instead of manually installing use the provided environment.yml file 37 | 38 | 39 | ## Recommandation: develop using Jupyter Notebook 40 | 41 | 1. Start Command Promt (CMD) as **administrator** (right click). Do not enter any environment yet. 42 | 2. Install Jupyter (and nb_conda as well as ipykernel to get your environments listed: *conda install jupyter nb_conda ipykernel* 43 | 3. Activate the environment you want to add to jupyter kernel: *conda activate myenv* 44 | 4. Install ipykernel in the environment (do this for all envvironemnts you would like to add): *conda install ipykernel* 45 | 5. To start Jupyter, cd to root (cd .. until you are at C:) then type (does not need to be inside and env): *Jupyter noteboook* 46 | 6. You might need to confrim that it shall open in a web browser (I use chrome) 47 | 7. Once open in a browser navigate to the folder of your choice, then make a new python 3 file. 48 | 8. Once inside click Kernel -> Change kernel and select the conda env you would like 49 | 9. To run a cell: either use the run button, or shift + enter. 50 | 51 | 52 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: opennesspy 2 | channels: 3 | - defaults 4 | dependencies: 5 | - ca-certificates=2019.5.15=0 6 | - certifi=2019.3.9=py37_0 7 | - openssl=1.1.1c=he774522_1 8 | - pip=19.1.1=py37_0 9 | - python=3.7.3=h8c8aaf0_1 10 | - setuptools=41.0.1=py37_0 11 | - sqlite=3.28.0=he774522_0 12 | - vc=14.1=h0510ff6_4 13 | - vs2015_runtime=14.15.26706=h3a45250_4 14 | - wheel=0.33.4=py37_0 15 | - wincertstore=0.2=py37_0 16 | - pip: 17 | - pythonnet==2.4.0 18 | prefix: C:\Users\Jonas\.conda\envs\opennesspy 19 | 20 | -------------------------------------------------------------------------------- /opennesspy.py: -------------------------------------------------------------------------------- 1 | 2 | import clr 3 | clr.AddReference('C:\\Program Files\\Siemens\\Automation\\Portal V15_1\PublicAPI\\V15.1\\Siemens.Engineering.dll') 4 | from System.IO import DirectoryInfo 5 | import Siemens.Engineering as tia 6 | 7 | 8 | project_path = DirectoryInfo ('C:\\Jonas\\TIA') 9 | project_name = 'PythonTest' 10 | 11 | #Starting TIA 12 | print ('Starting TIA with UI') 13 | mytia = tia.TiaPortal(tia.TiaPortalMode.WithUserInterface) 14 | 15 | #Creating new project 16 | print ('Creating project') 17 | myproject = mytia.Projects.Create(project_path, project_name) 18 | 19 | #Addding Stations 20 | print ('Creating station 1') 21 | station1_mlfb = 'OrderNumber:6ES7 515-2AM01-0AB0/V2.6' 22 | station1 = myproject.Devices.CreateWithItem(station1_mlfb, 'station1', 'station1') 23 | 24 | print ('Creating station 2') 25 | station2_mlfb = 'OrderNumber:6ES7 518-4AP00-0AB0/V2.6' 26 | station2 = myproject.Devices.CreateWithItem(station2_mlfb, 'station2', 'station2') 27 | 28 | print ("Press any key to quit") 29 | input() 30 | quit() 31 | --------------------------------------------------------------------------------