OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Corel User Forums > CorelDRAW > Macros/Add-ons

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 25-05-2010, 15:28
thayne
Guest
 
Posts: n/a
Default VSTA Anyone?

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
Reply With Quote
  #2  
Old 25-05-2010, 16:34
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Vsta

Quote:
Originally Posted by thayne View Post
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.
And that is the problem, there is no way provided to make icons / shortcut keys to your VSTA code, it only works running at startup. So until this is available I doubt you will see VSTA used much.

-Shelby
Reply With Quote
  #3  
Old 27-05-2010, 09:17
thayne
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by shelbym View Post
And that is the problem, there is no way provided...
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
Reply With Quote
  #4  
Old 27-05-2010, 11:49
runflacruiser's Avatar
runflacruiser runflacruiser is offline
Senior Member
 
Join Date: Jun 2009
Location: Pigeon Forge, TN USA
Posts: 811
Default

Quote:
Originally Posted by thayne View Post
And finally, if the latter is the case, What Was Corel Thinking!?

Thayne
Visual basic is still a great way to go, and will be around for many years to come, but VSTA is the future. They're probably just setting it up just like DRAW9 did with VBA.
-John
Reply With Quote
  #5  
Old 27-05-2010, 12:51
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Vsta

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
Reply With Quote
  #6  
Old 27-05-2010, 14:43
thayne
Guest
 
Posts: n/a
Default

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.
Reply With Quote
  #7  
Old 05-08-2010, 03:52
Yurchick
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by thayne View Post
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.
See here:
http://coreldraw.com/blogs/insider/p...coreldraw.aspx
Reply With Quote
  #8  
Old 05-01-2011, 16:57
still
Guest
 
Posts: n/a
Default

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

    }
}
2) Custom Form Code:

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.
Reply With Quote
  #9  
Old 08-02-2011, 18:17
thayne
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by still View Post
All working, but I dont know how to bind ToolBox.Show(); on custom pannel button.
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.
Reply With Quote
  #10  
Old 17-04-2011, 14:15
helpy
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by thayne View Post
Quote:
Originally Posted by thayne View Post
All working, but I dont know how to bind ToolBox.Show(); on custom pannel button.
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.
I wrote a little addin in VSTA for CorelDRAW X5 (C#), which creates a custom CommandBar with 10 Buttons. There are some problems:
  • You can not run this in Debugger! It only works if you compile it and copy the dll to the AddIn directory.
  • Cleaning up (RemoveUI) does not work in ShutDown Event, so I did it in the QueryQuit Event.

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

    }
}
For now it only uses the same default icon for each button. I will try to change icons later.

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.
Reply With Quote
Reply

Tags
add-in, addin, addon, tutorial, vsta


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
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


All times are GMT -5. The time now is 22:20.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com