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

How to define script selection.index in History?

Contributor ,
Jul 05, 2019 Jul 05, 2019

Hi experts,

my script like this:

#target indesign
var
mMsg = {title: "addBottomEdge"};

//~ app.doScript( main, ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, mMsg.title );
main ();
function main ()
{ // initial code
try {
   doJob ( checkSelection () );
   }
  catch (e) {
   mMsg.text = e;
   mMsg.line = e.line;
   errorClose (mMsg);
   }
}
function mDialog ()
{
    mMsg.funName = "mDialog";
var
        colorList = app.activeDocument.swatches.everyItem().name,
        strokeTypeList = app.activeDocument.strokeStyles.everyItem().name,
  curPartHistory = eval( app.extractLabel(mMsg.title) );
if (!curPartHistory || false)
  curPartHistory = {
   w: 0,
   c: 0,
   e: 0
   };
     var
        w1 = new Window("dialog","", undefined, {closeButton: false}),  
            mPanel = w1.add("panel", undefined, "Add cell’s bottom edge"),
                mSpace = mPanel.add("group"),
                topLine = mPanel.add("group"),
                    mSt = topLine.add("statictext", undefined, "Line weight: "),
                    mEd = topLine.add("edittext", undefined, String(curPartHistory.w) ),
                    mSt1 = topLine.add("statictext", undefined, "pt"),
               botLine = mPanel.add("group"),
                    mSt2 = botLine.add("statictext", undefined, "Line color: "),
                    mDD = botLine.add("dropdownlist", undefined, colorList),
               botLine = mPanel.add("group"),
                    mSt3 = botLine.add("statictext", undefined, "Stroke type: "),
                    mLL = botLine.add("dropdownlist", undefined, strokeTypeList),
        mButtons = w1.add("group");
  
mButtons.add ('button', undefined, "取り消す", {name: "Cancel"});
mButtons.add ('button', undefined, "OK", {name: "OK"});
   
    mSt1.graphics.font = ScriptUI.newFont ("Verdana", "Italic", 10);
   
    mPanel.alignChildren= "left";
    mEd.characters = 3;
    mDD.selection = curPartHistory.c<colorList.length ? mDD.items[curPartHistory.c] : mDD.items[0];
    mLL.selection = curPartHistory.e<strokeTypeList.length ? mLL.items[curPartHistory.e] : mLL.items[0];
   
    w1.location = [150,150];
//||||||||||||||||||||||||||||||||||||||||||||||||| DIALOG OUTPUT |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  
if (w1.show() ==1 ) {
  with (curPartHistory) {
   w = Number(mEd.text);
   c = mDD.selection.index;
   e = mLL.selection.index;
   }
  app.insertLabel(mMsg.title, curPartHistory.toSource() );
  return curPartHistory;
  }
else exit();
    }
function doJob ( cTarget )
{
    var mChoice = mDialog ();
    with (cTarget) {
        bottomEdgeStrokeWeight = mChoice.w + "pt" ;
        bottomEdgeStrokeColor = app.activeDocument.swatches.item(mChoice.c);
        bottomEdgeStrokeType = app.activeDocument.strokeStyles.item(mChoice.e);
        }
    }
function checkSelection ()
{ // return cells (1st row) or exit()
mMsg.funName = "Check Selection";
var
  mTarget, firstCell, lastCell;
 
if ( !app.documents.length || !app.selection.length || !app.selection[0].hasOwnProperty ("autoGrow")) {
  mMsg.line = $.line - 1;
  mMsg.text = "Nothing selected.\nMy target is a part of table.";
  errorClose (mMsg);
  }
return app.selection[0];
}
function errorClose (Msg)
{ // finish job with error
var
  cContact = "...",
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  cContact_Msg = "...",
  info = "xxxx",
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  conLine, conLineDescr, conLineText, conInfo,
 
  errWin = new Window ("dialog", Msg.title, undefined, {closeButton: false}),
  firstLine = errWin.add("statictext", undefined, "Error detected!\r ", {multiline: true}),
 
  funLine = errWin.add("group"),
  funLineDescr = funLine.add("statictext", undefined, "Function name: "),
  funLineText = funLine.add("statictext", undefined, Msg.funName),
 
  lineLine = errWin.add("group"),
  lineLineDescr = lineLine.add("statictext", undefined, "Line number: "),
  lineLineText = lineLine.add("statictext", undefined, Msg.line),
 
  errLine = errWin.add("group"),
  errLineDescr = errLine.add("statictext", undefined, "Error message: "),
  errLineText = errLine.add("statictext", undefined, Msg.text, {multiline: true}),
 
 
  b = errWin.add("group");
  b.alignment = "center";
  errLine.alignChildren = "top";
// variables defined

  if (cContact_Msg.length) {
   conLine = errWin.add("group");
   conLineDescr = conLine.add("statictext", undefined, cContact);
   conLineText = conLine.add("statictext", undefined, cContact_Msg);
   conInfo = errWin.add("statictext", undefined, info, {multiline: true});
  
   conLineDescr.graphics.font = ScriptUI.newFont ("Verdana", "Bold", 12);
  
   conLineDescr.graphics.foregroundColor  =
    errWin.graphics.newPen (errWin.graphics.PenType.SOLID_COLOR, [1, 0.3, 0], 1);
   
   conInfo.graphics.foregroundColor = firstLine.graphics.foregroundColor =
    errWin.graphics.newPen (errWin.graphics.PenType.SOLID_COLOR, [0.7, 0.7, 0.7], 1);
   
   firstLine.graphics.foregroundColor =
    errWin.graphics.newPen (errWin.graphics.PenType.SOLID_COLOR, [1, 0.3, 0], 1);
   
   conInfo.graphics.font = ScriptUI.newFont ("Verdana", "Bold", 10);
   }
  errWin.alignChildren = "left";
  firstLine.alignment = "center";
  conInfo.alignment = "right";
  funLineDescr.graphics.font =
  lineLineDescr.graphics.font =
  errLineDescr.graphics.font =
  firstLine.graphics.font =
    ScriptUI.newFont ("Verdana", "Bold", 12);
 
  b.add ('button', undefined, "OK", {name: "OK"}); 
 
errWin.show();
with (app.activeDocument.viewPreferences) {
  horizontalMeasurementUnits = cMH;
  verticalMeasurementUnits = cMV;
  rulerOrigin = cRO;
  }
app.activeDocument.zeroPoint = cZP;
exit();
}

it error on line 75

bottomEdgeStrokeType = app.activeDocument.strokeStyles.item(mChoice.e);

it seem has some thing wrong on define the history.

Could someone please tell me how to fix it, please.

thanks

regard

John

TOPICS
Scripting
384
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
Community Expert ,
Jul 06, 2019 Jul 06, 2019

Hi John,

I don't see any error when running your code. Can you also add the preconditions for running your code that causes the issue. i tried several values from the dropdown and it worked, i tried with cell and column selection and it worked just fine.

-Manan

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
Community Expert ,
Jul 06, 2019 Jul 06, 2019

> it error on line 75

And (we asked before) add the exact error text that you get.

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
Contributor ,
Jul 06, 2019 Jul 06, 2019
LATEST

Thank you guys,

in my side not working.

the error come from line 75

bottomEdgeStrokeType = app.activeDocument.strokeStyles.item(mChoice.e);

error reason:

parameter invalid.

John

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