是否可以使用 IronPython 将当前 *.dxp 项目的路径 return 作为字符串?

Is it possible to use IronPython to return the path of the current *.dxp project as a string?

假设存在答案,这应该(我认为)有一个简单的答案。

是否可以使用IronPython将当前*.dxp项目的路径return作为字符串?我经常在 VBA 中使用类似的东西,它变得非常有用。

我试过寻找,但我很难通过 TIBCO 的 Python material。 :\

下面的脚本应该可以帮助您。有两种获取分析路径的方法,具体取决于您使用的是库文件还是 .dxp。您的具体问题是关于 .dxp 的,但为了传递知识,我想我会提到它。

Application 命名空间中的 DocumentMetaData class 是您需要的关键项。下面的脚本试图从基于 属性 的库中获取路径。如果等于 "None"(也不是来自库),那么我们尝试文件路径。除此之外,我还做了一些子字符串逻辑,以获取分析的确切名称作为完整路径的切片(子字符串)。

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