Vic*_*kov 13 ironpython spotfire
假设我有一个可视化,由面板按一些分类变量进行格式化,每页一个面板.我想循环遍历面板并将每个图像导出到一个文件,文件名与分类变量匹配.
根据一些已发布的示例,图像导出完全正常.但是,实际获取当前面板的名称时遇到很多麻烦,以便我可以正确命名图像.
这是我的代码:
from Spotfire.Dxp.Application.Visuals import VisualContent
from System.Drawing import Bitmap, Graphics, Rectangle, Point
from System.IO import Path
import re
vc=viz.As[VisualContent]() #viz is the visualization parameter passed to the script
trellis=vc.Trellis
originalIndex=trellis.ActivePageIndex
outputDir=Document.Properties["imageOutputDir"]
for i in range(trellis.PageCount):
#move to the right page
trellis.ActivePageIndex=i
#make the actual image -
viz_r = Document.ActivePageReference.GetVisualBounds(viz)
width=viz_r.Width
height=viz_r.Height
bm = Bitmap(width,height)
g = Graphics.FromImage(bm)
g.TextRenderingHint = g.TextRenderingHint.AntiAlias
r=Rectangle(0, 0, width,height)
vc.Render(g, r)
#save the image
name="%d"%i
#here we would like to instead get the current value of the trellis variable!
#name=?
clean_name=re.sub(r'[/\\:*?"<>|]', '_',name)
tempFilename = outputDir+"\\%s.png"%clean_name
bm.Save(tempFilename)
print "image saved as " + tempFilename
trellis.ActivePageIndex=originalIndex
Run Code Online (Sandbox Code Playgroud)
我貌似通过的所有方法看起来VisualContent和Trellis,并没有发现它.
另一种方法是遍历数据并获取分类变量的值.但是,订单不一定得到保留,因此效果不佳.如果我能得到与每个格子面板相对应的数据,当然我可以从中工作.
| 归档时间: |
|
| 查看次数: |
735 次 |
| 最近记录: |