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

Create a report or log file

Engaged ,
Feb 26, 2016 Feb 26, 2016

#target illustrator

var doc = app.activeDocument;

var allText = doc.textFrames;

var boldText = app.textFonts.getByName("Arial-Black")

var d = new Date();

var currentYear = d.getFullYear();

var currentMonth = ("0"+(d.getMonth()+1)).slice(-2);

var currentDay = ("0" + (d.getDate())).slice(-2)

for (var i = 0; i < allText.length; i++) {

    //alert(allText.contents.substr(0,4));

    if (allText.contents == "Electrical System") {

        //alert("This is an Electrical Schematic");

        var mediaType = allText.contents;

    }

    if (allText.contents.substr(0, 4) == "UENR") {

        //alert("Media Number " + allText.contents);

        var mediaNumber = allText.contents;

    }

    var textFieldRange = allText.textRange;

    var textProps = textFieldRange.characterAttributes;

    if (allText.contents != "Electrical System" && textProps.textFont == "[TextFont Arial-Black]") {

        //alert("Your Title is: " + allText.contents);

        var mediaTitle = allText.contents;

    }

}

var emailAddress = "someone@myemail.com";

var dateFormat = currentYear + "" + currentMonth + "" + currentDay;

//alert("Media #: " + mediaNumber + "\nMedia Type: " + mediaType + "\nTitle: " + mediaTitle + "\nEmail report to: " + emailAddress + "\nSubmitted on: " + dateFormat);

So I am wanting to take the information from the above script I wrote and have a text file of sorts in a certain format. For example I would like this format

<meta name="Internet E-Mail Address" content="emailAddress">

<meta name="Media No Rev" content="mediaNumber">

<meta name="Publication Date" content="dateFormat">

so a finished report would look like this for example:

<meta name="Internet E-Mail Address" content="someone@myemail.com">

<meta name="Media No Rev" content="UENR1234">

<meta name="Publication Date" content="20160226">

TOPICS
Scripting
896
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

Valorous Hero , Feb 26, 2016 Feb 26, 2016

Here is how I'd do this.

Start out with a string.

var str = '<meta name="Internet E-Mail Address" content="' + emailAddress + '">\r' +

'<meta name="Media No Rev" content="' + mediaNumber + '">\r' +

'<meta name="Publication Date" content="' + dateFormat + '">\r';

Then, write it to a text file.

var f = File("~/Desktop/myFile.txt);

f.open('w');

f.write(str);

f.close();

Translate
Adobe
Valorous Hero ,
Feb 26, 2016 Feb 26, 2016

Here is how I'd do this.

Start out with a string.

var str = '<meta name="Internet E-Mail Address" content="' + emailAddress + '">\r' +

'<meta name="Media No Rev" content="' + mediaNumber + '">\r' +

'<meta name="Publication Date" content="' + dateFormat + '">\r';

Then, write it to a text file.

var f = File("~/Desktop/myFile.txt);

f.open('w');

f.write(str);

f.close();

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
Engaged ,
Feb 29, 2016 Feb 29, 2016

That worked PERFECT!

Thanks so much Silly-V‌!!

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
Engaged ,
Mar 31, 2016 Mar 31, 2016

Silly-V‌ Is there a way to create this html file in a dynamic folder location?

So I have this code to create a folder.....

var mediaFolder = new Folder ("C:\\Users\\wolfecj\\Desktop\\" + mediaNumber.substring(0, 8));

    mediaFolder.create();

So I want this file....

    var f = File("~/Desktop/" + mediaNumber.substr(0, 8) + ".html");

    f.open('w');

    f.write(str);

    f.close();

Written into the folder location I have.

I know I can't write it like this exactly but this is the concept of what I am looking for:

var f = File("~/mediaFolder" + mediaNumber.substr(0, 8) + ".html");

Any thoughts?

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
Valorous Hero ,
Mar 31, 2016 Mar 31, 2016

Looks like you're looking for this:

var f = File(mediaFolder.parent + "/" + mediaNumber.substr(0, 8) + ".html");

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
Engaged ,
Mar 31, 2016 Mar 31, 2016
LATEST

Thanks! just took out the .parent and works exactly like I wanted!

var f = File(mediaFolder + "/" + mediaNumber.substr(0, 8) + ".html");

Thank you yet again Silly-V‌

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