私はあなたがずっと前にこれを求めていたことを知っているので、私は主に将来の検索に答えています. 私は、.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)