假设存在答案,这应该(我认为)有一个简单的答案。
是否可以使用 IronPython 将当前 *.dxp 项目的路径作为字符串返回?我经常在 VBA 中使用类似的东西,它变得非常有用。
我已经尝试查看,但我很难通过 TIBCO 的 Python 资料。 :\
请您参考如下方法:
下面的脚本应该可以帮助您解决这个问题。有两种获取分析路径的方法,具体取决于您使用的是库文件还是 .dxp。您的具体问题是关于 .dxp 的,但为了传递知识,我想我会提到它。
Application 命名空间中的 DocumentMetaData 类是您在这里需要的关键项。下面的脚本试图从基于库的属性中获取路径。如果等于“无”(也不是来自库),那么我们尝试文件路径。除此之外,我还执行了一些子字符串逻辑,以获取分析的确切名称作为完整路径的切片(子字符串)。
from Spotfire.Dxp.Application import DocumentMetadata
dmd = Application.DocumentMetadata #Get MetaData
path = str(dmd.LoadedFromLibraryPath) #Get Path
if path == "None": #If this isn't a library file get the local file path
path = str(dmd.LoadedFromFileName)
sub = path.rfind("\\") + 1 #Find "\" from the right and grab the position of the character past it
else:
sub = path.rfind("/") + 1 #Find "/" from the right and grab the position of the character past it
length = len(path) #get length of path
analysis = path[sub:length] #The specific analysis is the slice of the path after the farthest right '/' character.
print path #for testing
print analysis #for testing
打印输出示例:
C:\Users\CLESIEMO3\Desktop\super_neat_file.dxp
super 整洁文件.dxp
