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

how to shortcut the increase add space after and increase space before a paragraphi

Explorer ,
Jun 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

I want to use two shortcuts to improve my work.

I think it is possible by scripting but i don't know how so i ask here.
 i want to create a shortcut to increase space after paraprgaph as the button in palette and one to increase the space before the paragraph.

 

my left mouse button and relative finger will thank you forever.

TOPICS
How to , Scripting

Views

3.2K
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

Community Expert , Jun 03, 2021 Jun 03, 2021

For many years I have used small scripts to add or remove space before or after paragraphs. That's much easier than creating separate paragraph styles.

 

Two scripts below: the first adds 1 pt to the space before the currently selected paragraph, the second one adds half a line of white before the current paragraph. 'Selected' means: just click somewhere in the paragraph.

 

I use slight variants of these script to decrease the space by 1 point (simple change += with -=), and to add/remove space

...

Votes

Translate
Community Expert ,
Oct 30, 2023 Oct 30, 2023

Copy link to clipboard

Copied

@bracewell4213 

Don't bother. Below is an upgraded version of the script. It has two modes:

1. Select a text frame and all text columns are targeted.

2. Click in a text column, and only that column is targeted.

 

I also added something I remember I had in the script I used to have (but can't find), namely, a limit to the space to be added before the designated paragraphs. In the script you see the line

 

var maxAdd = 6;

 

which stipulates that not more than 6 points can be added to headings. Change that to any value you that meets your customer's specs.

 

 

// Select a frame to fill all columns in the frame
// Click in a text column to target just that column

(function () {

  app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
  
  // Specify the names of the paragraph styles to target
  var headingStyles = ['SecA', 'SecB', 'SecC'];
  
  // Specify the maximum amount (in points)
  // that can be added before a style
  var maxAdd = 6;
  
  var re = new RegExp ('^(' + headingStyles.join('|') + ')$');
  var columns = [];
  var i, j;
  var frame, headings, gap, delta;

  // Return the headings in a column
  
  function findHeadings (column) {
    var a = [];
    var p = column.paragraphs.everyItem().getElements();
    for (var i = p.length-1; i >= 0; i--) {
      if (p[i] != column.paragraphs[0] 
          && re.test (p[i].appliedParagraphStyle.name)) {
        a.push (p[i]);
      }
    }
    return a;
  }

  if (app.selection.length === 0) {
    exit();
  }
  
  if (app.selection[0] instanceof TextFrame) {
    columns = app.selection[0].textColumns.everyItem().getElements();
    frame = app.selection[0];
  } else if (app.selection[0].hasOwnProperty ('baseline')) {
    columns = [app.selection[0].textColumns[0]];
    frame = app.selection[0].parentTextFrames[0];
  } else {
    exit();
  }

  for (i = 0; i < columns.length; i++) {
    
    headings = findHeadings (columns[i]);
    if (headings.length === 0) {
      continue;
    }

    gap = frame.geometricBounds[2] - columns[i].lines[-1].baseline;
    delta = gap / headings.length;
    if (delta <= maxAdd) {
      for (j = 0; j < headings.length; j++) {
        headings[j].spaceBefore += delta;
      }
    }
  }
}());

 

 

Votes

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
Participant ,
Oct 31, 2023 Oct 31, 2023

Copy link to clipboard

Copied

Thanks a ton, @Peter Kahrel !  When my current mayhem subsides, I will experiment with this! Very powerful.

Votes

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