The Spotfire Community is moving to TIBCOmmunity and this forum location has closed. During the transition, you can still search the old forums but posting has been disabled. We encourage you to pick up the discussion at the new Spotfire community on TIBCOmmunity.
File Selection Dialog Via Python Script - TIBCO Spotfire Community

File Selection Dialog Via Python Script

Last post Thu, May 10 2012 6:35 AM by jcskalant. 16 replies.
Page 1 of 2 (17 items) 1 2 Next >
Sort Posts: Previous Next
  • Thu, Apr 12 2012 8:36 AM

    • dmoccia
    • Top 500 Contributor
    • Joined on Mon, Mar 19 2012
    • Posts 8

    File Selection Dialog Via Python Script

    Hello I am writing a script that takes a file and uses it to replace an existing data table in the analysis. Is there a way to access the file selection dialog via the API such that the end users would be able to select a file and return it to such a script? If not I was thinking that I could use the Tix python library to do this (http://docs.python.org/library/tix.html) but I am not sure how additional python libraries can be added to Spotfire server for use? Any help with either of these optiions would be great! Thank you,
  • Thu, May 3 2012 7:13 AM In reply to

    • cougar
    • Not Ranked
    • Joined on Thu, May 3 2012
    • Posts 4

    Re: File Selection Dialog Via Python Script

    Try this:

    import clr
    import System
    clr.AddReference("System.Windows.Forms")
    from System.Windows.Forms import OpenFileDialog, MessageBox
    from Spotfire.Dxp.Data import DataType, DataTable
    from Spotfire.Dxp.Data.Import import TextDataReaderSettings, TextFileDataSource

    #GETS THE FILE PATH FROM THE USER THROUGH A FILE DIALOG
    OpenFile = OpenFileDialog()
    OpenFile.ShowDialog()
    filename=OpenFile.FileName
    MessageBox.Show(filename)

    Filed under: ,
  • Fri, May 4 2012 10:26 AM In reply to

    • dmoccia
    • Top 500 Contributor
    • Joined on Mon, Mar 19 2012
    • Posts 8

    Re: File Selection Dialog Via Python Script

    Thank you very much for this code, works beautifully!!! Dennis
  • Sun, May 6 2012 5:08 PM In reply to

    Re: File Selection Dialog Via Python Script

    Hi Dennis,

    Would you mind to explain the requirement and the solution. It would be very much helpful.

    I am looking some thing very similar.

    User has a visualization pointing to the excel file. They wants to feed a different excel file every month / every week or when ever they want to that Visualization.

    Can you please explain the steps that are involved in writing this script.

    Thanks. 

     

    Jesus answered, “I am the way and the truth and the life. No one comes to the Father except through me. John 14:6
  • Mon, May 7 2012 6:52 AM In reply to

    • dmoccia
    • Top 500 Contributor
    • Joined on Mon, Mar 19 2012
    • Posts 8

    Re: File Selection Dialog Via Python Script

    Essentially I build a workflow which can query a data warehouse for testing data. On occasion the data is not yet in the warehouse and the scientist needs to load a file of data into the workflow. Of course I would like them to be able to browse to select the file, that is the code that "cougar" supplied. This returns a path. The rest of the script uses that path to create a table # get data ds = Document.Data.CreateFileDataSource(fileLocation) # returned from cougars code #create DataFlowBuilder dfb = DataFlowBuilder(ds, Application.ImportContext) # first parameter is number of transformations dfb.Execute(0, DataSourcePromptMode.RequiredOnly) # create the flow flow = dfb.Build() #assayDataTable = Document.Data.Tables["My Results Table"] #assayDataTable.ReplaceData(flow) uniqueName = Application.Document.Data.Tables.CreateUniqueName("File Data Table") fileTable = Application.Document.Data.Tables.Add(uniqueName, flow) Let me know if this helps you
  • Mon, May 7 2012 6:56 AM In reply to

    • dmoccia
    • Top 500 Contributor
    • Joined on Mon, Mar 19 2012
    • Posts 8

    code format

    Sorry I did not know how to format the code so it was easier to read...
  • Mon, May 7 2012 9:37 AM In reply to

    Re: File Selection Dialog Via Python Script

    Thank you for the information. I am not an expert in API's.

    But I hope this would help me.

    Just a basic question to start with - where would I add this code. Can you please explain a little bit more, a small step by step would be really helpful and I will take it from there.

    How would the Dialog box appears to select the File?

    Thanks.

    Jesus answered, “I am the way and the truth and the life. No one comes to the Father except through me. John 14:6
  • Mon, May 7 2012 10:02 AM In reply to

    Re: File Selection Dialog Via Python Script

    Hi Dennis,

    I partially understood the initial code.

    What I did is, I added a text area, added a button and pasted the Code provided by Cougar.

    When I clicked the button the File open dialog box opened.

    Now I have to add your code which I think would replace the datatable with new excel file.

    How complex it would be if I have around 5 datatables in my Visualization.

    Thanks.

    Jesus answered, “I am the way and the truth and the life. No one comes to the Father except through me. John 14:6
  • Tue, May 8 2012 11:48 AM In reply to

    Re: File Selection Dialog Via Python Script

    Hi,

    I am successful till here,

    import clr
    import System
    clr.AddReference("System.Windows.Forms")
    from System.Windows.Forms import OpenFileDialog, MessageBox
    from Spotfire.Dxp.Data import DataType, DataTable
    from Spotfire.Dxp.Data.Import import TextDataReaderSettings, TextFileDataSource
    OpenFile = OpenFileDialog()
    OpenFile.ShowDialog()
    filename=OpenFile.FileName
    MessageBox.Show(filename)
    ds = Document.Data.CreateFileDataSource(filename)
    dfb.Execute(0, DataSourcePromptMode.RequiredOnly)   - This code gives error : Microsoft.Scripting.Runtime.UnboundNameException: name 'dfb' is not defined

    Do you know what would be the reason?Am I missing some thing?

    Thanks

    Jesus answered, “I am the way and the truth and the life. No one comes to the Father except through me. John 14:6
  • Tue, May 8 2012 12:08 PM In reply to

    • cougar
    • Not Ranked
    • Joined on Thu, May 3 2012
    • Posts 4

    Re: File Selection Dialog Via Python Script

    It looks like you missed the line of code that creates the Data Flow Builder (dfb) before you execute it:

     dfb = DataFlowBuilder(ds, Application.ImportContext)

  • Tue, May 8 2012 2:15 PM In reply to

    Re: File Selection Dialog Via Python Script

    Hi Cougar,

    Thanks.

    This is my updated code and I still see that error when I Run the Script.

    import clr
    import System
    clr.AddReference("System.Windows.Forms")
    from System.Windows.Forms import OpenFileDialog, MessageBox
    from Spotfire.Dxp.Data import DataType, DataTable
    from Spotfire.Dxp.Data.Import import TextDataReaderSettings, TextFileDataSource

    OpenFile = OpenFileDialog()
    OpenFile.ShowDialog()
    filename=OpenFile.FileName
    MessageBox.Show(filename)
    ds = Document.Data.CreateFileDataSource(filename)
    dfb = DataFlowBuilder(ds, Application.ImportContext)
    dfb.Execute(0, DataSourcePromptMode.RequiredOnly)   - Microsoft.Scripting.Runtime.UnboundNameException: name 'DataFlowBuilder' is not defined

    Once that is fixed, I am going to add the below code, couple of questions on the below code, can you please correct if I am wrong.

    flow = dfb.Build()
    DataTable = Document.Data.Tables["My Results Table"]  - Is this the name of datatable in my visualization?

    DataTable.ReplaceData(flow)
    uniqueName = Application.Document.Data.Tables.CreateUniqueName("File Data Table") - What is this Datatable?
    fileTable = Application.Document.Data.Tables.Add(uniqueName, flow)

    Thanks.

    Jesus answered, “I am the way and the truth and the life. No one comes to the Father except through me. John 14:6
  • Tue, May 8 2012 2:38 PM In reply to

    • cougar
    • Not Ranked
    • Joined on Thu, May 3 2012
    • Posts 4

    Re: File Selection Dialog Via Python Script

    I think you need to import DataFlowBuilder at the beginning.  Try changing this:

     from Spotfire.Dxp.Data import DataType, DataTable

    To this:

    from Spotfire.Dxp.Data import DataType, DataTable, DataFlowBuilder, DataFlow

  • Wed, May 9 2012 12:01 AM In reply to

    • youbing
    • Top 500 Contributor
    • Joined on Thu, Apr 26 2012
    • Posts 9

    Pink beats by dr. dre studio

    Huge kobe beats betters Schokohutige From Generate Dre Abundant analogue Earbuds, for every accent the abandoned acquisition a new intricate Beats by dr. dre studio ferrariconsiderations with music artists and forth accessories automated engineer.The appearance advice or Pink beats by dr. dre studio maybe
  • Wed, May 9 2012 1:26 PM In reply to

    Re: File Selection Dialog Via Python Script

    Perfectly works and the datatable changes, except the last code gives error,

    FileTable = Application.Document.Data.Tables.Add(uniqueName, flow)  - Failed to create DataTable --->

    Probably the above code is changing the Datatable name with the newly inserted File?

    But even if I don't include the code, the data table changes and works fine and expected.

    Any impact of not adding the last code?

     Thanks.

    Jesus answered, “I am the way and the truth and the life. No one comes to the Father except through me. John 14:6
  • Wed, May 9 2012 1:35 PM In reply to

    • dmoccia
    • Top 500 Contributor
    • Joined on Mon, Mar 19 2012
    • Posts 8

    Re: File Selection Dialog Via Python Script

    That line of code is creating a new table, I do not think you need it. If you get errors once it is removed/or you are not getting the functionality you expect post your full code and I will take a look. Dennis
Page 1 of 2 (17 items) 1 2 Next >
©Copyright 2000-2011 TIBCO Software Inc | Privacy Policy | Terms of Use I Blog I Contact Us I Content Center