Creating an Addon (Docker) for Corel Draw

In Corel Draw, starting from version 17, there is a convenient opportunity to create add-ons not only in VBA, but also in C # VSTA. So let's take advantage of this and bring the dream of a Make Nice button closer .





Disclaimer

For programmers - since 2002 I have been working as a prepress engineer in a printing house. For me, programming is a hobby: both the code and the description are not perfect. Therefore, I will be glad to proofread and criticism.





For printers - I understand that slopes are collected in specialized programs, but in the realities of my city this is not advisable. Circulations are small, but the number of layouts, on the contrary, is large and 95% of layouts are made in CorelDraw.





What you need to make the magic work:

Corel draw





Visual Studio





Visual Studio Tools for Applications (optional if you want to write simple macros)





Basic knowledge of C #





Basic knowledge of WPF









For the convenience of writing, we will use add-ons for Visual Studio from " bonus360 ":





CorelDraw Addons Templates





CorelDraw Addons Packer






Let's run the studio as an administrator, so that when compiling, copy the files to the system folders. Create a new project by choosing “CorelDRAW Docker Addon” as a template. We assign a name, for example “MagicUtilites”.





,   “MagicUtilites”, CorelDraw, . “Done” .





. , Extensions.cs, .





F5 CorelDraw - Window - Dockers . , .






DockerUI.xaml



XAML .





<Grid Margin="0,0,0,0">
	<StackPanel>
		<Button Content="Text Convert to Curves" Height="25" Margin="4" Click="Button_Click"/>
	</StackPanel>
</Grid>
      
      



MVVM ( WPF), . , .






DockerUI.xaml.cs







private corel.Application corelApp;
      
      



corel.Application



, . .





Button_Click



.





, CorelDraw . , .





private void Button_Click(object sender, RoutedEventArgs e)
{
  if (corelApp.ActiveDocument == null)
		return;
}
      
      



ActiveDocument



corel.Application



.





.





private void Button_Click(object sender, RoutedEventArgs e)
{
	if (corelApp.ActiveDocument == null)
		return;

	corelApp.BeginDraw();

	corelApp.EndDraw();
}
      
      



. BeginDraw()



, corel . EndDraw()







. corel .





private void Button_Click(object sender, RoutedEventArgs e)
{
  if (corelApp.ActiveDocument == null)
    return;

  corelApp.BeginDraw();

  foreach (corel.Page page in corelApp.ActiveDocument.Pages)
  {
    foreach (corel.Shape shape in page.Shapes.All())
    {
      if (shape.Type == corel.cdrShapeType.cdrTextShape)
        shape.ConvertToCurves();
    }
  }

  corelApp.EndDraw();
}
      
      







, ConvertToCurves()



, corel .





. “Text Convert to Curves” . corel , PowerClip . 





, Corel Draw .





corel.Shape



corel . Type



corel . corel.Shape



corel , Type



cdrGroupShape



. Shapes



, corel .





corel . Type



cdrBitmapShape



, Bitmap



. Type



cdrGuidelineShape



, Guide







corel – PowerClip . corel PowerClip-, PowerClip



null.





.





corel . 





private void MakeToAllPages()
{
  if (corelApp.ActiveDocument == null)
    return;
  corelApp.BeginDraw();
  foreach (corel.Page page in corelApp.ActiveDocument.Pages)
  {
    MakeToShapeRange(page.Shapes.All());
  }
  corelApp.EndDraw();
}
      
      



MakeToAllPages



.





private void MakeToShapeRange(corel.ShapeRange sr)
{
  foreach (corel.Shape shape in sr)
  {
    if (shape.Type == corel.cdrShapeType.cdrGroupShape)
      MakeToShapeRange(shape.Shapes.All());

    if (shape.PowerClip != null)
      MakeToShapeRange(shape.PowerClip.Shapes.All());

    if (shape.Type == corel.cdrShapeType.cdrTextShape)
      shape.ConvertToCurves();
  }
}
      
      



MakeToShapeRange



corel .





corel , corel . corel PowerClip- , corel . corel , .





private void Button_Click(object sender, RoutedEventArgs e)
{
  MakeToAllPages();
}
      
      



Button_Click



MakeToAllPages



.





. PowerClip.






, , .

<StackPanel>
  <Button Content="Text convert to curves" Height="25" Margin="4" Click="ConvertToCurves"/>
  <Separator Margin="4"/>
  <Button Content="Uniform fill to CMYK" Height="25" Margin="4" Click="UniformFillToCMYK"/>
  <Button Content="Outline fill to CMYK" Height="25" Margin="4" Click="OutlineFillToCMYK"/>
  <Button Content="Fountain fill to CMYK" Height="25" Margin="4" Click="FountainFillToCMYK"/>
  <Separator Margin="4"/>
  <Button Content="Bitmap to CMYK" Height="25" Margin="4" Click="BitmapToCMYK"/>
  <Button Content="Resample Bitmap to 300 dpi" Height="25" Margin="4" Click="ResampleBitmap"/>
