This lesson is part of the Scripting in Ignition course. You can browse the rest of the lessons below.

LESSON LIST

Autoplay Off
Take topic challenge

Description

The script console in the Designer and the print command are described here.

Video recorded using: Ignition 7.8

Transcript

(open in window)

[00:00] Before we dive into the Python language, we should get familiar with a location where we can read scripts as well as a print command that will let us see what we're doing. Now scripts can run in a lot of places in the designer. And you see I got my designer from front of me. But let's take a look at the script console. So come up under tools and go to script console. Now, the script console is only available in the designer, so you can't run this from the client or anything like that. And it's a tool that will allow you to, run scripts on demand. So on the left hand side, you have this multi line buffer, this is where you'll type your code. And on the right hand side is the interactive interpreter. This is where the output will be. So we can start with a very simple example. We'll just start with the print statement. So I'll take print, and the print statement will just print something to our console, just some sort of output depending on, whatever I put after this print statement here. Now since this is an introductory example, let's go ahead and use hello world. Note the use of the double quotes around hello world here. This is because strings in Python need to be wrapped in quotation marks. Now you can use single or double quotes here, doesn't matter what you use as long as you're consistent. So whatever you use at the end of the string must match what you're using at the beginning of the string. Now, if I click Execute, we can see on the right hand side that a printed out hello world without the quotes. Now it's very important to note that, the right hand side here isn't just a console, it's actually a live Python terminal. So for example, I can come up here I can clear out a print statement I can just say x equals 10. And I can execute that. Now of course, we don't have a print statement, so nothing will come out. But I can come over here and clear out that x equals 10 and just print out x. When I execute. We see that it printed out the value that I assigned to x. Now if I wanted to clear out this console, say I've been executing couple times here, and I'd like to simplify things a bit. I can click on this clear button or this trash can icon, and I can keep executing. And I'll still remember what X was designed. I want to start from scratch completely, I can click right here on the reset button. And now if I try to execute, it'll give me an error because it doesn't know what x is, x is no longer defined here. Now the script console is a great tool to use when learning how to write a script as well as testing them out and Ignition. Though important remember scope here, when I run the print command here in script console, they'll print over here to the output. However, if I had a window open and had a button on it, or some component that was running a print statement via script, then the output would actually come over to the designer or client console stuff, so if I go to tools and console, it print down here. If I had a tag change script, on one of my tags here that was printing out, some sort of statement or string. I wouldn't see the output in the output console in the designer or the client, I'd see it in the gateways output console, which in this case would be the wrapper log. So this concept of scope is very important to keep in mind when writing your scripts in a Ignition. The location of the script determines the scope as well as where the output will be.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.