World Wind Forums

Go Back   World Wind Forums > WorldWind Development (Other) > Add-on & Script Development

Add-on & Script Development Creating add-ons and scripts for World Wind.

Reply
 
Thread Tools Display Modes
Old 02-25-2007, 05:51 PM   #1
rghosh
Member
 
Join Date: Dec 2006
Location: Kitchener, Ontario
Posts: 52
Default Python Console

TerminallyIll is an embedded Python console World Wind plugin.

http://ranenghosh.com/WorldWind/TerminallyIll/

Name will change to something respectable once the console's capabilities are respectable. Right now you get nothing more than IronPython with IronTextBox in a World Wind plugin form (no specialized environment setup, no utilities, no examples, ...).

First enhancement to Python support in WW on my list doesn't affect this plugin directly -- it's adding support for plugins written in IronPython.
rghosh is offline   Reply With Quote
Old 02-25-2007, 06:25 PM   #2
withak
What?
 
withak's Avatar
 
Join Date: Apr 2005
Location: San Francisco, California
Posts: 2,464
Default

Neat. To get it to load you have to delete the REFERENCES: line in the header and put the dlls in the same directory as WorldWind.exe. Now to learn how to make it do something besides calculator...
withak is offline   Reply With Quote
Old 02-25-2007, 06:42 PM   #3
rghosh
Member
 
Join Date: Dec 2006
Location: Kitchener, Ontario
Posts: 52
Default

Oops! Heh, that's why I started the version number at 0.1

http://ranenghosh.com/WorldWind/Term...llyIll_0_2.zip

Edit: Oh yeah, I put the dlls in the same dir as the plugin (manually created a Plugins/TerminallyIll directory and put them in there), seems to also work Sorry I was mistaken, the dlls were in the WorldWind.exe directory all along, so withak was right.

Last edited by rghosh; 02-26-2007 at 05:23 AM. Reason: wrong advice
rghosh is offline   Reply With Quote
Old 02-25-2007, 08:00 PM   #4
nlneilson
Super Member
 
Join Date: Nov 2006
Location: 35.0376,-117.9688
Posts: 1,519
Default

Will be very interested in how this is implemented.

An interesting note:
IronPython is an implementation of Python that runs atop the .NET's Common Language Runtime. It's still a new project, but its initial performance is promising. Lead developer Jim Hugunin was hired by Microsoft to work on dynamic language support for the CLR, and one of his tasks will be to complete the IronPython implementation.

Last edited by nlneilson; 02-25-2007 at 09:17 PM.
nlneilson is offline   Reply With Quote
Old 02-26-2007, 05:05 AM   #5
rghosh
Member
 
Join Date: Dec 2006
Location: Kitchener, Ontario
Posts: 52
Default

Ah, OK, so I figured out how to get a reference to the world:

Code:
import clr
clr.AddReferenceByPartialName("System.Windows.Forms")
clr.AddReferenceByPartialName("WorldWind")
from WorldWind import MainApplication
from System.Windows.Forms import Control
app = Control.FromHandle( MainApplication.GetWWHandle() )
world = app.WorldWindow.CurrentWorld
This will go in some kind of environment setup script that automatically runs when the console is started so the app and world variables will be ready from the start.

So then I can mess around:

Code:
>>>world.RenderableObjects

<WorldWind.Renderable.RenderableObjectList object at 0x000000000000002E [Earth]>
>>>dir(world.RenderableObjects)

['Add', 'BuildContextMenu', 'ChildObjects', 'CompareTo', 'Count', 'Delete', 'Description', 'DisableExpansion', 'Dispose', 'Enable', 'Equals', 'Finalize', 'GetHashCode', 'GetObject', 'GetObjects', 'GetType', 'IconImage', 'IconImagePath', 'Initialize', 'Initialized', 'IsOn', 'MakeDynamicType', 'MemberwiseClone', 'MetaData', 'Name', 'OnDbfInfo', 'OnDeleteClick', 'OnGotoClick', 'OnInfoClick', 'OnPropertiesClick', 'Opacity', 'Orientation', 'ParentList', 'PerformSelectionAction', 'Position', 'Reduce', 'ReferenceEquals', 'RefreshTimer', 'Remove', 'RemoveAll', 'Render', 'RenderPriority', 'ShowOnlyOneLayer', 'SortChildren', 'StartRefreshTimer', 'Thumbnail', 'ThumbnailImage', 'ToString', 'TurnOffAllChildren', 'Update', 'World', '__class__', '__doc__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__str__', '_metaData', 'dbfIsInZip', 'dbfPath', 'isInitialized', 'isOn', 'isSelectable', 'm_children', 'm_description', 'm_iconImage', 'm_iconImagePath', 'm_opacity', 'm_propertyBrowser', 'm_renderPriority', 'm_thumbnailImage', 'm_world', 'name', 'orientation', 'position']
>>>world.RenderableObjects.Count

