Customer Banners (Ads) - SpiceUp. AX and SpotfireX Disclaimer



If you find this site useful and you want to support, buy me a coffee   to keep this site alive and without ads.
Showing posts sorted by relevance for query metadata. Sort by date Show all posts
Showing posts sorted by relevance for query metadata. Sort by date Show all posts

Analysis Properties Metadata

# This script gets dxp metadata info into an md variable and stores it to a documentProperty variable

# Config section
myDocProp = "FileInfoMetaData" #if you change this, make sure such doc property exists

# Global string to hold metadata info
# Ddocumentation here: https://docs.tibco.com/pub/doc_remote/spotfire/6.5.0/api/?topic=html/P_Spotfire_Dxp_Application_DocumentMetadata_FileNameUsedBySave.htm

from Spotfire.Dxp.Application import DocumentMetadata
dmd = Application.DocumentMetadata 
md = "============ DXP info ================="
md += "\nLoadedFromLibraryPath: " + str(dmd.LoadedFromLibraryPath)
md += "\nIsDirty: " + str(dmd.IsDirty)
#md += "\nLibraryItemUsedBySave: " + str(dmd.LibraryItemUsedBySave)
md += "\nLoadedFromFileName: " + str(dmd.LoadedFromFileName)
md += "\nLoadedFromLibraryItem: " + str(dmd.LoadedFromLibraryItem)
md += "\nLoadedFromLibraryPath: " + str(dmd.LoadedFromLibraryPath)

# Gets library metadata if LibraryItemUsedBySave exists
# Reference: https://docs.tibco.com/pub/doc_remote/spotfire/6.5.0/api/html/AllMembers_T_Spotfire_Dxp_Framework_Library_LibraryItem.htm
from Spotfire.Dxp.Framework.Library import LibraryItemType
if dmd.LibraryItemUsedBySave !=None:
 li = dmd.LibraryItemUsedBySave
 md += "\n\n=== LibraryItemUsedBySave info ===="
 md += "\nContentSize:" + str(li.ContentSize)
 md += "\nCreated:" + str(li.Created)
 md += "\nDescription:" + str(li.Description)
 md += "\nHasBeenAccessed:" + str(li.HasBeenAccessed)
 md += "\nId:" + str(li.Id)
 md += "\nItemType.Analysis:" + str(li.ItemType.Analysis == LibraryItemType.Analysis)
 md += "\nItemType.Folder:" + str(li.ItemType.Folder == LibraryItemType.Folder)
 md += "\nItemType.InformationLink:" + str(li.ItemType.InformationLink == LibraryItemType.InformationLink)
 md += "\nLastAccess:" + str(li.LastAccess)
 md += "\nLastModified:" + str(li.LastModified)
 md += "\nPath:" + str(li.Path)
 md += "\n:Title" + str(li.Title)

# Gets file metadata if LoadedFromFileName exists
# Documentation here: http://msdn.microsoft.com/en-us/library/system.io.fileinfo_properties(v=vs.110).aspx

# check if LoadedFromFileName, if so, extract attributes from such file
if dmd.LoadedFromFileName!=None:
 md += "\n\n=== LoadedFromFileName info ===="
 from System.IO import FileInfo
 fi = FileInfo(dmd.LoadedFromFileName)
 md += "\n CreationTime: " + fi.CreationTime.ToString()
 md += "\n Directory: " + fi.Directory.ToString()
 md += "\n LastAccessTime: " + fi.LastAccessTime.ToString()
 md += "\n LastWriteTime: " + fi.LastWriteTime.ToString()

#stores md in doc property
Document.Properties[myDocProp]=md

#debug, preview output
print md


Example outputs from a dxp saved in local computer connecting to an excel file:

============ DXP info =================
LoadedFromLibraryPath: None
IsDirty: False
LoadedFromFileName: C:\Users\Jose\Documents\WGC\FileInfo\FileInfo.xlsx
LoadedFromLibraryItem: None
LoadedFromLibraryPath: None

