Write a script? - Page 1
Forum section: electronics / general

author: vlad777
author_rank: Frequent Contributor
timestamp: May 07, 2016, 06:01:27 pm
content: Write a script?What does it mean?Dave asks this question here:Apr 15, 2016 Live Show 0:37:00I know that you can write shell script for Linux or write a bat file for windows,but this is useful mostly with commands that come with OS and most other programs don't havecommand line interface commands.I also know you can control blender trough python.But other than that , when people say "why don't you write a script" i don't know what they mean.Can someone give me examples?Many thanks.

author: stmdude
author_rank: Frequent Contributor
timestamp: May 07, 2016, 06:18:36 pm
content: It's a very ambiguous expression, and this is coming from a software guy.The analogy I can make is telling an EE guy to "Make a circuit". I.e, pick the tools you know and cobble together a solution to the problem.Scripting is sort of simplified programming (in some cases, not so simplified) meant to solve small problems efficiently, by providing very flexible tools to do it with (scripting languages are typically very powerful for string manipulation, whilst compiled languages are not).Seems good? Well, the down-side is that you usually end up with a very specialized script to solve one particular problem. And, speed (if that matters to you, that a completely different question).These days, it seems (and I might very well be out-of-date here) are mostly done in Python and JavaScript. Old farts like me still use Perl.Whilst you can script to some extent in bat-files, I don't think anyone does that on any serious level. Shell-scripting in Linux is still quite common, usually to automate a few commands together (but they can be made quite complex and powerful).People who say "write a script" to non-software people are the equivalent to EE people telling rookies in electronics to "just use an op-amp".Op-amps are very flexible devices, and takes a little while to learn (assuming you already know the basics of circuits), and can be used in a million different ways.I'm sure everyone and their dog is going to disagree with me, and downplay the complexity. Thing is, to write scripts (or any kind of software), you need basic knowledge like program-blocks, basic logic, loops, types, conditionals, etc, which seem like no-brainers to SW guys (because they've got that way of thinking ingrained in them), but are actually things that regular people _need_ to learn before being able to "write a script".

author: ataradov
author_rank: Super Contributor
timestamp: May 07, 2016, 06:20:31 pm
content: The question is very broad. You can do anything you like with Python, not just control Blender.

author: ataradov
author_rank: Super Contributor
timestamp: May 07, 2016, 06:23:04 pm
content: Quote from: stmdude on May 07, 2016, 06:18:36 pmWhen you are coming from a practical perspective, it gets easier because of google and stackoverflow. If code beauty and performance is not a factor, almost anyone can assemble together a simple Python script from bits and pieces.General understanding of how programming works will be desirable, but I would not call it "learning" and it does not take a lot of time even for complete newbies.

author: vlad777
author_rank: Frequent Contributor
timestamp: May 07, 2016, 06:24:00 pm
content: What confuses me is: how do you expect a script to control a "random" program or app , that maybe wasn't intended to be scripted.But reading the comments inside the video someone said "AutoIt " , and looking at wikipedia it seems that this can send keystrokes to an app.

author: ataradov
author_rank: Super Contributor
timestamp: May 07, 2016, 06:27:13 pm
content: Quote from: vlad777 on May 07, 2016, 06:24:00 pmIn general you can't.Things like AutoIt are useful at times, but generally a big pain. There are plenty of others and they are typically used for automated UI testing, so some of them can make mouse clicks, analyze text under the cursor and do all the stuff humans can do.But if that advice was specifically about controlling an app that is not designed for that, then more details will be needed. What app are we talking about?

author: vlad777
author_rank: Frequent Contributor
timestamp: May 07, 2016, 06:29:42 pm
content: I'm just thinking in general , don't have a problem to solve.I'm gonna have to look into how python does it and with what apps.

author: ataradov
author_rank: Super Contributor
timestamp: May 07, 2016, 06:31:47 pm
content: Quote from: vlad777 on May 07, 2016, 06:29:42 pmPython can't do anything to apps that did not expose proper interfaces.Python is at the core of Blender, you don't even need to have Python installed, it comes as an integral part in case of Blender.Most of the time, programs that can be useful when automated are properly designed for automation.

author: vlad777
author_rank: Frequent Contributor
timestamp: May 07, 2016, 06:49:15 pm
content: Quote from: ataradov on May 07, 2016, 06:31:47 pmI think this is the key concept, thanks.Are these interfaces tied to a particular language?What do they call those , I am thinking something like API?

author: ataradov
author_rank: Super Contributor
timestamp: May 07, 2016, 06:55:02 pm
content: Quote from: vlad777 on May 07, 2016, 06:49:15 pmNot necessarily. For long-running application that may need automation one of the most common ways is to use sockets. The program simply opens a local port and listens for connections. Any language with networking capabilities will be able to control that program.Quote from: vlad777 on May 07, 2016, 06:49:15 pmAutomation API would be an acceptable name.

author: vlad777
author_rank: Frequent Contributor
timestamp: May 07, 2016, 07:01:12 pm
content: So sockets and maybe other IPC Inter-process communication I guess then.

author: vlad777
author_rank: Frequent Contributor
timestamp: May 07, 2016, 07:09:20 pm
content: So when you run a script like that, then you call it a "job" ?

author: ataradov
author_rank: Super Contributor
timestamp: May 07, 2016, 07:11:21 pm
content: Quote from: vlad777 on May 07, 2016, 07:09:20 pmCall it whatever you like. I don't think there is standard terminology for any of this.Why not just call it "running a script"?

author: vlad777
author_rank: Frequent Contributor
timestamp: May 07, 2016, 07:12:47 pm
content: Standard terminology is very useful for googling , just that.

author: ataradov
author_rank: Super Contributor
timestamp: May 07, 2016, 07:14:14 pm
content: Well, when you actually want to do something with a specific app, you just google "<app_name> scripting" or "<app_name> automation" and you'll find all you need to know.

author: ajb
author_rank: Super Contributor
timestamp: May 08, 2016, 02:21:10 am
content: Many programs have built-in scripting support as well. Altium and Eagle do, as does AutoCAD. Even Excel has built-in support for scripting (via Visual Basic for Applications), there's an entire (optional) tab on the ribbon dedicated to it. In some cases you have to write the script in an external editor, in other cases (like Excel) you can write and debug the script right in the main application.Done properly, scripting support can allow end users to implement very powerful productivity-enhancing capabilities that the original software developers never anticipated, or that are too specific to a user's needs for them to have bothered with.

author: amspire
author_rank: Super Contributor
timestamp: May 08, 2016, 05:12:28 am
content: Just to give a real example, I recently had to write a script. I had a server connected to the Internet with a dynamically assigned IP address and a fixed DNS record pointing to the currently assigned IP address.I wanted to get an email every hour when the current IP of the internet connection does not match the address in the DNS. In this case, the Internet provider was adamant the IP would not change as long as the connection remained, but the truth was the IP was changing every 3 days - usually at the same time of the day.This is the kind of thing you use scripts for - you need some kind of custom function that is hard to do from standard applications, but easy to do from a Linux Bash shell script.Exactly the same kind of thing within applications that have scripting available. You might want to draw lines in a graphics package based on a list of GPS coordinates in a CSV file, and the graphics package may have no inbuilt function to do this. You could probably do this with a script file about 10 lines long.