Using Interop.Illustrator In C# .netCore 3.1, unable to set (X,Y) position of added GroupItem

Community Beginner ,
May 17, 2022 May 17, 2022

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.

Andrew22814310roa5_0-1652820480543.png

 

TOPICS
How to , Scripting , SDK

Views

59

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 18, 2022 May 18, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 18, 2022 May 18, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 18, 2022 May 18, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 18, 2022 May 18, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 18, 2022 May 18, 2022

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)");

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 18, 2022 May 18, 2022

Copy link to clipboard

Copied

LATEST

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.

AndrewBancroft00_1-1652890438229.png

 

illustratorApp.DoJavaScript("alert (activeDocument.swatches[3].name + ' - ' + activeDocument.swatches[3].color)");

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines