Blog

TIA Portal Autosave with Openness

TIA Portal Autosave with Openness

Sometimes my computer crashes. Sometimes I forget to save for extended periods of time while I’m developing code in TIA Portal. When these events coincide, I don’t have a good time. However, with a little bit of C# .NET knowledge this problem can be solved. Assuming you have installed TIA Portal Openness, the below code can be run as a console application to automatically save all active instances of TIA Portal V15.1 every 5 minutes.


using System;
using System.Collections.Generic;
using System.Linq;
using Siemens.Engineering;

namespace PortalAutoSave
{
    class TIAAutoSave
    {
        static void Main(string[] args)
        {
            //Endlessly run this instruction
            while(true)
            {
                //Call function to save portal projects
                SavePortal();
                //Wait 5 minutes
                System.Threading.Thread.Sleep(300000);
            }
        }

        public static void SavePortal()
        {
            //Need a list that can hold all of the TIA portal processes
            //All portal processes are retrieved using a static method of TiaPortal
            IList<tiaportalprocess> processes = TiaPortal.GetProcesses();
            TiaPortal MyTiaPortal;
            //Loop through all TIA portal processes and attempt to save
            foreach (var process in processes)
            {
                try
                {
                    MyTiaPortal = process.Attach();
                    MyTiaPortal.Projects.FirstOrDefault().Save();
                }
                catch (Exception e)
                {
                    //Print any error messages to the console
                    Console.WriteLine(e.Message);
                }
            }
        }
    }
}

In addition to the code above, you’ll need to include a reference to the Siemens.Engineering.dll used to call openness instructions. A small side effect is to keep in mind is that every time you save in TIA Portal you lose the ability to undo actions.

If you’d like to learn more about DMC’s Siemens expertise and how we can help you improve your project efficiency, development, and effectiveness, check out our Manufacturing Automation & Intelligence Services.

Comments

There are currently no comments, be the first to post one.

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above:

Related Blog Posts