Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

File.openDialog();

Participant ,
Feb 19, 2020 Feb 19, 2020

Hopefully an easy one.

If I let my script open

 

var aseFile = File.openDialog()

var data = app.parseSwatchFile(aseFile);

 

When my script opens. I can get the information I want from my ase file in my panel example below.


Screenshot 2020-02-19 at 17.12.44.png
However if I use a button to load the ase file 

btn.onClick = function(){

File.openDialog();

var data = app.parseSwatchFile(aseFile);

}

Then I get zippo.

I've tried using my functions, which essentially is what I'm using to fill the panel when I update my edittext, but event that doesn't work

btn.onClick = function(){

File.openDialog();

var data = app.parseSwatchFile(aseFile);

cleanUpGroup(grpContainer);

parseColor();

updatePanel(win);

apply();

}

TOPICS
Error or problem , Resources , Scripting , User interface or workspaces
3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Feb 19, 2020 Feb 19, 2020

You need to save selected file into a variable. Then check if user canceled or selected something. If nothing selected - abort, else do your magic.

 

P.S. Please use Inset/Edit code samples button that looks like this </> to post your code snippets - it makes so much easier to read your code.

 

btn.onClick = function() {
	var aseFile = File.openDialog('Select *.ase file');
	if (aseFile) {
		var data = app.parseSwatchFile(aseFile);
		cleanUpGroup(grpContainer);
		parseColor();
		updatePanel(win);
...
Translate
Advocate ,
Feb 19, 2020 Feb 19, 2020

You need to save selected file into a variable. Then check if user canceled or selected something. If nothing selected - abort, else do your magic.

 

P.S. Please use Inset/Edit code samples button that looks like this </> to post your code snippets - it makes so much easier to read your code.

 

btn.onClick = function() {
	var aseFile = File.openDialog('Select *.ase file');
	if (aseFile) {
		var data = app.parseSwatchFile(aseFile);
		cleanUpGroup(grpContainer);
		parseColor();
		updatePanel(win);
		apply();
	}
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 19, 2020 Feb 19, 2020

Ah, that makes sense.

 

Big big thanks.

 

P.s shall do, I forget to do that. In creative cow I'm awful for doing it.

 

Also based on the other forum page. I promise my coding will improve and be less messy. Self teaching to get it to work Vs tidy and correct coding is something some friends get angry about. 😁

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 24, 2020 Feb 24, 2020

I'm still struggling with this. I can get this to work by adding the onClick feature in the function. But want to make sure that this is the right way of doing this.

If I have the btn2.onClick outside of the function, it doesn't pass the information, but going off the addColorButtons in the script you sent me in the other post, I'm guessing that it is.

var btn = win.add('button', undefined, 'Load Swatch');
var btn2 = win.add('button', undefined, 'Call Swatch');

btn.onClick = function() {
var aseFile = File.openDialog('Select *.ase file');
if (aseFile) {
var data = app.parseSwatchFile(aseFile);
         var numColors = data.values.length; 
         var str = data.values[0].name;
}

btn2.onClick = function(){
alert(str);
    }
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 24, 2020 Feb 24, 2020
LATEST

Your str variable is scoped inside btn.onClick() function and is not accessible inside btn1.onClick() function. Please read about variable scopes in Javascript https://www.sitepoint.com/demystifying-javascript-variable-scope-hoisting/ to understand what's happening.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines