Copy link to clipboard
Copied
Hi,
I have a little question about swatch and color.
I have a table and I try to change the the border of the table (weight, color and type)
1/ For the style
myTable.TopBorderStrokeType = myDocument.StrokeStyles ;
I try to find the "Solid", "outset" and "inset" style (continue style) but I didn't. I try g from 1 to 20 and no style like this. How can I find it?
In C# I cant use myDocument.StrokeStyles.item("Solid") and I did'nt found a methode like StrokStyles.GetByName("Solid") or something like that.
An idea?
2/ For the color
I have a big problem :
myTable.BottomBorderStrokeColor = createColor(hexToRGB(int.Parse(table.Attributes["borderColor"].InnerText)));
/*
** Convert a decimal color to an RGB color
*/
private Array hexToRGB(int color)
{
int[] rgb = new int[3];rgb[0] = (color >> 16) & 0xFF;
rgb[1] = (color >> 8) & 0xFF;
rgb[2] = color & 0xFF;return rgb;
}}
When I try this. An error. I can't convert InDesign.Color into InDesign.Swatch.
I try to create a new swatch, but method like : myDocument.Colors.add() doesn't exist for swatch. I make some tests but unfortunatly they didn't work.
So what I am supposed to do?
It's very complicated for a small colored border :'( :'(
Thank you for your answer.
PS : when my project will be finish, I will post some tutorial for InDesign Scripting in C# to help others adventurers. Where will I post it?
(sorry for my english mistakes. French inside )
Oh. C# is definitely not the way to script InDesign...
Here's an example in JS with all the arguments:
I don't know if you can pass undefined in C#. If yes, just make them
all undefined.
If you can't pass undefined (and I'm assuming that's the case), try
this:
I'm passing an empty array as the third argument and setting the
UndoMode to entire script with a script name of My Fancy Script.
app.doScript(myFunction, ScriptLanguage.JAVASCRIPT, [],
UndoModes.ENTIRE_SCRIPT, "My Fancy Script");
Harbs
Copy link to clipboard
Copied
Any idea ? :'(
Copy link to clipboard
Copied
Hi Melzi94270,
About the 'stroke styles' problem, try something like this:
myTable.TopBorderStrokeType = myDocument.strokeStyles.item("$ID/Solid");
@+
Marc
Copy link to clipboard
Copied
thanks, but my biggest problem is between swatch and color. I don't understand the difference. And as I am coding in C# (strong type) i don't know how to give a color to a stoke. 😕
Copy link to clipboard
Copied
Still have the same problem...
InDesign.Color myColorPage = myDocument.Colors.Add();
myColorPage.Model = InDesign.idColorModel.idProcess;
myColorPage.Space = InDesign.idColorSpace.idRGB;
myColorPage.ColorValue = rgb;
My tests :
myTable.BottomBorderStrokeColor = myStroke;
Error : Cannot implicitly convert type 'InDesign.Color' to 'InDesign.Swatch'. An explicit conversion exists. (Are you missing a cast?)
myTable.BottomBorderStrokeColor = (InDesign.Swatch) myStroke;
Error : System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'InDesign.Swatch'
myTable.BottomBorderStrokeColor = (InDesign.Swatch)myDocument.Swatches[myDocument.Swatches.Count];
Error : System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'InDesign.Swatch'
How can I put my InDesign.Color type into MyTable.BottomBorderStrokeColor?
I am really lost and I don't know how to do :'(
Copy link to clipboard
Copied
Dim myInDesign As InDesign.Application
Dim myDoc As InDesign.Document
Set myInDesign = CreateObject("InDesign.Application.CS3")
Set myDoc = myInDesign.ActiveDocument
Set MyTable = myDoc.Stories.Item(1).Tables.Item(1)
Set myColor = myDoc.Colors.Add
myColor.Name = "Green"
myColor.Model = idColorModel.idProcess
myColor.Space = idColorSpace.idRGB
myColor.ColorValue = Array(0, 255, 0)
MyTable.BottomBorderStrokeColor = myColor
Copy link to clipboard
Copied
Thank you,
But in C# as I wrote, It doesn't work :
Error : Cannot implicitly convert type 'InDesign.Color' to 'InDesign.Swatch'. An explicit conversion exists. (Are you missing a cast?)
Someone can help me?
Copy link to clipboard
Copied
Mel - Melanie?
A while ago this link was mentioned for similar trouble. Too bad that the forum archives are already purged...
http://confluence.ubs-icap.org/display/PUBASSIST/Windows+Vista+and+InDesign+Notes
I don't know whether this will solve your problem.
Dirk
Copy link to clipboard
Copied
Mel as Melanie yes.
Thanks for your answer. But I am on an XP. So I think this problem is not mine. C# use strong type and javascript not. And here is my problem.
in javascript you can give to stroke color a color. It don t make the distinction between swatch and color.
In c#, it make the difference between an indesign.color type and an indesign.swatch type. So I can't do the same thing that javascript tutorials show.
I don't know how to make a conversion from color type to swatch.
If someone have the solution please answer me.
i am really desperate
Copy link to clipboard
Copied
Even though you run on XP, have you verified that the classes are correctly registered? Incomplete registration can be caused by file/folder permissions in the initial run when the tlb is built.That web site and your error message in the explicit cast suggest that C# depends on registry IDs where most others don't.
Look for these values taken from the SDK, the format of the registry representation will slightly differ:
#define kSwatch_CLSID { 0xa373654f, 0x4f5c, 0x11d2, { 0xab, 0x7, 0x0, 0xc0, 0x4f, 0xa3, 0x49, 0xc7 } }
Also from my archive:
"Debilo" once managed to work around trouble with function arguments.
You may be able to adopt it to your problem...
- Build a very small VB.NET Application that calls the function without the optional parameters.
- Disassemble the EXE with Reflector (http://www.aisto.com/roeder/dotnet/) and view the C# code.
The resulting code will look like this:
object scriptArgs = LateBinding.LateGet( _id, null, "ScriptArgs", new object[0], null, null );
LateBinding.LateCall( scriptArgs, null, "Clear", new object[0], null, null );
You need a reference to the "Mircosoft.VisualBasic" DLL ! ( probably a typo -- Dirk )
Then include these two namespaces:
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
-----------
Another different approach, from my "hack" department:
Watch out for a collection method named itemByID(), or whatever the TLB name formatting did to it.
Most InDesign objects have an ID which maps straight to the internal UID. Exceptions include ..preferences, Text ( Paragraph etc. ) and XML.
You should be able to take the ID property from that wannabe color, and if it is really a swatch then the equivalent to JS doc.swatches.itemByID(myID) should yield a swatch.
As I said, a hack, if it does not work I'm sorry.
------
Last resort would be: invoke JS from C# ...
Dirk
Copy link to clipboard
Copied
While we're talking about CLSIDs, I think you can use Reflect to look up the interface by ID rather than go thru TLB. Maybe that helps with the cast. See the link in the other thread, which in the next hop leads to http://msdn.microsoft.com/en-us/library/k3a58006(VS.80).aspx .
Dirk
Copy link to clipboard
Copied
Does this work?
InDesign.Swatch myColorPage = myDocument.Colors.Add();
Harbs
Copy link to clipboard
Copied
@Harbs : Thanks for your answer, but no it doesn't work.
@Dirk :
Th itemById() approach doesn't work.
InDesign.Color myStroke = createColor(decToRGB(int.Parse(table.Attributes["borderColor"].InnerText)));
myTable.BottomBorderStrokeColor = (InDesign.Swatch)myDocument.Swatches.ItemByID(myStroke.Id);
ERROR : Unable to cast COM object of type 'System.__ComObject' to interface type 'InDesign.Swatch'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A373654F-4F5C-11D2-AB07-00C04FA349C7}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Other approaches (VB.NET and Reflector, and format of the regitry) are (I think) a little bit too difficult for me .
So I will call a javascript from my C# ... just for a poor color border..... It's so disappointing. 😕
But I am coding on server side. It is possible to have javascript at the server side? How could I call the javascript in my C# method?
Thank you for all the time you have taken to help me Dirk.
Have a good day
Copy link to clipboard
Copied
You should be able to save the JS code as a String and use doScript()
to run it.
Harbs
Copy link to clipboard
Copied
Thank you Harbs
My javascript is working! But I can't arrived to call it from c#.
app.DoScript(object script, InDesign.idDscriptLanguage language, object withArguments, InDesign.idUndoModes, string undoMode);
I do :
InDesign.Color myColor = createColor(decToRGB(int.Parse(table.Attributes["borderColor"].InnerText)));
object[] args = new object[2] { myTable, myColor };
string script = "main(); function main(args){var myTable = args[0]; var myColor=args[1]; myTable.topBorderStrokeColor = myColor;myTable.bottomBorderStrokeColor = myColor; myTable.leftBorderStrokeColor = myColor; myTable.rightBorderStrokeColor = myColor;}";
app.DoScript(script , InDesign.idScriptLanguage.idJavascript, args, InDesign.idUndoModes.idEntireScript, "test");
I can't find tutorial on the web. I don't know how to use the 2 last arguments. Something doesn't work, "undefined is not an object".
Do you know where I can find documentation of this function ? (to understand each argument)
Or someone have already use this method and can explain me?
And if one day I have to do InDesign Scripting again... I promise I will use Javascript. C# is too horrible 😕
Copy link to clipboard
Copied
The last two arguments are optional. Just leave them out.
In the third argument, you can have the whole script undoable in one
step. The last argument sets the undo name.
Harbs
Copy link to clipboard
Copied
Unfortunately not in C#. All arguments are obligatory......
I don't found how to make it work... I don't know how to use the 4th and 5th arguments.
And for the third argument, it corrresponding to arguments I give to my script.
I give args (array) with args[0] = myTable and args[1] = my Color.
I have to do something like that in my script?
main(args);
main (array args)
{
var myTable = args[0];
var myColor=args[1];
myTable.topBorderStrokeColor = myColor;
myTable.bottomBorderStrokeColor = myColor;
myTable.leftBorderStrokeColor = myColor;
myTable.rightBorderStrokeColor = myColor;
}
or could I put directly that :
var myTable = args[0];
var myColor=args[1];
myTable.topBorderStrokeColor = myColor;
myTable.bottomBorderStrokeColor = myColor;
myTable.leftBorderStrokeColor = myColor;
myTable.rightBorderStrokeColor = myColor;
I really don't uderstand how works this function... Somebody have an exemple of use? Or informations about DoScript()?
Copy link to clipboard
Copied
Oh. C# is definitely not the way to script InDesign...
Here's an example in JS with all the arguments:
I don't know if you can pass undefined in C#. If yes, just make them
all undefined.
If you can't pass undefined (and I'm assuming that's the case), try
this:
I'm passing an empty array as the third argument and setting the
UndoMode to entire script with a script name of My Fancy Script.
app.doScript(myFunction, ScriptLanguage.JAVASCRIPT, [],
UndoModes.ENTIRE_SCRIPT, "My Fancy Script");
Harbs
Copy link to clipboard
Copied
It is workiiing !! Yes !!!!!
The C# code :
object[] args = new object[2] {myTable, myColor};
string script = "var myTable = arguments[0]; var myColor = arguments[1]; myTable.topBorderStrokeColor = myColor; myTable.bottomBorderStrokeColor = myColor; myTable.leftBorderStrokeColor = myColor; myTable.rightBorderStrokeColor = myColor;";
app.DoScript(script, InDesign.idScriptLanguage.idJavascript, args, InDesign.idUndoModes.idEntireScript, "My Script");
Thanks you very very VERY much Harbs
And if someone do indesign scripting in C# like me (in fact it's a bad idea), I can help (I already work on textFrame, tables, pictures, etc)
Copy link to clipboard
Copied
It is indeed possible to leave out arguments, just use the value "Type.Missing"
Ie:
DocRef.Export(exportFormat, targetfilename, false, presetObject, Type.Missing, false);
Thanks,
Ruvan
Frontlab.com