0

InDesignCS3vb.netスクリプトでテキストフレームをグループ化したい。InDesign 2.0では機能しましたが、InDesignCS3では機能しません。これが私のコードです:

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 Framework を使用してこれを行う完全に管理された方法を見つけていません。私は何百万もの異なるキャスト、サブクラス化、リフレクションなどを試しました。最終的にうまくいったのは JavaScript でした。以下は、InDesign.Document オブジェクトと、InDesign アイテム ID を表す 2 つ以上の整数を受け取るメソッドです。次に、いくつかの 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 Scripting Samples で答えを見つけました - Neon サンプル スクリプトはグループ化の例を示しました

于 2011-09-29T18:02:43.913 に答える