Skip to main content
Inspiring
November 25, 2022
Question

ExtendScript VBScriptの連携

  • November 25, 2022
  • 1 reply
  • 508 views

「新規ページ参照...」メニューアクションを使って索引を作ろうと考えました。

「新規相互参照」ダイアログが表示されている間はScriptが止まる様なので
外部にVBScriptを作っておいてそれを呼び出しています。
外部のVBScriptでキー操作をおこない、ダイアログの操作をしているのですが「読み」の部分が二重に入力されてしまいます。

解決方法がありますでしょうか?

 

外部のVBScript(ディスクトップに「KeyOperations.vbs」として存在(キーボード操作を行いますので注意)

Dim MyShell
Set MyShell= WScript.CreateObject("WScript.Shell")
WScript.Sleep 1000
MyShell.SendKeys "%s" 'キー操作 ALT + S
WScript.Sleep 500
MyShell.SendKeys "^v" 'キー操作 CTRL + V
WScript.Sleep 500
MyShell.SendKeys "%l" 'キー操作 ALT + L
WScript.Sleep 500
MyShell.SendKeys "{ENTER}" 'キー操作 ENTER
Set MyShell = Nothing

 

 ExtendScript

var indexArray = ["猫", "犬"];
var readingArray = ["ねこ", "いぬ"];
app.documents.add();
app.activeDocument.textFramePreferences.properties = {
    autoSizingType : AutoSizingTypeEnum.HEIGHT_AND_WIDTH,
    autoSizingReferencePoint : AutoSizingReferenceEnum.TOP_LEFT_POINT,
    useNoLineBreaksForAutoSizing : true
}
for(var i = 0; i < indexArray.length; i++){
    var myTextFrame = app.activeDocument.pages.firstItem().textFrames.add();
    for(var j = 0; j < 10; j++){
        myTextFrame.parentStory.contents += indexArray[i];
    }
}
var myTextFrameForCopy = app.activeDocument.pages.firstItem().textFrames.add();
app.findTextPreferences = NothingEnum.NOTHING;
for(var i = 0; i < indexArray.length; i++){
    myTextFrameForCopy.parentStory.contents = readingArray[i];
    myTextFrameForCopy.texts.firstItem().select(SelectionOptions.REPLACE_WITH);
    app.copy();
    app.findTextPreferences.findWhat = indexArray[i];
    var findResultArray = app.activeDocument.findText();
    findResultArray[0].select(SelectionOptions.REPLACE_WITH);
    app.doScript('Dim MyShell\r' +
        'Set MyShell = CreateObject("WScript.Shell")\r' +
        'MyShell.Run MyShell.SpecialFolders("Desktop") & "\\KeyOperations.vbs"\r' +
        'Set MyShell = Nothing'
    ,ScriptLanguage.VISUAL_BASIC);
    app.menuActions.item("新規ページ参照...").invoke();
}
This topic has been closed for replies.

1 reply

Inspiring
November 26, 2022
「読み」の部分は仮に入力した後、修正する様にしました。

外部のVBScript(ディスクトップに「KeyOperations.vbs」として存在(キー操作を行いますので注意)

 

Dim MyShell
Set MyShell = CreateObject("WScript.Shell")
WScript.Sleep 1000
MyShell.SendKeys "%s" 'キー操作 ALT + S
WScript.Sleep 500
MyShell.SendKeys "temporary" '文字入力 temporary
WScript.Sleep 500
MyShell.SendKeys "%l" 'キー操作 ALT + L
WScript.Sleep 500
MyShell.SendKeys "{ENTER}" 'キー操作 ENTER
Set MyShell = Nothing

 

 

ExtendScript

 

var indexArray = ["猫", "犬"];
var readingArray = ["ねこ", "いぬ"];
app.documents.add();
app.activeDocument.textFramePreferences.properties = {
    autoSizingType : AutoSizingTypeEnum.HEIGHT_AND_WIDTH,
    autoSizingReferencePoint : AutoSizingReferenceEnum.TOP_LEFT_POINT,
    useNoLineBreaksForAutoSizing : true
}
if(app.activeDocument.indexes.count() == 0){
    app.activeDocument.indexes.add();
}
for(var i = 0; i < indexArray.length; i++){
    var myTextFrame = app.activeDocument.pages.firstItem().textFrames.add();
    for(var j = 0; j < 10; j++){
        myTextFrame.parentStory.contents += indexArray[i];
    }
}
app.findTextPreferences = NothingEnum.NOTHING;
var myNumberOfTopics = 0;
for(var i = 0; i < indexArray.length; i++){
    myNumberOfTopics = app.activeDocument.indexes.firstItem().topics.count();
    app.findTextPreferences.findWhat = indexArray[i];
    var findResultArray = app.activeDocument.findText();
    findResultArray[0].select(SelectionOptions.REPLACE_WITH);
    app.doScript('Dim MyShell\r' +
        'Set MyShell = CreateObject("WScript.Shell")\r' +
        'MyShell.Run MyShell.SpecialFolders("Desktop") & "\\KeyOperations.vbs"\r' +
        'Set MyShell = Nothing'
    ,ScriptLanguage.VISUAL_BASIC);
    app.menuActions.item("新規ページ参照...").invoke();
    if(myNumberOfTopics != app.activeDocument.indexes.firstItem().topics.count()){
        app.activeDocument.indexes.firstItem().topics.itemByName(indexArray[i]).sortOrder = readingArray[i];
    }
}