vb.net en InDesign Scripting - TextFrames Agrupamiento
-
29-09-2019 - |
Pregunta
Quiero TextFrames grupo en mi guión vb.net InDesign CS3. Se trabajó para InDesign 2.0, pero no funciona con InDesign CS3. Aquí está mi código:
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)
error al obtener "No se puede convertir objeto de tipo 'System.Object []' al tipo 'InDesign.Objects'."
Solución 3
He encontrado mi respuesta en las muestras de secuencias de comandos de InDesign - el script de ejemplo de neón dio ejemplos agrupación
Otros consejos
Yo sé que pediste esto hace mucho tiempo, así que estoy respondiendo sobre todo para futuras búsquedas. No he encontrado una manera totalmente logrado hacer esto utilizando el .NET Framework y créanme, he buscado para ello. He probado un millón de moldes diferentes, la subclasificación, reflexión, lo que sea. Lo que finalmente trabajó en el final era JavaScript. A continuación se muestra un método que toma un objeto InDesign.Document y dos o más enteros que representan ID de elementos de InDesign. A continuación, crea algo de JavaScript y ha InDesign ejecutarlo. Por último se devuelve un InDesign.Group creado a partir de esos objetos.
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
Para usarlo en su código que diría:
Dim MyGroup = GroupObjects(myOuterTextFrame, myInnerTextFrame, myContentTextFrame)
Éste trabajó para mí:
Type type = Type.GetTypeFromProgID("InDesign.Application");
Host = (InDesign.Application)Activator.CreateInstance(type);
InDesign.Objects o = Host.CreateCollection();