0

我想在我的 InDesign CS3 vb.net 脚本中对文本框进行分组。它适用于 InDesign 2.0,但不适用于 InDesign CS3。这是我的代码:

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'类型。”

4

3 回答 3

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)
于 2010-12-14T18:34:34.107 回答
1

这个对我有用:

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

        InDesign.Objects o = Host.CreateCollection();
于 2013-02-21T02:27:00.113 回答
0

我在 InDesign 脚本示例中找到了答案 - Neon 示例脚本提供了分组示例

于 2011-09-29T18:02:43.913 回答