The same as in the other scripting languages:
Happy to help.
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
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<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);
like above content
for selection content u have to type cast selection object.
InDesign.Selection = (InDesign.Selection).myDocument.Selection;
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.contents
pls help me
Thank you for your reply....
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 Err.Number & " " & Err.Description