15
So some operations that are well-suited to the command line include
  • Filter all renderable objects by a regular expression match of the name, and setting the matches to visible, everything else invisible
  • More generally, use arbitrary conditions like "object.alt > 11000"
  • Query spatial objects from a spatial database, a directory of shape files, an RSS feed, etc., filter based on a condition as above, and use WKT or WKB to create renderable objects and add them to the world

All of these operations rely on expressions of arbitrary structure and so are possibly better suited to a console interface than an ordinary gui interface

Edit: Oh yeah and apparently IronPython.CodeDom.PythonProvider() is incomplete and broken (admittedly so by IronPython, as it apparently breaks some of the tests that IronPython ships with, and there is debate over whether it should actually be removed since Python is a dynamic language), so adding a code provider to WorldWind/PluginEngine/PluginCompiler.cs doesn't work, so there is no clean and simple way to add support for IronPython plugins. A cruddy way that should work is to have a c# plugin that acts as a manager for all python plugins.

Last edited by rghosh; 02-26-2007 at 05:10 AM. Reason: append
rghosh is offline   Reply With Quote
Old 02-26-2007, 02:35 PM   #6
withak
What?
 
withak's Avatar
 
Join Date: Apr 2005
Location: San Francisco, California
Posts: 2,464
Default

Excellent. I got it to find the WW classes but couldn't figure out how to get the mainapplication reference.

Quote:
* Query spatial objects from a spatial database, a directory of shape files, an RSS feed, etc., filter based on a condition as above, and use WKT or WKB to create renderable objects and add them to the world
Yeah, this will make dealing with imported shapefiles a lot easier.

Last edited by withak; 02-26-2007 at 02:38 PM.
withak is offline   Reply With Quote
Old 03-01-2007, 06:36 AM   #7
rghosh
Member
 
Join Date: Dec 2006
Location: Kitchener, Ontario
Posts: 52
Default

Version 0.3:
http://ranenghosh.com/WorldWind/Term...llyIll_0_3.zip

Basic env setup:
  • Now on startup of the console there is an object named env which has fields app and world. So, for example, type "dir(env.world)" to see world's members
  • The directory of the plugin is added to the python path, so you can import python modules in that directory. For example, put a python file named foo.py into the same directory as the plugin, and from the console type "import foo"
rghosh is offline   Reply With Quote
Old 03-01-2007, 03:09 PM   #8
nlneilson
Super Member
 
Join Date: Nov 2006
Location: 35.0376,-117.9688
Posts: 1,519
Default

Downloaded v0.3, put the .dll files in the dir with WorldWind.exe
Made a dir TerminallyIll in the plugins dir for the env.py file
Put TerminallyIll.cs in the WorldWind dir so a breakpoint when debugging will work
Tried the dir(env.world) and dir(env.app) at the prompt, OK

Opened up the Console, surprise, surprise, a help with 9 commands, GPSTracker has a help file also, there may be other plugins that have some type of help but they are in a slim minority.

Is the Big Snake (Python) going to help in getting "Help" into WW?

Last edited by nlneilson; 03-01-2007 at 03:18 PM.
nlneilson is offline   Reply With Quote
Old 03-01-2007, 03:30 PM   #9
withak
What?
 
withak's Avatar
 
Join Date: Apr 2005
Location: San Francisco, California
Posts: 2,464
Default

http://www.codeplex.com/IronPython/R...x?ReleaseId=47

The tutorial that comes with IronPython itself is pretty good, and there are a ton of other samples there as well.

With the environment set for you up it's basically just a matter of translating anything you would do in a C# plugin into python. It just takes a little longer because there isn't any kind of tab completion.

I asked the IronTextBox guy on codeproject about tab completion, he says he is looking into it.

Last edited by withak; 03-01-2007 at 03:46 PM.
withak is offline   Reply With Quote
Old 03-01-2007, 03:47 PM   #10
nlneilson
Super Member
 
Join Date: Nov 2006
Location: 35.0376,-117.9688
Posts: 1,519
Default

Just downloaded IronPython, the IronPython IDE and the Zeus IDE trial a few days ago and have not tinkered with it very much, may be able to use PyScripter as well as Idle. Python has byte of python, dive into python and py_grimoire that is probably applicable to IronPython also, will go thru the IPy tutorial.
Good job on getting this in.
nlneilson is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
General abilities of World Wind globpat WorldWind General 14 02-28-2007 04:07 PM
Download Console michaeltoe Suggestion Box 3 11-07-2004 06:54 PM


All times are GMT +1. The time now is 04:33 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.