config file

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

lee ky
Posts: 22
Joined: Tue Mar 03, 2020 3:59 am

config file

Post by lee ky »

I want to create a "config file".
using the prompt
I want to create an ini file like the example below.

Please write and read source.
example
--------------------------------------------
[body]
cropx= 100
cropy= 200

[hair]
cropx= 10
cropy= 80
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: config file

Post by Kukurykus »

Code: Select all

ini = '[body]\ncropx= 100\ncropy= 200\n\n[hair]\ncropx= 10\ncropy= 80';
(fle = File('~/Desktop/File.ini')).open('w'), fle.write(ini), fle.close()

Code: Select all

(fle = File('~/Desktop/File.ini')).open('r'), ini = fle.read(), fle.close(), ini
lee ky
Posts: 22
Joined: Tue Mar 03, 2020 3:59 am

Re: config file

Post by lee ky »

Thank you very much.
When cropx = 100
When reading only "cropx" values
How do you extract variable values?
Last edited by lee ky on Thu Mar 26, 2020 1:10 am, edited 1 time in total.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: config file

Post by Kukurykus »

Code: Select all

ini.match(/\d+(?=\ncropy)/g)[0]
lee ky
Posts: 22
Joined: Tue Mar 03, 2020 3:59 am

Re: config file

Post by lee ky »

(fle = File('~/Desktop/config.ini')).open('r'), ini = fle.read(), fle.close(), ini
var y=ini.match(/\d+(?=\ncropy)/g)[0]
alert(y);
------------------------------------------------------------------------
(fle = File('~/Desktop/config.ini')).open('r'), ini = fle.read()
var y=ini.match(/\d+(?=\ncropy)/g)[0]
fle.close(), ini
alert(y);

I'm sorry, I can't.
Call the first line only
------------------------------------------------------------------------
[dress]
cropx= 100
cropy= 200
[hair]
cropx= 10
cropy= 50
[glasses]
cropx= 1
cropy= 30

alert(dress_cropx);
alert(dress_cropy);
alert(hair_cropx);
alert(hair_cropy);
alert(glasses_cropx);
alert(glasses_cropy);

We need to create a total of 6 variables each
Could you please give me more advice
Last edited by lee ky on Fri Mar 27, 2020 5:26 am, edited 5 times in total.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: config file

Post by Kukurykus »

You were not precise, saying of first value and then of all of them in your post, so I extracted examplary first cell from array, while you can have all of them at once removeing [0] from latest code. To get other values separatly use (singly) another numbers in square brackets.