</StackPanel>
      
      



.





private void ConvertToCurves(object sender, RoutedEventArgs e){}

private void BitmapToCMYK(object sender, RoutedEventArgs e){}

private void UniformFillToCMYK(object sender, RoutedEventArgs e){}

private void OutlineFillToCMYK(object sender, RoutedEventArgs e){}

private void FountainFillToCMYK(object sender, RoutedEventArgs e){}

private void ResampleBitmap(object sender, RoutedEventArgs e){}
      
      



corel MakeToShapeRange



. , corel . MakeToShapeRange



, .





MakeToAllPages()



MakeToAllPages(Action<corel.Shape> action)



. MakeToShapeRange



. MakeToAllPages



.





private void MakeToAllPages(Action<corel.Shape> action)
{
  if (corelApp.ActiveDocument == null)
    return;
  corelApp.BeginDraw();
  foreach (corel.Page page in corelApp.ActiveDocument.Pages)
  {
    MakeToShapeRange(page.Shapes.All(), action);
  }
  corelApp.EndDraw();
}

private void MakeToShapeRange(corel.ShapeRange sr, Action<corel.Shape> action)
{
  foreach (corel.Shape shape in sr)
  {
    if (shape.Type == corel.cdrShapeType.cdrGroupShape)
      MakeToShapeRange(shape.Shapes.All(), action);

    if (shape.PowerClip != null)
      MakeToShapeRange(shape.PowerClip.Shapes.All(), action);

    action(shape);
  }
}
      
      



.





MakeToAllPages



  .





.





private void ConvertToCurves(object sender, RoutedEventArgs e)
{
  MakeToAllPages((s) =>
  {
    if (s.Type == corel.cdrShapeType.cdrTextShape) //  
      s.ConvertToCurves(); //   
  });
}

private void BitmapToCMYK(object sender, RoutedEventArgs e)
{
  MakeToAllPages((s) =>
  {
    if (s.Type == corel.cdrShapeType.cdrBitmapShape) //  
      if (s.Bitmap.Mode != corel.cdrImageType.cdrCMYKColorImage) //    CMYK
        s.Bitmap.ConvertTo(corel.cdrImageType.cdrCMYKColorImage); //   CMYK
  });
}

private void UniformFillToCMYK(object sender, RoutedEventArgs e)
{
  MakeToAllPages((s) =>
  {
    if (s.CanHaveFill) //     
      if (s.Fill.Type == corel.cdrFillType.cdrUniformFill) //  
        if (s.Fill.UniformColor.Type != corel.cdrColorType.cdrColorCMYK) //    CMYK
          s.Fill.UniformColor.ConvertToCMYK(); //   CMYK
  });
}

private void OutlineFillToCMYK(object sender, RoutedEventArgs e)
{
  MakeToAllPages((s) =>
  {
    if (s.CanHaveOutline) //     
      if (s.Outline.Type == corel.cdrOutlineType.cdrOutline) //  
        if (s.Outline.Color.Type != corel.cdrColorType.cdrColorCMYK) //    CMYK
          s.Outline.Color.ConvertToCMYK(); //   CMYK
  });
}

private void FountainFillToCMYK(object sender, RoutedEventArgs e)
{
  MakeToAllPages((s) =>
  {
    if (s.CanHaveFill) //     
      if (s.Fill.Type == corel.cdrFillType.cdrFountainFill) //  
      {
        foreach (corel.FountainColor c in s.Fill.Fountain.Colors) //     
        {
          if (c.Color.Type != corel.cdrColorType.cdrColorCMYK) //    CMYK
            c.Color.ConvertToCMYK(); //   CMYK
        }
      }
  });
}

private void ResampleBitmap(object sender, RoutedEventArgs e)
{
  MakeToAllPages((s) =>
  {
    int resolution = 300;
    if (s.Type == corel.cdrShapeType.cdrBitmapShape) //  
      if (s.Bitmap.ResolutionX != resolution || s.Bitmap.ResolutionY != resolution) //     
        s.Bitmap.Resample(0, 0, true, resolution, resolution); //    
  });
}
      
      



.






.





In the next article I want to describe how to create a docker to automatically draw cut marks on the descent.






Taking this opportunity, I recommend very cool and free interactive online programming courses from Kontur . I also recommend Pavel Shmachilin 's WPF channel , this is the best I've seen on YouTube on this topic.








All Articles