Python help for a total novice

Forum rules

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo

Posted on
Mon Jan 21, 2013 5:01 pm
SpencerJRoberts offline
User avatar
Posts: 256
Joined: Dec 09, 2012
Location: Mountain View, CA

Python help for a total novice

Hoping someone can help me get started here. I am a novice scripter, all I've ever used is Applescript (no formal programming background but I pick things up fairly quickly). I am trying to teach myself python, or at least as much python as I need to know to work with Indigo, but am having trouble just getting python to talk to Indigo. I have followed the steps outlined here http://www.perceptiveautomation.com/wiki/doku.php?id=indigo_6_documentation:plugin_scripting_tutorial#device_examples but am probably doing something wrong. When I go to type [indigo host -i] into the scripting shell I get the following

Code: Select all
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'indigohost' is not defined
>>>



If I can just get Python to talk to Indigo I'm confident I can hack my way through learning what I need to! Thanks in advance for any help!

Posted on
Mon Jan 21, 2013 5:16 pm
matt (support) offline
Site Admin
User avatar
Posts: 21429
Joined: Jan 27, 2003
Location: Texas

Re: Python help for a total novice

From Terminal execute both these lines:

Code: Select all
echo "alias indigohost='/Library/Application\ Support/Perceptive\ Automation/Indigo\ 6/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost'" >> ~/.bashrc

echo "alias indigohost='/Library/Application\ Support/Perceptive\ Automation/Indigo\ 6/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost'" >> ~/.bash_profile


Then close the Terminal window and re-open it. Does it work?

Note there is an even easier way though -- select the Plugins→Open Scripting Shell menu item, then you can copy/paste in the lines from the tutorial.

Image

Posted on
Mon Jan 21, 2013 5:28 pm
gtreece offline
Posts: 171
Joined: Sep 26, 2011

Re: Python help for a total novice

I can confirm on my Lion machine, that it is only loading .bash_profile when a new terminal window opens, so the second command Matt posted is what I had to use.

I think you could also include the .bashrc file in your .bash_profile, to achieve the same results, but I just created the alias directly in .bash_profile.

Posted on
Mon Jan 21, 2013 5:30 pm
SpencerJRoberts offline
User avatar
Posts: 256
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: Python help for a total novice

Thanks Matt, that did work but now I still can't get a .py to talk to indigo. I've created a test.py on the desktop and entered this:

Code: Select all
indigohost -e '
indigo.device.toggle("TV Room")
'


and Python returns this:

Code: Select all
Traceback (most recent call last):
  File "/Users/Roberts/Desktop/test.py", line 1, in <module>
    indigohost -e
NameError: name 'indigohost' is not defined
>>>


Sorry for the stupid questions :P

Posted on
Mon Jan 21, 2013 6:09 pm
matt (support) offline
Site Admin
User avatar
Posts: 21429
Joined: Jan 27, 2003
Location: Texas

Re: Python help for a total novice

The 'indigohost' alias is just a shortcut so you can execute Indigo python commands from the Terminal (or a shell script). You don't want to call that from a .py script itself.

If you are wanting to make Indigo python API or object model calls from a .py script (like "indigo.device.toggle"), then that .py script has to be executed by Indigo as an Indigo action OR you can execute it from the shell using something like:

Code: Select all
indigohost -x /SomeFolder/indigo_script.py

That tells the indigo host process to launch and then run the .py file. Point being, Indigo .py files are special and have to be executed from Indigo or using the indigohost to work.

Image

Posted on
Mon Jan 21, 2013 6:31 pm
SpencerJRoberts offline
User avatar
Posts: 256
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: Python help for a total novice

Got it, that should be enough to get me started. Thanks so much!

Posted on
Fri Jan 25, 2013 10:05 pm
SpencerJRoberts offline
User avatar
Posts: 256
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: Python help for a total novice

Thanks again for the help, I'm loving learning Python! Quick question, is there still no way execute action groups or schedules from python? Thanks

Posted on
Fri Jan 25, 2013 11:09 pm
jay (support) offline
Site Admin
User avatar
Posts: 18265
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python help for a total novice


Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jan 25, 2013 11:16 pm
SpencerJRoberts offline
User avatar
Posts: 256
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: Python help for a total novice

Ah, I've been referencing this and must have missed that section, thanks!!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests