Copy link to clipboard
Copied
Is there any documentation anywhere on how to utilize the interop com dll within a c# application?
I can create a grouped item to a layer, and add a text frame to the grouped item using the following code, but I haven't been able to figure out how to set the position for where the grouped item will live.
var decorationLayer = document.Layers["Decoration"];
GroupItem embColorGroupItem = decorationLayer.GroupItems.Add();
TextFrame embColorHeader = embColorGroupItem.TextFrames.Add();
embColorHeader.Contents = "EMBROIDERY COLORS";
embColorHeader.Name = "EMB COLORS";
I can see that GroupItem has a Position element with a { get; set; }, but there doesn't appear to be a way to use it. GroupItem also has "Top" and "Left", but setting those to any value doesn't change the location of the grouped item, which gets created at the very top of the AI File, just off of the edge of the document.
Copy link to clipboard
Copied
It appears that using the .Translate(X,Y) method on the GroupItem after adding at least one TextFrame will set the position.
This is very unintuitive and the coordinate system seems odd to me, I had to set it to (644, -286) to get it in the lower right-hand quadrant.
Copy link to clipboard
Copied
.top &.left position should work
there's also a .position property that takes Array(x, y)
I rarely see C# questions here, must you use C#? is learning Javascript an option for you? there are a lot of resources and everyone here could help you with it.
Copy link to clipboard
Copied
Top and Left do also work, but I could not get the Position property on the COM side to work.
I tried to pass in a List<double> { x, y } but received the error: "Exception has been thrown by the target of an invocation. Point value expected"
embColorGroupItem.Position = new List<double> { xCoord, yCoord };
We can't create an array like Double[25.3, -30.5] since that attempts to create a 2-dimensional array, and the negative value throws an exception.
Some of the Script documentation can translate over to the C# side, but not all unfortunately.
Copy link to clipboard
Copied
Oops, missed the second part of your answer.
Javascript is an option, but we need to create a fully automated solution that pulls data from an API, downloads files, generates templates with the downloaded files, and then re-uploads the finished product to an API.
Javascripting with Adobe, to my knowledge, also requires a user to run the script from the menu, we can also trigger that from the COM/C# code, but w/o documentation on how that works, it would be very trial & error.
It is unfortunate that adobe hasn't invested in creating a headless code solution for automation.
Copy link to clipboard
Copied
I see, there's a doJavascript method in VBA/vbscript. One option would be to send javascript code to illustrator. Check if it also available from C#
it would work like this
yourIllustratorAppReference.doJavascript ("alert (app.name)");
or
yourIllustratorAppReference.doJavascript ("alert (activeDocument.swatches[5].name)");
Copy link to clipboard
Copied
Yes, we can do that with the C# side as well, I only recently discovered it but haven't gone fully down that path as an alternative.
illustratorApp.DoJavaScript("alert (activeDocument.swatches[3].name + ' - ' + activeDocument.swatches[3].color)");