Skip to main content
Participating Frequently
May 17, 2022
質問

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

  • May 17, 2022
  • 返信数 1.
  • 1355 ビュー

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.

 

このトピックへの返信は締め切られました。

返信数 1

Participating Frequently
May 18, 2022

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.

CarlosCanto
Community Expert
Community Expert
May 18, 2022

.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.

Participating Frequently
May 18, 2022

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.