Search code examples
ironpythonspotfire

Spotfire Ironpy how to edit specific visualization


In all the Spotfire IronPy tutorials the visualizations are defined this way:

vc = detailsVis.As[VisualContent]()

My question is how do I define an object for a specific visualization? Can I do it by title? Can I do it by objectid?

Basically, I have multiple visualizations on a tab. I would like to be able to point the script toward a specific visualization to change axis values and some other stuff..


Solution

  • the easiest way is to use the parameters supplied in the script editor. this is pretty clearly detailed in the online help so I won't go into it.

    you can also refer to a visualization by its title or Id (no imports required):

    # loop through all pages in analysis
    for p in Document.Pages:
        print p.Title, p.Id
    
    # loop through all visuals on a page
    page_index = 3    # integer index of the page (left to right; starts at 0)
    for v in Document.Pages[page_index].Visuals:
        print v.Title, v.Id
    
    # try to find a specific visual on a page by title
    for p in Document.Pages:
        for v in p.Visuals:
            if v.Title == "sometitle": visual_id = v.Id 
    
    # or by Id, if you know it already
    Document.Pages[1].Visuals.TryGetVisual(visual_id)
    

    Document.Pages is a PageCollection.

    Document.Pages.Visuals is a VisualCollection

    it's probably best to just stick with the parameters, though :)