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

时间:2022-11-06 07:45:51

This should (I think) have a simple answer, assuming that an answer exists.

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

Is it possible to use IronPython to return the path of the current *.dxp project as a string? I use something similar in VBA frequently, and it's become pretty useful.

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

I've tried looking, but I have a hard time working through TIBCO's Python material. :\

我试过看,但我很难通过TIBCO的Python材料。 :\

1 个解决方案

#1


2  

The script below should help you with this. There are 2 ways to get the path of the analysis depending on if you are using a library file or a .dxp. Your specific question is for .dxp but for the sake of passing knowledge on I figured I'd mention it.

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

The DocumentMetaData class in the Application namespace is the key item you need here. The script below is attempting to get the path from the library based property. If that is equal to "None" (aka not from the library) then we try the file path. Beyond that I do some substring logic to get the exact name of the analysis as a slice (substring) of the full path.

Application命名空间中的DocumentMetaData类是此处所需的关键项。下面的脚本试图从基于库的属性获取路径。如果它等于“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

Example output of the prints:
C:\Users\CLESIEMO3\Desktop\super_neat_file.dxp
super_neat_file.dxp

打印输出示例:C:\ Users \ CLESIEMO3 \ Desktop \ super_neat_file.dxp super_neat_file.dxp

#1


2  

The script below should help you with this. There are 2 ways to get the path of the analysis depending on if you are using a library file or a .dxp. Your specific question is for .dxp but for the sake of passing knowledge on I figured I'd mention it.

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

The DocumentMetaData class in the Application namespace is the key item you need here. The script below is attempting to get the path from the library based property. If that is equal to "None" (aka not from the library) then we try the file path. Beyond that I do some substring logic to get the exact name of the analysis as a slice (substring) of the full path.

Application命名空间中的DocumentMetaData类是此处所需的关键项。下面的脚本试图从基于库的属性获取路径。如果它等于“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

Example output of the prints:
C:\Users\CLESIEMO3\Desktop\super_neat_file.dxp
super_neat_file.dxp

打印输出示例:C:\ Users \ CLESIEMO3 \ Desktop \ super_neat_file.dxp super_neat_file.dxp