vb.net dans InDesign Scripting - Regroupement TextFrames
-
29-09-2019 - |
Question
Je veux groupe dans mon script cadres de texte de vb.net InDesign CS3. Il a travaillé pour InDesign 2.0, mais il ne fonctionne pas avec InDesign CS3. Voici mon code:
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)
Obtenir erreur "Impossible d'objet cast de type 'System.Object []' taper 'InDesign.Objects'."
La solution 3
J'ai trouvé ma réponse dans les échantillons de scripts InDesign - l'exemple de script Neon a fourni des exemples de groupement
Autres conseils
Je sais que vous avez demandé ce depuis longtemps, donc je suis la plupart du temps à répondre pour les recherches futures. Je ne l'ai pas trouvé un moyen totalement réussi à le faire en utilisant le Framework .Net et croyez-moi, je l'ai cherché pour cela. J'ai essayé un million de différents moulages, sous-classement, de réflexion, vous le nom. Ce qui, finalement, a travaillé à la fin était JavaScript. Ci-dessous est un procédé qui prend un objet InDesign.Document et deux ou plusieurs nombres entiers qui représentent les ID d'objet InDesign. Il crée alors un peu de JavaScript et a InDesign exécuter. Enfin, il renvoie 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 l'utiliser dans votre code, vous diriez:
Dim MyGroup = GroupObjects(myOuterTextFrame, myInnerTextFrame, myContentTextFrame)
Celui-ci a fonctionné pour moi:
Type type = Type.GetTypeFromProgID("InDesign.Application");
Host = (InDesign.Application)Activator.CreateInstance(type);
InDesign.Objects o = Host.CreateCollection();