脚本位置:文件->文档属性,新建即可。
1、使用IronPython检查数据表是链接到源还是嵌入在Spotfire中
from Spotfire.Dxp.Data import *table=Document.Data.Tables["表名"]found,tableSettings=Application.Document.Data.SaveSettings.TryGetDataTableSettings(table.Id);
if found and not tableSettings.UseLinkedData :print "Table is embedded"
else:print "Table is Linked"
2、使用IronPython获取登录的Spotfire和Windows用户名
from System import Environment, Threading, Security#This script assumes you have a document property called "myProperty" and will populate the property with the output.
# 需要定义 myProperty 属性
Document.Properties["myProperty"] ="\nSpotfire Username: " + Threading.Thread.CurrentPrincipal.Identity.Name
Document.Properties["myProperty"] +="\nWindows Username(Env): " + Environment.UserName
Document.Properties["myProperty"] +="\nWindows Username(WinIdent): " + Security.Principal.WindowsIdentity.GetCurrent().Name
3、验证是否连接服务器
from Spotfire.Dxp.Framework.ApplicationModel import ConnectivityServiceconnectivity= Application.GetService[ConnectivityService]()
# In 10.4+
#Document.Properties["myProperty"] ="Public Server URI: " + str(connectivity.ServerPublicUri)
#Document.Properties["myProperty"] +="\nInternal Server URI: " + str(connectivity.ServerInternalUri)# Obsolete, but still availiable
Document.Properties["myProperty"] ="Server: " + str(connectivity.ServerUri)Document.Properties["myProperty"] += "\nConnected: " + str(connectivity.IsOnline)
4、使用CredentialsService存储当前用户的凭据
在用户会话结束之前(通常在关闭应用程序或Web浏览器时),设置凭据才可用。这些凭据存储在内存中,并且可以在用户会话中的任何后续脚本或其他外部API调用中使用。
from Spotfire.Dxp.Framework.ApplicationModel import CredentialsService
from System.Threading import Thread credService = Application.GetService(CredentialsService)#Store the username and map it with the key myuser
credService.SetCredentials[str]('myuser',Thread.CurrentPrincipal.Identity.Name)#Get the currentuser
if credService.HasCredentials("myuser"): currentuser=credService.TryGetCredentials[str]('myuser')#To Remove Credential key
credService.RemoveCredentials("myuser")#Now this key can be accessed in any other python script using #credService.TryGetCredentials[str]('myuser')
#and does not need to be stored in a document property.
5、使用JavaScript禁用Spotfire中的左右手柄
$( document ).ready(function(){setTimeout(function(){// Unbind() method removes event handlers from selected elements.$(".Handle.sf-element.sf-element-thumb.TouchTarget").unbind()}, 3000);
})
6、在可视化中打开/关闭轴选择器
from Spotfire.Dxp.Application.Visuals import VisualContent# 1、[Spotfire.Dxp.Application.Visuals.ScatterPlot]
visual = myvis.As[VisualContent]()
# x轴
if(visual.XAxis.ShowAxisSelector==True):visual.XAxis.ShowAxisSelector = False
else:visual.XAxis.ShowAxisSelector = True
# y轴
if(visual.YAxis.ShowAxisSelector==True):visual.YAxis.ShowAxisSelector = False
else:visual.YAxis.ShowAxisSelector = True#'myvis' is a script parameter of type 'Visualization'.# 2、[Spotfire.Dxp.Application.Visuals.HtmlTextArea] 中不可用,没有x,y轴# 3、[Spotfire.Dxp.Application.Visuals.CrossTablePlot]
vi = myvi.As[VisualContent]()
print vi
# print vi.RowAxis
if(vi.ShowAxisSelectors==True):vi.ShowAxisSelectors = False
else:vi.ShowAxisSelectors = True
7、显示或隐藏页面
以编程方式在查看模式下向消费者用户显示或隐藏页面。这意味着可以根据打开分析的上下文(例如,登录用户是谁)向消费者用户显示或隐藏页面。
for p in Document.Pages:if p.Title=='Intro':if p.Visible == False:p.Visible = Trueelse:p.Visible = False