Using file explorer for a plugin

Using file explorer for a plugin

Aprucka
Participant Participant
828 Views
5 Replies
Message 1 of 6

Using file explorer for a plugin

Aprucka
Participant
Participant

I am creating a plugin which will allow a user to create a drawing automatically based upon a json file. I would like to use a file explorer for the user to select the json file, in the same way that the NETLOAD command works. I was not able to find any sample code for this in the dev guide, is it possible? If so, how? 

Thank you!

0 Likes
Accepted solutions (1)
829 Views
5 Replies
Replies (5)
Message 2 of 6

Aprucka
Participant
Participant
Just to clarify, I am coding the plugin in C#
0 Likes
Message 3 of 6

David_Prontnicki
Collaborator
Collaborator
Accepted solution

Where and when do you want the "file explorer" to show up? Meaning is this from a command in AutoCAD and is it part of a larger project? If its within a larger program loaded into AutoCAD you can use the below function to get the full path and filename of the JSON file.

 

Public Function SelectJsonFile() As String Implements IFileServices.SelectJsonFile

        Dim JsonFileNameAndLocation As String = "Please select an JSON .json file..."

        Try

            Dim selectJsonFileDialog As New OpenFileDialog With {
                        .Title = "Select JSON File:",
                        .Filter = "JSON (*.json)|*.json",
                        .CheckFileExists = True,
                        .Multiselect = False,
                        .FilterIndex = 2,
                        .RestoreDirectory = True
                    }

            If selectJsonFileDialog.ShowDialog() <> DialogResult.Cancel Then

                JsonFileNameAndLocation = IO.Path.GetFullPath(selectJsonFileDialog.FileName)

            End If

        Catch ex As Exception

            'Message omited on purpose

        End Try

        Return JsonFileNameAndLocation

    End Function

 

 This is VB but can easily be converted online. 

0 Likes
Message 4 of 6

Aprucka
Participant
Participant

Yes, part of a larger project. I want to load a dll for a plugin I have made which has the code to parse a json into a given autocad drawing, then the plugin asks for a file and brings up the file explorer, before taking the path given in the file explorer and parsing it as a string in the code.

0 Likes
Message 5 of 6

David_Prontnicki
Collaborator
Collaborator

See above...

0 Likes
Message 6 of 6

Aprucka
Participant
Participant

Thanks!