Bringing File Path into Text Field

By Using the Text Field Component - Scripting - mouseReleased - Script Editor
path = system.file.openFile()
I have been able to bring up a popup for selecting a file.

How do I move the selected file’s path into the same text Field’s Text Property?
Properly formatted so the selected file (image) can be displayed in an Image component.

Example:

Add something like this to your script (edit to match your components):

event.source.parent.textField.text = path

Or are you already getting the path into the field but there’s a formatting issue? Share your code and details of what is not working as desired if you’d like a more detailed answer.

1 Like

Works perfect! Thank you.
I was close but oh so far from working.
My final Script looks like this -

path = system.file.openFile()
if path != None:
    event.source.text = path
1 Like

How would I change the script that opens the file popup so it will open an exact path?
Right now I’m using the following.

path = system.file.openFile()

What if we want to bring the popup open to J:\Historian\pics?

Something like:

path = system.file.openFile(defaultLocation = 'J:\Historian\pics')

See https://docs.inductiveautomation.com/display/DOC79/system.file.openFile. If you aren’t using all the parameters in a function like this, you just have to specify what you are using with the parameterName = syntax as in example above.

Thank You. The script below is working.

path = system.file.openFile(path = system.file.openFile('pdf', 'J:\FULLSAIL\Historian'))
if path != None:
event.source.text = path

Now I have one more question. What do I use in place of the ‘pdf’ to open All Files?
I have tried several variations with no luck.

Does it work without error like this (not nested)?

path = system.file.openFile('pdf', 'J:\FULLSAIL\Historian')
if path != None:
	event.source.text = path

Yes. That solves that issue. Thanks

Does this work?

path = system.file.openFile(defaultLocation = 'J:\FULLSAIL\Historian')
if path != None:
	event.source.text = path

Nope, Received this error.
TypeError: openFile(): takes no keyword arguments

Okay, so defaultLocation = isn’t going to let us skip the file type. I’m not in a position to test at the moment, but a couple options I’d try if you haven’t already:

path = system.file.openFile( ,'J:\FULLSAIL\Historian')
if path != None:
	event.source.text = path
path = system.file.openFile('*','J:\FULLSAIL\Historian')
if path != None:
	event.source.text = path

I appreciate your help.

path = system.file.openFile( ,'J:\FULLSAIL\Historian')

Returns an error as soon as Apply is hit.

path = system.file.openFile('*','J:\FULLSAIL\Historian')

Opens the dialog box but is looking for files with the extension .*
Seems like what ever is entered into the first position is changed to .xxx

Could try just '' (no space) in that first spot, but doesn’t sound promising. Sorry I’m out of ideas!

I received an answer from Ignition Tech Support this morning. They said to use the following script.

path = system.file.openFile(None,'J:\FULLSAIL\Historian')

The term ‘None’ must have the first letter capitalized. i first tried ‘none’ and received an error msg.
Tested and works exactly like I was hoping.
Thanks to all for your help.

1 Like

That makes sense; thanks for posting the solution!