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

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. :\

解决方案

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值