是否可以使用IronPython将当前* .dxp项目的路径作为字符串返回? [英] Is it possible to use IronPython to return the path of the current *.dxp project as a string?

查看:77
本文介绍了是否可以使用IronPython将当前* .dxp项目的路径作为字符串返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我认为)这应该有一个简单的答案,前提是存在答案.

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

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

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.

我尝试过查找,但是在TIBCO的Python资料编写方面很难. :\

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

推荐答案

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

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.

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

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

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

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

这篇关于是否可以使用IronPython将当前* .dxp项目的路径作为字符串返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