Sunday, April 4, 2010

how to get selection text in indesign...

Hi to all,

i need to get selection content text in indesign using C#

pls help me

Thank you


Thangaraj

how to get selection text in indesign...

The same as in the other scripting languages:

alert (app.selection[0].contents);

Thank youhow to get selection text in indesign...

Hi Jongware,

This is not correct in C# you have type cast all the object to another Object and then only we can access it in required format

for example

if want to get font in active Document

InDesign.Application myInDesign=?(InDesign.Application) COMCreateObject(''InDesign.Application'');

InDesign myDocument = (InDesign.Document)myInDesign.ActiveDocument;


InDesign.ParagraphStyles pStyles = (InDesign.ParagraphStyle)myDocument.ParagraphStyles

InDesign.ParagraphStyle pSteyls = (InDesign.ParagraphStyle)myDocument.ParagraphStyle

for(int i =0;i%26lt;pStyles.Count;i++)

{

pStyle = (InDesign.ParagraphStyle)myDocument.ParagraphStyles[i];

}

public static object COMCreateObject (string sProgID)
{
?// We get the type using just the ProgID
?Type oType = Type.GetTypeFromProgID (sProgID);
?if (oType != null)
?{?
?return Activator.CreateInstance( oType);
?}
?
?return null;
}

like above content

for selection content u have to type cast selection object.

InDesign.Selection = (InDesign.Selection).myDocument.Selection;

Console.Writeline(InDesign.Selection.Contents);

but it showing error....

like this you have to type cast all things in C# and you cannot simply get selection contents like app.selection[0].contents

pls help me

Thank you for your reply....

R. Thangaraj

O-kay. Seems a lot of stuff happens behind javascript's back.

Why would Writeline fail? You say it 'gives an error' but you don't say what error. I would guess this: ''selection'' is an untyped object in ID, because it can return all kinds of objects. In this particular case, you get a return value but you have to manually cast it to the type you would expect [*] -- in this case 'text'. An additional problem may be that it's probably Unicode (wide) text, and -- as documented -- if you select just one special character, it's not text at all but a long integer code for that special character.

[*] That's quite the opposite of what happens with JS, but I think it's the case here.

Hi to all,

I tried in Vb6 to get Indesign Com object and its working

You can get selection content like this

and you convert this code for C#

Dim Appl As InDesign.Application

Dim sel As Variant

Private Sub Command1_Click()
On Error GoTo Err1:

Set Appl = CreateObject(''InDesign.Application.CS3'')
Set sel = Appl.Selection(1) 'selection variable should be a variant
MsgBox (sel.AppliedFont)
MsgBox(sel.Contents)
Err1:
MsgBox Err.Number %26amp; '' '' %26amp; Err.Description

End Sub

  • eye color
  • No comments:

    Post a Comment