vb.net中的InDesign脚本-分组文本帧

vb.net中的InDesign脚本-分组文本帧,vb.net,arrays,scripting,cs3,adobe-indesign,Vb.net,Arrays,Scripting,Cs3,Adobe Indesign,我想在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(myInne

我想在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'。

我知道您很久以前就提出过这个问题,所以我主要回答将来的搜索。我还没有找到一种完全管理的方法来使用.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

我知道你很久以前就问过这个问题,所以我主要是回答将来的搜索。我还没有找到一种完全管理的方法来使用.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

我在InDesign脚本示例中找到了我的答案-Neon示例脚本给出了分组示例

我在InDesign脚本示例中找到了我的答案-Neon示例脚本给出了分组示例

这一个对我有效:

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

        InDesign.Objects o = Host.CreateCollection();

这一个对我有用:

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

        InDesign.Objects o = Host.CreateCollection();