VB.NET in InDesign Scripting - TextFrames Raggruppare
-
29-09-2019 - |
Domanda
Voglio TextFrames gruppo nel mio script vb.net InDesign CS3. Ha funzionato per InDesign 2.0, ma non funziona con InDesign CS3. Ecco il mio codice:
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)
Come errore "Impossibile oggetto cast di tipo 'System.Object []' digitare 'InDesign.Objects'".
Soluzione 3
Ho trovato la mia risposta nei campioni InDesign Scripting - lo script di esempio al neon ha dato raggruppamento esempi
Altri suggerimenti
Lo so che hai chiesto per questo molto tempo fa, quindi sono per lo più di rispondere per le ricerche future. Non ho trovato un modo completamente gestito per farlo utilizzando il Framework .Net e, credetemi, ho cercato per esso. Ho provato un milione di diversi calchi, sottoclasse, riflessione, è il nome. Ciò che in ultima analisi, ha lavorato alla fine è stato JavaScript. Qui di seguito è un metodo che accetta un oggetto InDesign.Document e due o più numeri interi che rappresentano gli ID elemento InDesign. Si crea quindi un po 'di Javascript e ha InDesign eseguirlo. Infine restituisce un InDesign.Group creata da quegli oggetti.
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
Per usare nel codice che ci si dice:
Dim MyGroup = GroupObjects(myOuterTextFrame, myInnerTextFrame, myContentTextFrame)
Questo ha funzionato per me:
Type type = Type.GetTypeFromProgID("InDesign.Application");
Host = (InDesign.Application)Activator.CreateInstance(type);
InDesign.Objects o = Host.CreateCollection();