Idiots Guide to Scripting

Feedback
2012-05-17
2014-10-11
  • Ian Hargraves
    Ian Hargraves
    2012-05-17

    Hi,
    I want to automate some scenes in Stellarium for use with a "Sky Guide"
    PowerPoint presentation that I will be giving to my local astronomy club once
    every 3 months. It would be great to open the show with a view of the night
    sky looking south at say midnight on each night of the following 3 months so
    that the constellations run across the screen, without the daylight hours etc.

    I guess that I need to write a script to do this. In a previous life I was a
    software developer using C++ and would like to get started with scripting in
    Stellarium. I have played with the script console window and loaded and run a
    few of the supplied scripts so have a very basic understanding of what's going
    on.

    Therefore I would appreciate some pretty basic help as folows:

    1. Is thjere an idiots guide to scripting Stellarium?

    2. I assume that I should develop scripts in the script console window, or is there a better way of writing the scripts before debugging in the cosole?

    3. Where do I find a list of all the Classes and accessible Member Functions (or whatever they are called in the scipting language?

    4. How do I record a script (like a macro) while running the program?

    5. Is it possible to move the observer's location in the z axis by several hundred lys so that I could "fly" out passed constellations to demonstrate their three-dimensionality, ie. see them changing into an unrecognisable shape?

    6. Once I have got my script running correctly can I record the screen display in some video format that can be called and run from PowerPoint so that I get a seamless PowerPoint presentation?

    Stellarium is absolutely great, the best photo-realistic sky I have ever seen,
    absolutely brilliant.

    Thanks for your help.

     
  • Kajaji
    Kajaji
    2012-05-17

    1. Is thjere an idiots guide to scripting Stellarium?

    I don't think so. Stellarium core script language is ECMAScript.

    1. I assume that I should develop scripts in the script console window, or is there a better way of writing the scripts before debugging in the cosole?

    Another way is to write the script using a text editor, like notepad++ and
    saving the script file in the stellarium user directory (see the first line of
    your log in the help window to know where is the user directory). then execute
    from scripts list in configuration window.

    1. Where do I find a list of all the Classes and accessible Member Functions (or whatever they are called in the scipting language?

    here:
    http://www.stellarium.org/doc/head/scripting.html

    Not all classes can be called from scripts.

    1. How do I record a script (like a macro) while running the program?

    This feature is not available.

    1. Is it possible to move the observer's location in the z axis by several hundred lys so that I could "fly" out passed constellations to demonstrate their three-dimensionality, ie. see them changing into an unrecognisable shape?

    Observer locations can be on Earth, Solar system objects, and a location
    called "Solar system observer" which is a location 334 AU above the solar
    system. To be on any of these locations, select the location and then Ctrl+G
    will take you there

    1. Once I have got my script running correctly can I record the screen display in some video format that can be called and run from PowerPoint so that I get a seamless PowerPoint presentation?

    Stellarium does not have movie recording feature.

    To make a movie, I use script to produce screen shots, then I combine the
    images to make a clip using windows movie maker.

    This is an example:
    a clip to show Venus, Jupiter, the Moon and the Pleiades during March and
    early April 2012.

    I used the following script to produce screen shots every day, then used Movie
    Maker to combine the images into a clip.

    before the script you have to set the viewing direction to West. Timing is
    applicable to my region in Saudi Arabia

    core.setTimeRate(0);
    core.setDate("2012:03:05T16:30:00");
    core.wait(2);
    for (i=0; i<35; i++)
    {
    core.setDate("+1 days")
    core.wait(.2);
    core.screenshot("jv", false);
    }

    The clip is here: http://www.youtube.com/watch?v=VLPu8qH2dbU&context=C4d7c730
    ADvjVQa1PpcFNGRd3bXawIu9wUNVraTfl3SEzD41q7X5Q=

     
  • Ian Hargraves
    Ian Hargraves
    2012-05-18

    Hi Kajaji,
    Many thanks for your help, I shall go and investigate this and watch your
    video.

    Thanks also for the comment about the "Solar System Observer" location as I
    want to produce a movie of the relative planet positions from above the solar
    system over a few months.

    Ian

     
  • Ian Hargraves
    Ian Hargraves
    2012-05-18

    Hi Kajaji,
    Do you know how to hide the Script Console from a script?

    Also how you turn on Planet labels from a script? I tried to use the Planet
    class but the parser did not recognise it!

    Thanks
    Ian

     
  • Kajaji
    Kajaji
    2012-05-18

    I do not know if you can hide the script console from within the script, you
    can toggle it off manually when the script is running, but if your script is
    tested and ready you can save it and execute from the script list with the
    option "close window when script runs".

    Planet labels use this:
    SolarSystem.setFlagLabels(false);

    or

    SolarSystem.setFlagLabels(true);

     
  • Ian Hargraves
    Ian Hargraves
    2012-05-19

    Hi Kajaji,
    With all your help, I'm starting to get somewhere now but I now have two
    problems that I don't seem to be able to sort out:

    1> If I use StelMovementMgr.autoZoomIn(6) to zoom into a planet that I have
    previously selected and then zoom back out again.
    and then use StelMovementMgr.setFlagTracking(false)
    Then I change the time of the display the Earth (landscape) moves with the sky
    as I appear to still be tracking the object, instead of remaining stationary
    while the sky moves.
    Any ideas on how to fix this problem?

    2> When I save my scripts I can't find them from Windows Explorer so I can't
    email them to anyone. I have noticed that when I go to load a script all the
    ones that I have saved have got padlock symbols on them. Is this why I cant
    find them from Windows Explorer?

    Thanks
    Ian

     
  • Kajaji
    Kajaji
    2012-05-20

    Hi Ian,

    1> If I use StelMovementMgr.autoZoomIn(6) to zoom into a planet that I have
    previously selected and then zoom back out again.
    and then use StelMovementMgr.setFlagTracking(false)
    Then I change the time of the display the Earth (landscape) moves with the sky
    as I appear to still be tracking the object, instead of remaining stationary
    while the sky moves.
    Any ideas on how to fix this problem?

    I think you need to have pairs of
    StelMovementMgr.setFlagTracking(true);
    .
    .
    StelMovementMgr.setFlagTracking(false);

    before and after selecting any object.

    ex:

    LandscapeMgr.setFlagLandscape(false);
    LandscapeMgr.setFlagAtmosphere(false);
    StelMovementMgr.setFlagTracking(true);
    StelMovementMgr.setFlagTracking(false);
    core.selectObjectByName("Moon", true);
    StelMovementMgr.setFlagTracking(true);
    StelMovementMgr.autoZoomIn();
    core.wait(5);
    StelMovementMgr.autoZoomOut();
    core.wait(4);
    StelMovementMgr.setFlagTracking(false);
    core.selectObjectByName("Venus", true);
    StelMovementMgr.setFlagTracking(true);
    StelMovementMgr.autoZoomIn();
    core.wait(5);
    StelMovementMgr.autoZoomOut();
    core.wait(4);
    StelMovementMgr.setFlagTracking(false);
    core.setTimeRate(400);

    2> When I save my scripts I can't find them from Windows Explorer so I can't
    email them to anyone. I have noticed that when I go to load a script all the
    ones that I have saved have got padlock symbols on them. Is this why I cant
    find them from Windows Explorer?

    Stellarium, in windows system, saves the scripts in a folder under the AppData
    hidden folder.

    To show hidden folders in windows, use control panel -> folder options -> View
    tab -> Advanced settings (check "Show hidden files and folders" box)

    The path to the script folder is usually like
    C:\Users*Ian*\AppData\Roaming\Stellarium\scripts

    Change Ian to your windows user name.

     
  • Ian Hargraves
    Ian Hargraves
    2012-05-21

    Hi Kajaji.
    Thanks again for your greatly appreciated help.

    It would now appear as though the
    StelMovementMgr.setFlagTracking(false);
    works some time but not others.

    Once this has started happening I then have to restart Stellarium to get the
    script to run properly even though I call
    core.clear("natural")
    StelMovementMgr.setFlagTracking(false);

    as part of my intitialisation sequence.

    It almost as though the commend is missed sometimes but that still doesent
    explain why the above doesent clear it at the start of the next run of the
    script.

    Is there a need to always wait after issuing this command?

    Is there a keyboard command that I can use to save me having to restart
    Stellarium?

    Regards
    Ian

     
  • Ian Hargraves
    Ian Hargraves
    2012-05-26

    Hi Kajaji,
    I have now got most things sorted out in my script that I am writing for a Sky
    Guide for my astronomy club however I am also writing one for the Transit of
    Venus and I am having major problems with the timings when I vary the Time
    speed to speed up the rate of sunrise (in the UK the Sun rises with the
    transit more than 3/4 of the way through. Then I slow the rate down a bit and
    zoom in on the Sun as it rises and then I wait until after 4th contact and
    then speed it up again slightly before zooming back out. (By the way by using
    an autoZoomOut() after each autoZoomIn() followed by a setFlagTracking(false)
    I appear to have cured the intermittent issue with the continued tracking of
    objects that have been focused on by autoZoomIn(). Many thanks for that lead!

    While struggling with the timing issues caused by core.wait() and the variable
    time rate I saw a mention of a function called waitFor() and also on the same
    wiki page http://stellarium.org/doc/head/classStelMainScriptAPI.html it mentions a function
    double StelMainScriptAPI::jdFromDateString ( const QString & dt, const QString
    & spec )
    It says that it returns a double (presumably Julian date for use with waitFor.

    I dont appear to be able to find any info on waitFor(), can I use it to wait
    for the second of 04:57:00 (local) on 06/06/2012?

    Any ideas how I call up the "Date and Time" dialog from a script?

    As always, many thanks for your help and advice.

    Ian

     
  • Kajaji
    Kajaji
    2012-05-27

    core.waitFor("2010:04:30T23:30:00","local"); used to work for 0.10.4.
    Later releases did not support this function.

    To have a similar effect you have two workaround options:

    1. Timelapse
      set the rate to 0 and advance the time manually.

    This is an example that will start and stop at the time you want.

    // Author:  Khalid AlAjaji
    // Name:  timelapse
    // License: Public Domain
    // Description:
    //--------------------------
    core.setMinFps(500);
    
    core.setTimeRate(0);
    core.setDate("2012:06:06T02:27:35");
    end_time = core.getJDay();
    
    core.setDate("2012:06:06T01:30:00");
    start_time = core.getJDay();
    
    total_seconds = 24 * 3600 * (end_time - start_time);
    for (i=0; i<total_seconds; i++)
    {
        core.setDate("+1 seconds")
        core.wait(.001);
    }
    
    core.setTimeRate(0);
    

    The second option will use the time rate function but it will miss the target
    time by a few seconds.

    //
    // Name: waituntil alternative to core.waitfor function which does not work any more
    // License: Public Domain
    // Author: Khalid AlAjaji 
    // Description: example
    // see also [url]http://sourceforge.net/projects/stellarium/forums/forum/278769/topic/3906038[/url]
    function WaitUntil(jd)
    {
        tr = core.getTimeRate(); //get time rate
        core.wait(2);
        var dfTimeNow = 0;
        if (tr > 0)  
          {
            do
            {
              dfTimeNow = core.getJDay();
            }
            while( dfTimeNow < jd);    // let time go by
          }
        else  
          {
            do
            {
              dfTimeNow = core.getJDay();
            }
            while( dfTimeNow > jd);    // let time go by
          }
    }                                                  
    core.setTimeRate(0);
    
    core.setDate("2010-05-01T00:30:00","local");
    timelater = core.getJDay();
    core.setDate("2010:04:30T23:28:35","local");  
    timebefore = core.getJDay();
    plzwait = LabelMgr.labelScreen("testing time forward ...  ", 30, 50, true, 30, "#ffffff");
    core.wait(2);
    core.setTimeRate(100);
    
    WaitUntil(timelater);
    core.setTimeRate(0);
    
    core.wait(5);
    
    plzwait = LabelMgr.labelScreen("testing time backward ...  ", 30, 50, true, 30, "#ffffff");
    
    core.setTimeRate(-100);
    
    WaitUntil(timebefore);
    core.setTimeRate(0);
    
    LabelMgr.deleteAllLabels();
    

    the waituntil function is a modification of the WaitHours(Hours) function at
    this link:
    https://sourceforge.net/projects/stellarium/forums/forum/278769/topic/3906038

    You may want to check this cool animation of the transit. It will set your
    location automatically:
    http://www.sunaeon.com/venustransit/

     

  • Anonymous
    2014-10-11

    Maybe look into recordmydesktop?

     


Anonymous


Cancel   Add attachments