Je sais que vous avez demandé cela il y a longtemps, je réponds donc principalement à de futures recherches. Je n'ai pas trouvé un moyen entièrement géré de faire cela en utilisant le. Net Framework et croyez-moi, je l'ai cherché. J'ai essayé un million de distributions différentes, sous-classes, réflexions, vous l'appelez. Ce qui a finalement fonctionné à la fin était JavaScript. Voici une méthode qui prend un objet InDesign.Document et deux entiers ou plus qui représentent des ID d'éléments InDesign. Il crée ensuite du JavaScript et InDesign l'exécute. Enfin, il retourne un InDesign.Group créé à partir de ces objets.
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
Pour utiliser dans votre code, vous diriez:
Dim MyGroup = GroupObjects(myOuterTextFrame, myInnerTextFrame, myContentTextFrame)