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

[JS] Add section with user defined marker

New Here ,
Apr 20, 2017 Apr 20, 2017

Copy link to clipboard

Copied

Hi

I'm trying to write (read: copy and paste bits of code from around the web) a script that adds a section to the active page with a section marker that the user defined through a prompt. This input is then sliced to also create the section prefix.

Now I went and looked at JongWare's excellent Object Model database for the sections.add() entry, and this entry in the ExtendScript API on GitHub. But I am really confused on how to fill in the add ([reference: Page][, withProperties: Object]) to define the section as the active page with the marker and the prefix defined by the user

Any help is appreciated

This is what I have so far.

var myDoc = app.activeDocument;

var aPag = app.activeWindow.activePage.name;

var sName = prompt("Input section name","","Section name");

var sPre = sName.slice(0,2);

myDoc.sections.add( xxxxxx );

PS. This thread is closest to my question, but has not been answered and is getting quite old.

PPS. I have the latest CC version.

TOPICS
Scripting

Views

1.1K

Translate

Translate

Report

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

Enthusiast , Apr 20, 2017 Apr 20, 2017

Just for starters. Of course you will need to make sure the page selected does not have a section applied already, etc.

try {

var myDoc = app.activeDocument;

var aPag = app.activeWindow.activePage;

var sName = prompt ("Input section name", "", "section name");

var mySection = myDoc.sections.add(aPag, {sectionPrefix:"B", includeSectionPrefix:true,marker:sName});

} catch (e) {

    $.writeln("Error "+e.message+" at line "+e.line);

}

Votes

Translate

Translate
Enthusiast ,
Apr 20, 2017 Apr 20, 2017

Copy link to clipboard

Copied

Just for starters. Of course you will need to make sure the page selected does not have a section applied already, etc.

try {

var myDoc = app.activeDocument;

var aPag = app.activeWindow.activePage;

var sName = prompt ("Input section name", "", "section name");

var mySection = myDoc.sections.add(aPag, {sectionPrefix:"B", includeSectionPrefix:true,marker:sName});

} catch (e) {

    $.writeln("Error "+e.message+" at line "+e.line);

}

Votes

Translate

Translate

Report

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
New Here ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

Yes, this works perfectly (if no section is applied yet)!

Just to understand: the add() command is filled in with

add(startPage, {sectionProperty1: value, sectionProperty2: value})

And the sectionProperties can be found here.

I'm quite now to coding so I'm still trying to understand the structure.

Thank you!

Votes

Translate

Translate

Report

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
New Here ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

LATEST

A reply, since I can't seem to edit my previous post:

I added a check to see if there is a section marker already applied:

var myDoc = app.activeDocument;

var aPag = app.activeWindow.activePage.documentOffset;

var s = myDoc.pages.item(aPag).appliedSection;

var apSec = s.marker;

if(apSec == ""){

  var sName = prompt ("Apply a new section:", "", "section name");

  var sPre = sName.slice(0,2);

  var mySection = myDoc.sections.add(myDoc.pages.item(aPag), {sectionPrefix:sPre, includeSectionPrefix:true,marker:sName});

} else {

  alert("Section with name " + apSec + " already applied");

}

Perhaps this is useful for somebody else...

Votes

Translate

Translate

Report

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