On Tue, Oct 08, 2013 at 03:33:42PM +0200, David Nečas (Yeti) wrote:
> I modified your script so that it works

And now I even attached it...

Yeti

#################################################
# process_afm.py
import os, sys, gwy

plugin_menu = "/Process AFM Image"
plugin_type = "PROCESS"
plugin_desc = "Process currently active file"

def run():
    c = gwy.gwy_app_data_browser_get_current(gwy.APP_CONTAINER)
    process_container(c)

# I make this a separate function so I can call it from other scripts
def process_container(c):
    gwy.gwy_process_func_run("line_correct_median", c, gwy.RUN_IMMEDIATE)
    gwy.gwy_process_func_run("scars_remove", c, gwy.RUN_IMMEDIATE)
    dfields = get_data_fields_dir(c)
    d = dfields['/0/data']
    w = d.get_xres()
    h = d.get_yres()
    d.fit_lines(0,0,w,h,3,False,gwy.ORIENTATION_VERTICAL)
    d.data_changed()

def get_data_fields_dir(container):
    """
    Get list of available datafield stored in given container as directory
    where key is key name and value is DataField object.

    @param container: gwy.Container with datafields

    @return: a directory of datafields
    """
    d = {}
    for key in container.keys_by_name():
        x = container.get_value_by_name(key)
        if type(x) is gwy.DataField:
            d[key] = x
    return d

#################################################
# process_all.py
# This calls another script I wrote so I need to import it.
import os, sys, gwy

sys.path.append(os.environ['HOME'] + '/.gwyddion/pygwy')
import process_afm

plugin_menu = "/Process All Opened Files"
plugin_type = "PROCESS"
plugin_desc = "Process all opened files"

def run():
    cons = gwy.gwy_app_data_browser_get_containers()
    for c in cons:
        gwy.gwy_app_data_browser_select_data_field(c, 0)
        process_afm.process_container(c)

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Gwyddion-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gwyddion-users

Reply via email to