![]() |
#1
|
|||
|
|||
![]()
First, I'm surprised that there are no new posts on VSTA since the release of X5. I've used it a little and have found it much easier than VBA to program with. However, the barrier that is preventing me from really using it is the implementation of an add-in as opposed to simply running a VBA macro.
I understand the process where I compile the C# or VB code into a DLL file and then copy the file into the appropriate directory so that it will run when CorelDRAW starts up. What I haven't figured out is how to run it by a command so it only executes when I want it to. I know there is a way since there are many good add-ins out there but there are no tutorials on how to do it. If you have experience in this area and are willing I (and probably many others) would be very grateful for a little instruction to get started. Thanks in advance Thayne |
#2
|
||||
|
||||
![]() Quote:
-Shelby |
#3
|
|||
|
|||
![]()
As you stated I haven't been able to find any way to implement my code but I am not a programmer. However, I can't believe that no one would have experience with a workaround or some sort of solution (but maybe that is because I am not a programmer).
What I really want to know is if I should continue to look for a solution or stop wasting time but there is absolutely no way to use VSTA code in a reasonable way. And finally, if the latter is the case, What Was Corel Thinking!? Thayne |
#4
|
||||
|
||||
![]() Quote:
-John |
#5
|
||||
|
||||
![]()
Yes I have to agree, this is just the first step. It is great that they have included it so we may begin to get our feet wet and in future versions I am sure it will become much more useful.
-Shelby |
#6
|
|||
|
|||
![]()
I have made some progress towards what I think may be a solution. I will post the code once I get it to where it works properly. The gist of the solution though is that the DLL creates and displays a Window's form with the desired funcitonality (similar to some VBA solutions but it automatically runs at startup instead of by a macro button). The more difficult part is to get the new window to interact with CorelDraw, but it's not impossible. Like I said, I'm not a programmer so I am sure there are better ways of doing this, but it is a start.
|
#7
|
|||
|
|||
![]() Quote:
http://coreldraw.com/blogs/insider/p...coreldraw.aspx |
#8
|
|||
|
|||
![]()
Sorry, my english is bad, so I just show my solution:
1) Main.cs: Code:
using System; using Corel.Interop.CorelDRAW; namespace MyAddin { [System.AddIn.AddIn("My Addin", Version = "1.0", Publisher = "", Description = "")] public partial class Main { private void Main_Startup(object sender, EventArgs e) { ToolboxForm ToolBox = new ToolboxForm(); ToolBox.app = this.app; ToolBox.Show(); } private void Main_Shutdown(object sender, EventArgs e) { } #region VSTA generated code private Corel.Interop.CorelDRAW.Application app = null; private void InternalStartup() { this.Startup += new System.EventHandler(Main_Startup); this.Shutdown += new System.EventHandler(Main_Shutdown); app = (Corel.Interop.CorelDRAW.Application)this.Host; } #endregion } } Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Corel.Interop.CorelDRAW; namespace GritsayAddin { public partial class ToolboxForm : Form { public Corel.Interop.CorelDRAW.Application app = null; public ToolboxForm() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (app != null) { app.ActiveLayer.CreateLineSegment(0, 0, 2, -2); } } } } Form showing up when Corel Draw run. When button pressed - in active layer it draw line. All working, but I dont know how to bind ToolBox.Show(); on custom pannel button. |
#9
|
|||
|
|||
![]()
That is the problem, there isn't a way to do that as far as I know and it relegates VSTA in Corel to useless status until it is corrected by Corel. It is unfortunate since it is so powerful compared to VBA.
|
#10
|
|||
|
|||
![]() Quote:
Here is my example: Code:
using System; using Corel.Interop.CorelDRAW; using Corel.Interop.VGCore; namespace [YourNameSpace] { [System.AddIn.AddIn("TESTC AddIn", Version = "0.1", Publisher = "", Description = "")] public partial class Main { CommandBar cbAddIn; string[] cmdID = new string[10]; CommandBarControl[] ctlBtn = new CommandBarControl[10]; private void Main_Startup(object sender, EventArgs e) { app.Start += new DIDrawApplicationEvents_StartEventHandler(app_Start); app.QueryQuit += new DIDrawApplicationEvents_QueryQuitEventHandler(app_QueryQuit); app.OnUpdatePluginCommand += new DIDrawApplicationEvents_OnUpdatePluginCommandEventHandler(app_OnUpdatePluginCommand); app.OnPluginCommand += new DIDrawApplicationEvents_OnPluginCommandEventHandler(app_OnPluginCommand); UI_Setup(); } private void app_Start() { } private void app_QueryQuit(ref bool Cancel) { UI_Remove(); } private void Main_Shutdown(object sender, EventArgs e) { } public void UI_Setup() { string toolTip; cbAddIn = app.FrameWork.CommandBars.Add("TEST AddIn", cuiBarPosition.cuiBarFloating, true); if (cbAddIn == null) { return; } for (int i = 0; i <= 9; i++) { cmdID[i] = System.Guid.NewGuid().ToString(); if ( app.AddPluginCommand( cmdID[i], "Caption of command " + i.ToString(), "Tooltip of command " + i.ToString() ) == true ) { toolTip = "Tooltip of TestButton " + i.ToString(); ctlBtn[i] = cbAddIn.Controls.AddCustomButton( Corel.Interop.VGCore.UICategories.cdrCmdCategoryPlugins, cmdID[i], 0, true ); if (ctlBtn[i] != null) { ctlBtn[i].Visible = true; ctlBtn[i].ToolTipText = toolTip; } else { System.Windows.Forms.MessageBox.Show("Could not add CommandBarControl: CommandID = " + cmdID[i]); } } else { System.Windows.Forms.MessageBox.Show("Could not add PluginCommand: CommandID = " + cmdID[i]); } } cbAddIn.Visible = true; } public void UI_Remove() { cbAddIn.Delete(); for (int i = 1; i < 10; i++) app.RemovePluginCommand(cmdID[i]); } public void TestButtonX(int nr, string CommandID) { System.Windows.Forms.MessageBox.Show("You pressed button nr. " + nr.ToString() + " with CommandID " + CommandID); } private void app_OnPluginCommand(string CommandID) { for( int i = 0; i<10; i++) { if (cmdID[i] == CommandID) { TestButtonX(i, CommandID); break; } } } private void app_OnUpdatePluginCommand(string CommandID, ref bool Enabled, ref Corel.Interop.CorelDRAW.cdrCommandCheckState CheckState) { for (int i = 0; i < 10; i++) { if (cmdID[i] == CommandID) { Enabled = true; break; } } } #region VSTA generated code private Application app = null; private void InternalStartup() { this.Startup += new System.EventHandler(Main_Startup); this.Shutdown += new System.EventHandler(Main_Shutdown); app = (Application)this.Host; } #endregion } } There are some more application events (DocumentClose, DocumentNew, DocumentOpen, WindowActivate, ...) which you also could use! Hope, that this will help some of you! greetings from Germany, guido Last edited by helpy; 17-04-2011 at 14:17. |
![]() |
Tags |
add-in, addin, addon, tutorial, vsta |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Migrate from VBA to VSTA | thayne | CorelDRAW/Corel DESIGNER VBA | 4 | 11-09-2009 13:58 |
Vsta | DebG | CorelDRAW/Corel DESIGNER VBA | 2 | 18-02-2009 14:59 |