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

自作多情 提交于 2019-12-24 03:48:08

问题


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.

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


回答1:


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.

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.

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



来源:https://stackoverflow.com/questions/30081535/is-it-possible-to-use-ironpython-to-return-the-path-of-the-current-dxp-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!