=== LoadedFromFileName info ====
CreationTime: 10/8/2014 2:37:29 PM
Directory: C:\Users\Jose\Documents\WGC\FileInfo
LastAccessTime: 10/8/2014 4:19:25 PM
LastWriteTime: 10/8/2014 4:19:26 PM


Example outputs from a dxp saved in Library connecting to an excel file:

============ DXP info =================
LoadedFromLibraryPath: None
IsDirty: False
LoadedFromFileName: C:\Users\Jose\Documents\WGC\FileInfo\FileInfo.xlsx
LoadedFromLibraryItem: None
LoadedFromLibraryPath: None

=== LibraryItemUsedBySave info ====
ContentSize:40290
Created:10/8/2014 3:18:00 PM
Description:Shows data source metadata
HasBeenAccessed:False
Id:27266955-7578-4343-b8d4-2a702ebc5568
ItemType.Analysis:True
ItemType.Folder:True
ItemType.InformationLink:True
LastAccess:1/1/0001 12:00:00 AM
LastModified:10/9/2014 3:43:19 PM
Path:/Users/Jose Leviaguirre/FileInfo
:TitleFileInfo

=== LoadedFromFileName info ====
CreationTime: 10/8/2014 2:37:29 PM
Directory: C:\Users\Jose\Documents\WGC\FileInfo
LastAccessTime: 10/8/2014 4:19:25 PM
LastWriteTime: 10/8/2014 4:19:26 PM


Example of a dxp file connecting to an infolink not saved anywhere
============ DXP info =================
LoadedFromLibraryPath: None
IsDirty: True
LoadedFromFileName: None
LoadedFromLibraryItem: None
LoadedFromLibraryPath: None


Example of a dxp file connecting form infolink saved in library
============ DXP info =================
LoadedFromLibraryPath: None
IsDirty: False
LoadedFromFileName: None
LoadedFromLibraryItem: None
LoadedFromLibraryPath: None

=== LibraryItemUsedBySave info ====
ContentSize:33091
Created:10/9/2014 3:54:28 PM
Description:
HasBeenAccessed:False
Id:ef80f41e-3dc4-4c63-a815-99cebbbd42f9
ItemType.Analysis:True
ItemType.Folder:True
ItemType.InformationLink:True
LastAccess:1/1/0001 12:00:00 AM
LastModified:10/9/2014 3:54:28 PM
Path:/Users/Jose Leviaguirre/test
:Titletest


Document Metadata

from Spotfire.Dxp.Application import DocumentMetadata
print Application.DocumentMetadata.LoadedFromLibraryPath

Here are more properties from DocumentMetadata
NameDescription
Public propertyFileNameUsedBySave
Gets the current file name used by save operations initiated by the user.
Public propertyIsDirty
Returns true if the document has been changed since it was last saved.
Public propertyLibraryItemUsedBySave
Gets the library item that the analysis was last saved to in the library; otherwise null.
Public propertyLoadedFromFileName
Gets the file name that the analysis was opened from; otherwise null.
Public propertyLoadedFromLibraryItem
Gets the library item that the analysis was opened from; otherwise null.
Public propertyLoadedFromLibraryPath
Gets the library path that the analysis was opened from; otherwise null.


If the analysis is located in the library, then use the LibraryItemUsedBySave

from Spotfire.Dxp.Application import DocumentMetadata
libraryItem = Application.DocumentMetadata.LibraryItemUsedBySave

print "size:\t\t", libraryItem.ContentSize
print "date created:\t", libraryItem.Created
print "description:\t", libraryItem.Description
print "guid:\t\t", libraryItem.Id
print "last modified:\t",libraryItem.LastModified
print "location:\t\t",libraryItem.Path
print "Title\t\t",libraryItem.Title

result:


size: 685362
date created: 9/11/2016 10:19:43 AM
description:  Document Metadata Test
guid: 6f072612-7c3c-4653-a2e9-f76ce6f45dc3
last modified: 9/12/2016 10:19:43 AM
location: /Analysis/lab/documentMetaData
Title documentMetaData


Check these other posts for more on this topic