2010-08-17 3 views
0

Je souhaite regrouper des textframes dans mon script InDesign CS3 vb.net. Cela a fonctionné pour InDesign 2.0 mais cela ne fonctionne pas avec InDesign CS3. Voici mon code:vb.net dans InDesign Scripting - Grouping TextFrames

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 de jeter l'objet de type 'System.Object []' taper 'InDesign.Objects'."

Répondre

0

J'ai trouvé ma réponse dans les échantillons de scripts InDesign - l'exemple de script de Neon a donné groupant des exemples

2

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) 
1

Celui-ci a travaillé pour moi:

 Type type = Type.GetTypeFromProgID("InDesign.Application"); 
     Host = (InDesign.Application)Activator.CreateInstance(type); 

     InDesign.Objects o = Host.CreateCollection();