2010-08-17 62 views
0

我想在InDesign CS3 vb.net腳本中對文本框進行分組。它適用於InDesign 2.0,但不適用於InDesign CS3。這裏是我的代碼:InDesign中的vb.net腳本 - 分組文本框

Dim myDoc As InDesign.Document = Nothing 
Dim myGroup As InDesign.Group = Nothing 
Dim myObjectList(2) 

myObjectList.SetValue(myOuterTextFrame, 0) 
myObjectList.SetValue(myInnerTextFrame, 1) 
myObjectList.SetValue(myContentTextFrame, 2) 

myGroup = myDoc.Groups.Add(myObjectList) 

得到錯誤「無法投類型的對象System.Object的[]'鍵入‘InDesign.Objects’。」

回答

0

我發現我在InDesign中的腳本示例答案 - 霓虹燈示例腳本給分組例子

2

我知道你很久以前就問過這個問題了,所以我主要回答以後的搜索。我還沒有找到一個完全管理的方式來使用.Net框架來做到這一點,並相信我,我已經在尋找它。我已經嘗試過一百萬個不同的演員,分類,反思,你的名字。 JavaScript最終最終奏效了什麼。以下是一個使用InDesign.Document對象和兩個或多個表示InDesign項目ID的整數的方法。然後創建一些JavaScript並使InDesign執行它。最後,它返回從這些對象創建的InDesign.Group。

Public Function GroupObjects(ByVal indesignDocument As InDesign.Document, ByVal ParamArray objectIds() As Integer) As InDesign.Group 
    'Sanity checks 
    If indesignDocument Is Nothing Then Throw New ArgumentNullException("indesignDocument") 
    If objectIds Is Nothing OrElse objectIds.Count < 2 Then Throw New ArgumentException("You must pass at least 2 object ids") 

    'We'll assign a unique label to the group that we create in JavaScript so that we can find it in managed code later 
    Dim GID = Guid.NewGuid().ToString() 

    'Create the JavaScript 
    Dim Buf As New StringBuilder() 
    Buf.AppendLine("var items = new Array();") 
    For Each ID In objectIds 
     Buf.AppendFormat("items.push(app.activeWindow.activePage.pageItems.itemByID({0}));", ID) 
     Buf.AppendLine() 
    Next 
    Buf.AppendLine("var g = app.activeWindow.activePage.groups.add(items);") 
    Buf.AppendFormat("g.label='{0}';", GID) 

    Dim IA = indesignDocument.Parent 
    IA.DoScript(Buf.ToString(), InDesign.idScriptLanguage.idJavascript) 

    'Loop through all document groups looking for the object with the label created above 
    For Each G As InDesign.Group In indesignDocument.Groups 
     If Not String.IsNullOrWhiteSpace(G.Label) AndAlso G.Label = GID Then Return G 
    Next 
    Return Nothing 
End Function 

要使用它,在你的代碼,你會說:

Dim MyGroup = GroupObjects(myOuterTextFrame, myInnerTextFrame, myContentTextFrame) 
1

這一個工作me:

 Type type = Type.GetTypeFromProgID("InDesign.Application"); 
     Host = (InDesign.Application)Activator.CreateInstance(type); 

     InDesign.Objects o = Host.CreateCollection(); 
相關問題