How to Create a File Browser Using Ansys UI Toolkit?

Options
Vishnu
Vishnu Member, Employee Posts: 212
Name Dropper First Anniversary Solution Developer Community of Practice Member First Comment
edited August 2023 in Structures

You can create a file browser or a Folder browser using Ansys UI Toolkit or Windows Forms using clr.AddReference("System.Windows.Forms")

Tagged:

Best Answer

  • Vishnu
    Vishnu Member, Employee Posts: 212
    Name Dropper First Anniversary Solution Developer Community of Practice Member First Comment
    Answer ✓
    Options

    You can create a file browser or a Folder browser using Ansys UI Toolkit.

    Below is an example of File browser.

    def FileBrowser():
     import clr
     clr.AddReference("Ans.UI.Toolkit")
     import Ansys.UI.Toolkit
     DefaultFolder = r'D:'
     FilePath =Ansys.UI.Toolkit.FileDialog.ShowOpenFilesDialog(Ansys.UI.Toolkit.Dialog(),DefaultFolder,'Sample Excel File(s)|*.xlsx',0,'Select File',None)
     if str(FilePath[0]) == 'OK':
        return list(FilePath[1])[0]
    FilePath=FileBrowser()
    

    enter image description here

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 804
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options
    ExtAPI.UserInterface.UIRenderer.ShowFileOpenDialog() 
    

    can also be used.

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 280
    First Anniversary First Comment 5 Likes Ansys Employee
    Options

    This is another example with some more robust options for file save vs. open, multiple file selection, type filters, default directory, etc….