質問

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'を入力します。 "

役に立ちましたか?

解決 3

Indesign Scripting Samplesで私の答えを見つけました - Neon Sampleスクリプトはグループ化例を示しました

他のヒント

私はあなたがずっと前にこれを求めたことを知っているので、私は主に将来の検索に答えています。 .NETフレームワークを使用してこれを行うための完全に管理された方法を見つけていません。私を信じて、私はそれを検索しました。私は100万の異なるキャスト、サブクラス、リフレクション、あなたがそれに名前を付けました。最終的に最終的に機能したのは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)

これは私のために働いた:

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

        InDesign.Objects o = Host.CreateCollection();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top