1

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..

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
SwolleyBible
  • 243
  • 7
  • 20

1 Answers1

3

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 :)

niko
  • 3,946
  • 12
  • 26
  • Thanks. So, the TryGetVisual(visual_id) is an ironpy function? – SwolleyBible Sep 07 '15 at 16:58
  • it's a method of the VisualsCollection object which is implemented by the Spotfire API which can be accessed by IronPython. you don't need to import anything, but you couldn't run this function outside of Spotfire. note that referring to a visualization by id is a really hardcoded functionality. using a parameter is more flexible and allows you to more easily change which visualization is being referred to. otherwise you baiscally have to look up the visualization's id using the method I mention above and then copy that into the script. – niko Sep 07 '15 at 20:25
  • Ahh thanks.. yeah the problem is I use one property/script to edit only certain visualizations.. so the looping script is great – SwolleyBible Sep 07 '15 at 23:44