[VB JS] Trying to remove characters or pass reference to object to script
Copy link to clipboard
Copied
Hi all
I'm trying to remove characters using VB scripting (well, actually it's via C# and COM but the problem is the same), and I have found out that the Characters class does not have the Remove() method.
What I'm trying to do:
JS:
var tf = indoc.textFrames[0];
var chars = tf.characters.itemByRange(0,10); //just an example
chars.remove(); //not available in vb
So, I'm trying to find out how I could do this in VB?
One very simple way is to iterate through the characters and invoke Delete() on them, but that is highly inefficient.
If there is no other way, is there a way to pass a reference/id of an element from C# environment to a javascript? This way I could have the above code in Javascript and just pass a reference to the textframe/object I would like to invoke the script on.
If I only had the toSource() method in the vb/COM world I could easily pass the reference, but this is not possible right?
I would need to be able to find the object also if it's deeply nested inside a table of tables and such, so simply using AllPageItems would not work as far as I recall.
Many thanks in advance
Ruvan
Copy link to clipboard
Copied
Hi,
InDesign character object has the delete() method instead of remove() method in javascript. Both are doing the same task removing.
Else...
You use this trick like which character you want to delete means selecting that characters using vb selection code.
then write the javascript to capturing that selection objects and do whatever you want in javascript.
triggering the js code in vb using doscript method.
Hope this will help you............
Copy link to clipboard
Copied
Hi Imagine
The delete() method works, but is way too slow.
Unfortunately, using the selection method is not viable because the solution needs to work both on client and server.
If only I could pass a reference to the textframe I want to manipulate (remove) then I could do it in javascript easily. Anybody has an idea on how to pass a reference from c# to the javascript.
Regards,
Ruvan
Copy link to clipboard
Copied
If only I could pass a reference to the textframe I want to manipulate (remove) then I could do it in javascript easily. Anybody has an idea on how to pass a reference from c# to the javascript.
Can't you just call .toSpecifier() on it?
Copy link to clipboard
Copied
Hi John
Unless I'm mistaken, the toSource() method is only available from javascript - not vb/com/c#.
Best regards,
Ruvan
Copy link to clipboard
Copied
I certainly don't know, but I said Specifier not Source.
Copy link to clipboard
Copied
Sorry, my bad. I forgot to type that I tried both. That method does not exist either

