I draw a yellow square (C=0, M=0, Y=100, K=0) in an empty document, how to define only this color into the variable (cyan=false, magenta=false, yellow=true, black=false) ?
C# code, cmyk based color value 0 to 100, argb based color value 0 to 255
Shape s = corelApp.ActiveSelection; Color color = s.Fill.UniformColor; if (color.IsCMYK) { int c = color.CMYKCyan; int m = color.CMYKMagenta; int y = color.CMYKYellow; int k = color.CMYKBlack; System.Windows.MessageBox.Show(y.ToString()); }
Thanks for the answer, but I mean the definition of color separation in the whole document (As well as "File -> Print -> Color -> Print Separations"), let's say I have 5 yellow squares and 4 magenta squares in my document, how can I find what colors are used in the whole document and write finding color into the variables (cyan=false, magenta=true, yellow=true, black=false) without sorting of all shapes?
First I add reference to the "CorelDRAW 17.6 Type Library" use Visual Studio interface.
Then I initialized "Corel" variable with this code:
public CorelDRAW.Application Corel;
Corel = new CorelDRAW.Application();
And if I try to write code with "Corel" variable I get a hints:
Did I do it right?
this is your problem, you cannot create a new application object, you need use the object from running instance of coredraw, if you is building a Addon or VSTA macro you can overrride the main entry of your addon or macro passing application object by reference.
For exemple
public partial class ControlUI : UserControl { private Corel.Interop.VGCore.Application corelApp; public ControlUI(Corel.Interop.VGCore.Application app) { this.corelApp = app; InitializeComponent(); }
}
This is my code with namespaces.. I try to use the object from running instance of coredraw, following example above, but i got mistakes of compilations. How do I change the code, according with your advice?
using System;using System.Windows.Forms;
namespace WindowsFormsApplication1{ public partial class Form1 : Form { public CorelDRAW.Application Corel; public Form1() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) { Corel = new CorelDRAW.Application();
for (int i = 1; i <= Corel.ActiveDocument.PrintSettings.Separations.Plates.Count; i++) { bool plates = Corel.ActiveDocument.PrintSettings.Separations.Plates[i].Enabled; MessageBox.Show(Convert.ToString(plates)); } } }}
For you get the object from running instance is more complicated, you will need use the ROT, running object table, you can take a look in this post http://adndevblog.typepad.com/autocad/2013/12/accessing-com-applications-from-the-running-object-table.html.
In case my code, i use addon model, is more simple, but don't works if you need attach your standalone app in corel com object, in this case you will need use the ROT.
Thanks's for the answers, I will read about ROT. But one thing is strange - why anothers functions work perfectly, such as moving, resizing objects, counting the number of shapes in the document, etc.. Use this code:
Corel.ActiveDocument.ActivePage.Shapes.Count
I get correct value, and if I add some shapes in the document I get correct value too. What is the difference between Shapes.Count and Plates[i].Enabled vars ? If the namespace model will be wrong in my case with Plates[i].Enabled vars, it must be wrong in all other vars, or I missed something?