How to Create a File Browser Using Ansys UI Toolkit?

Vishnu
Vishnu Member, Employee Posts: 219
Solution Developer Community of Practice Member First Anniversary Name Dropper 100 Comments
✭✭✭✭
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: 219
    Solution Developer Community of Practice Member First Anniversary Name Dropper 100 Comments
    ✭✭✭✭
    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: 867
    500 Comments Photogenic Name Dropper Solution Developer Community of Practice Member
    ✭✭✭✭
    ExtAPI.UserInterface.UIRenderer.ShowFileOpenDialog() 
    

    can also be used.

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

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