Hello all,I am trying to write a macro/script/plugin for CorelDRAW. My current setup is simple VSTA script, that serves as wrapper for .dll (class library), which contains most of the actual script logic.This setup works well enough, however the only way I am able to launch it, is through the scripts window, which is really not ideal. I tried adding a GUI button to the workspace (through AppUI.xslt and UserUI.xslt), which I could not get to work - the button is present but clicking it does not do anything. I also tried commands menu under tools->options->customization, but that only lists VBA scripts for me. I cannot even assign shortcut to the VSTA script.I also found that it should be possible to add interface elements directly in VSTA code, but that seems messy and I could not get it to work anyways.What is the best aproach to add GUI elements to easily launch the VSTA script? I know that this is rather basic question, however I cannot find any relevant documentation.Thanks in advance
If you need to launch your script from the workspace (buttons, menus, or shortcuts), the recommended approach is to create an Addon instead of running it as a pure VSTA script.
CorelDRAW supports UI integration through XSLT (AppUI.xslt and UserUI.xslt) combined with a COM DataSource exposed by your .NET assembly. The COM DataSource acts as the "bridge" between your UI element (button/menu) and your code.
Using Addon was actually the first thing I tried, unfortunately I could not get it to work, so I ended up with VSTA wrapper for now.Do you have some simple full example by any chance, that would help me get the addon working? I tried implementing IVGAppPlugin interface:using System;using System.Runtime.InteropServices;using VGCore;[ComVisible(true)][Guid("a4b9c7f0-fd29-4fe5-a04d-40d9398deb74")][ProgId("HelloPlugin.HelloPlugin")][ClassInterface(ClassInterfaceType.None)]public class HelloPlugin : IVGAppPlugin{ private Application app; public HelloPlugin() { } public void OnLoad(Application Application) { app = Application; } public void OnUnload() { } public void StartSession() { } public void StopSession() { } public void Hello() { app.FrameWork.ShowMessageBox("Hello World"); }}I then tried invoking the hello function through a button, which I defined with XSLT files - I used example from documentation. Button shows up, but clicking it does nothing - the dynamic command is HelloPlugin.HelloPlugin.Hello.Any help would be greatly appriciated.
using System;
using System.Runtime.InteropServices;
using VGCore;
[ComVisible(true)]
[Guid("a4b9c7f0-fd29-4fe5-a04d-40d9398deb74")]
[ProgId("HelloPlugin.HelloPlugin")]
[ClassInterface(ClassInterfaceType.None)]
public class HelloPlugin : IVGAppPlugin
{
private Application app;
public HelloPlugin() { }
public void OnLoad(Application Application)
app = Application;
}
public void OnUnload() { }
public void StartSession() { }
public void StopSession() { }
public void Hello()
app.FrameWork.ShowMessageBox("Hello World");
when using a COM object implemented in .NET, the host (Corel) does not automatically create the object by CLSID like it does with native C++ COM objects (which are instantiated internally using CoCreateInstance). Because of that, you need to manually create the .NET COM object from your code (for example, inside a WpfHost) and then expose its properties and methods to the Corel UI.Exemple: github.com/.../Rename-Shape-CorelDraw-Addons-Context-Menu-Command
CoCreateInstance
WpfHost