How to Create a File Browser Using Ansys UI Toolkit?

Vishnu
Vishnu Member, Employee Posts: 222
100 Comments 100 Likes Second Anniversary Name Dropper
✭✭✭✭
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: 222
    100 Comments 100 Likes Second Anniversary Name Dropper
    ✭✭✭✭
    Answer ✓

    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: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭
    ExtAPI.UserInterface.UIRenderer.ShowFileOpenDialog() 
    

    can also be used.

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 361
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

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