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

How can i add a Tab Stop in a cell by insertionPoint?

Community Beginner ,
May 28, 2017 May 28, 2017

Copy link to clipboard

Copied

Hi, All:

I have a problem,

There is a table.

There are a number of cells in the table.

There are a number of text paragraphs in the cell.

I need to add a tab stop somewhere in the text paragraph.

and so:

I want to get X point for the New Tab Stop.

My approach is as follows:

1. Move the insertion point to the target position.

2. Obtain the insertion point of the X point.

This is my code to get the X point from insertion point:

var myIP = app.selection[0]

$.writeln(getRelativeX(myIP))

function getRelativeX(myIP){       

var myPG = myIP.paragraphs[0]

if(myPG.justification != Justification.LEFT_ALIGN){

      var scriptString = 'myPG.justification = Justification.LEFT_ALIGN';                   

      var test = app.doScript(scriptString, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "getRelativeX");     

      var myPGZeroPoint = myPG.horizontalOffset - myPG.leftIndent - myPG.firstLineIndent

      app.activeDocument.undo()

}else{

      var myPGZeroPoint = myPG.horizontalOffset - myPG.leftIndent  - myPG.firstLineIndent   

}

var myRelativeX = myIP.horizontalOffset - myPGZeroPoint

return myRelativeX

}

If the paragraph's alignment is not on the left will get the wrong answer.

So I change the alignment on the left and then undo.

Is there a better way? with out undo?

Thx a lot.

TOPICS
Scripting

Views

568

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
Guru ,
May 28, 2017 May 28, 2017

Copy link to clipboard

Copied

Hi Hoa,

One option would be to just use the properties

IN PSEUDO CODE!

var currentJust = myPG.justification;

if !LTR {

set to LTR

do the calculation

reset myPG.justification = currentJust

}

However it might be better to use the undo method but with the UndoModes.AUTO_UNDO and no tag so that the undo doesn't show up on the edit history.

I somehow also feel there might well be a better way of doing it. But I can see problems with them in cases like tables.

HTH

Trevor

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
Community Beginner ,
May 29, 2017 May 29, 2017

Copy link to clipboard

Copied

Hi Trevor,

Thanks for your reply.

I agree with you, change the properties will be better than use UNDO.

However, it seems to be no difference in nature.

Is it possible to get results in a calculated way?

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
Guru ,
May 29, 2017 May 29, 2017

Copy link to clipboard

Copied

If you are working with simple non transformed text frames then you can just add to the geometricBounds.

If your dealing with tables then your have to calculate the starts of the cell.

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
Guru ,
May 29, 2017 May 29, 2017

Copy link to clipboard

Copied

The fact is that the current method you are using is not going to deal with transformations.

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
Community Beginner ,
May 30, 2017 May 30, 2017

Copy link to clipboard

Copied

Do you mean we had a (better / correct) way to (get cell zero point / add a tab stop at insertion point)?

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
Guru ,
Jun 02, 2017 Jun 02, 2017

Copy link to clipboard

Copied

This is the sort of getter / setter I had in mind.

function getTabStop(tabStopProperties, applyToParagraphStyle) {

    var selection, tf, ipOffset, p, tabProperties, ip, tabListLength;

    selection = app.selection[0];

    if (!selection) {

        return 'No Selection';

    }

    if (!selection.properties.baseline) {

        return 'Selection is not a text object';

    }

    if (selection.parent.constructor !== Story) {

        return 'Sorry only simple text frames currently supported (No tables)';

    }

    tf = selection.parentTextFrames[0];

    if (tf.constructor !== TextFrame) {

        return 'Sorry only simple text frames currently supported (No paths)';

    }

    // Not dealing with character rotation or textFrame transformation

    // Will do so in exchange for payment

    ip = selection.insertionPoints[0];

    bound = ip.paragraphs[0].paragraphDirection === ParagraphDirectionOptions.LEFT_TO_RIGHT_DIRECTION ? 1 : 3;

    ipOffset = Math.abs(tf.geometricBounds[bound] - ip.horizontalOffset);

    if (!tabStopProperties) {

        return ipOffset;

    }

    tabProperties = {

        alignment: TabStopAlignment.LEFT_ALIGN,

        alignmentCharacter: ".",

        leader: "",

        position: ipOffset

    };

    if (tabStopProperties.alignment) {

        tabProperties.alignment = tabStopProperties.alignment;

    }

    if (tabStopProperties.alignmentCharacter) {

        tabProperties.alignmentCharacter = tabStopProperties.alignmentCharacter;

    }

    if (tabStopProperties.leader) {

        tabProperties.leader = tabStopProperties.leader;

    }

    p = applyToParagraphStyle ? ip.appliedParagraphStyle : ip.paragraphs[0];

    tabListLength = p.tabList.length;

    p.tabStops.add(tabProperties);

    if (tabListLength === p.tabList.length) {

        // Basic paragraph style - couldn't add tab spot to style so add it to paragraph

        // This will also get set if the tab position already exists

        ip.paragraphs[0].tabStops.add(tabProperties);

    }

    return ipOffset;

}

function setTabStop(tabStopProperties, applyToParagraphStyle) {

    return getTabStop(tabStopProperties || true, applyToParagraphStyle);

}

alert('get position: ' + getTabStop());

//alert(setTabStop());

var props = {

    alignment: TabStopAlignment.LEFT_ALIGN,

    leader: "."

};

alert('set position: ' + setTabStop(props, true));

HTH

Trevor

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
Community Beginner ,
Jun 05, 2017 Jun 05, 2017

Copy link to clipboard

Copied

LATEST

This is good, but with the table or in other special positions is the main part of the problem I have yet to.

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