OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   Macros/Add-ons (http://forum.oberonplace.com/forumdisplay.php?f=21)
-   -   VSTA Anyone? (http://forum.oberonplace.com/showthread.php?t=6985)

thayne 25-05-2010 15:28

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

shelbym 25-05-2010 16:34

Vsta
 
Quote:

Originally Posted by thayne (Post 16556)
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

thayne 27-05-2010 09:17

Quote:

Originally Posted by shelbym (Post 16557)
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

runflacruiser 27-05-2010 11:49

Quote:

Originally Posted by thayne (Post 16570)
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

shelbym 27-05-2010 12:51

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

thayne 27-05-2010 14:43

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.

Yurchick 05-08-2010 03:52

Quote:

Originally Posted by thayne (Post 16575)
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

still 05-01-2011 16:57

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.

thayne 08-02-2011 18:17

Quote:

Originally Posted by still (Post 17618)
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.

helpy 17-04-2011 14:15

Quote:

Originally Posted by thayne (Post 18369)
Quote:

Originally Posted by thayne (Post 18369)
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


All times are GMT -5. The time now is 07:43.

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