Difference between revisions of "Writing Plugins"

From WireCAD Online Help
Jump to: navigation, search
(Getting Started)
 
(31 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{unfinished}} WireCAD '''XLT''' and '''PRO''' provide access to the WireCAD Software Development Kit ('''SDK'''). With the WireCAD SDK you can write code to customize WireCAD to fit your needs. The assumption is that you have a basic understanding of [[Csharp programming syntax|C# programming syntax]] and structure (the examples are in C# but you may use and .NET programming language that you are comfortable with). If you do not understand it don't let that deter you. It is really very easy to understand. Microsoft has tons of examples. Just get on the web.
+
==INTRODUCTION==
  
STUDY THE EXAMPLES in the \WireCAD shared\WireCAD SDK\Examples folder
 
  
If you have WireCAD SDK specific questions post them on the discussion pages here along with as much code as you can and an explanation of what you are trying to do. We will try to help. If you need more help or if you are developing a commercial plugin for WireCAD you may want to consider purchasing SDK assurance. Please call the office for more information. Please note that we cannot take phone support calls for SDK issues unless you are an SDK assurance member.
+
Welcome to the WireCAD SDK examples. These examples show you how to <br>
 +
interact, via your own code, with WireCAD. These examples assume that<br>
 +
you understand the basics of C# programming syntax and structure <br>
 +
(the examples are in C# but you may use any .NET programming language<br>
 +
that you are comfortable with). <br>
 +
If you do not understand it don't let that deter you. It is really<br>
 +
very easy to understand. Microsoft has tons of examples. Just get on<br>
 +
the web. <br>
  
The first place to go with any programming effort is the ubiquitous "Hello World" example in the Basic folder.
+
If you have WireCAD SDK specific questions email support@wirecad.com<br>
 +
along with as much code as you can and an explanation of what you are<br>
 +
trying to do. We will try to help. If you need more help or if you are<br>
 +
developing a commercial plugin for WireCAD you may want to consider<br>
 +
purchasing custom programming services from us.<br>
 +
Please call the office for more information.<br>
  
== Plugin Types ==
 
  
NOTE: there are two types of WireCAD plugin.
+
==Getting Started==
  
#The automatically discovered (AD) plugin that loads silently and may or may not interact with the user.
+
The examples can be found in '''c:\users\public\documents\WireCAD\WireCAD9\WireCAD SDK\'''
#Plugins that require a WireCAD .wpi manifest file that describes where the plugin can be found, how to call it, what icon to display and on which toolbar or menu, etc. Both plugins implement the [[WireCAD.IPlugin]] interface.
+
  
== Plugin File Naming Conventions ==
+
You will want to download a .net ready integrated development environment(IDE)<br>
 +
like Visual Studio for c# or SharpDevelop. Visual Studio has free versions.<br>
 +
SharpDevelop is open source.<br><br>
 +
We recommend the Visual Studio for the ability to attach a debugger to your <br>
 +
running process. Also use the '''WireCADv9TemplateInstaller.vsix''' to install several<br>
 +
starter projects in Visual Studio that you can use from the '''File>New Project''' wizard.<br>
 +
<br>
 +
The first place to go with any programming effort is the ubiquitous<br>
 +
"Hello World" example in the Basic folder.<br>
 +
<br>
 +
NOTE: there are two types of WireCAD plugin. <br>
 +
#The automatically discovered '''(AD)''' plugin that loads silently and may or may not interact with the user.<br>
 +
#Plugins that require a WireCAD .wpi manifest file that describes where the plugin can be found, how to call it, what icon to display and on which toolbar or menu, etc.<br>
  
AD plugins are named YourPluginName.Plugin.Dll and are placed in the ..\WireCADx\bin folder. Standard WireCAD plugins have no naming requirements but must be accompanied by a .wpi file in the ..\WireCADx\bin\plugins folder.
+
Both plugins implement the '''[[WireCAD.IPluginCore]]''' interface.<br>
 +
<br>
 +
'''AD''' plugins are named YourPluginName'''.Plugin.Dll''' and are placed in the: <br>
 +
C:\users\public\documents\WireCAD\WireCAD9\bin folder.  
  
To create a wpi file you can use the utility in [[GUI:Plugin Manager|Plugins>Plugin Manager [New PI Info]]]
+
Standard WireCAD plugins have no naming requirements<br>
 +
but must be accompanied by a '''.wpi''' file in the:<br>
 +
C:\users\public\documents\WireCAD\WireCAD9\Plugins\Active Plugins folder.<br>
 +
<br>
 +
To create a wpi file you can use the utility in '''Plugins>Plugin Manager [New PI Info]''' in WireCAD  <br>
 +
<br>
 +
Take some time to read through the code. The [[WireCAD.IPluginCore]] interface is very simple,<br>
 +
yet you can access most of the WireCAD object model through the [[WireCAD.Workspace Object]] - including drawing,<br>
 +
data access, grids, GUI, reports, etc.<br>
 +
<br>
 +
You can also create your own forms and functions to interact with the<br>
 +
WireCAD objects.<br>
 +
<br>
 +
<br>
  
Take some time to read through the code. The interface is very simple, yet you can access most of the WireCAD object model including drawing, data access, grids, GUI, reports, etc.
+
==THIRD PARTY LIBRARIES==
  
You can also create your own forms and functions to interact with the WireCAD objects.
+
WIRECAD USES THIRD PARTY LIBRARIES THAT MAY REQUIRE YOU TO PURCHASE DEVELOPER<br>
 +
COPIES. PLEASE DO NOT IGNORE THIS STATEMENT. THESE ARE GREAT LIBRARIES AND<br>
 +
IF YOU ARE PLANNING TO DEVELOP A COMMERCIAL PLUGIN FOR WIRECAD YOU WILL WANT<br>
 +
TO HAVE THEM. If you are developing a small project or line of business function<br>
 +
for your own use you may not need to purchase licenses. Here is an example:<br>
 +
If you want your plugin to have the same look and feel, or create a custom form<br>
 +
with the same gridview or treeview as WireCAD you will need<br>
 +
to purchase the Developer Express library. If you are developing a custom form<br>
 +
that needs to show its own drawing engine you will need to purchase the<br>
 +
VectorDraw developer framework. If, on the other hand, you are able to use<br>
 +
the WireCAD baseforms object, are happy with the WinForms controls and can<br>
 +
develop using the WireCAD drawing engine then you can get started without<br>
 +
spending a dime. <br>
  
 +
<br>
 +
<br>
  
 +
==BUILDING YOUR FIRST PLUGIN==
  
== THIRD PARTY LIBRARIES ==
+
STEPS:<br>
 +
#Open your IDE
 +
#Click '''File>Open Project or Solution''' and browse to the basic hello world.csproj project file in the examples\basic\hello world folder
 +
#Click '''Build>Build Solution''' (Ctrl+Shft+B) to build the project.
 +
#Check that the file C:\Users\Public\Documents\WireCAD\WireCAD9\bin\'''helloworld.plugin.dll''' exists.If it does not then you need to check the project build path in the project properties section and point it to the WireCAD bin folder above. If you get any reference errors check Project>Hello World Properties...[Reference Paths] section points to C:\Users\Public\Documents\WireCAD\WireCAD9\bin\. If it does not then modify it and make sure that your reference errors disappear.
 +
#You now need to force WireCAD to load the shiny new plugin. Either relaunch WireCAD (tedious) or click '''Plugins>Plugin Manager ...''' then click the '''[Rescan and Reload All Plugins]''' button. Make sure that the helloworld.plugin appears in the Auto Discovered Plugins list.
 +
#Now enter ''hw'' in the commandline and click '''[Enter]'''. This will launch the command that the plugin registered in its Load() method.
 +
#Make some changes and click '''Build>Build Solution''' (Ctrl+Shft+B) to build the project again. If your changes are outside the load() method you will not need to force a reload. Just call the command again by typing ''hw'' in the commandline and click '''[Enter]'''.<br>
 +
<br>
 +
There you have it. You have just built your first WireCAD plugin. Now go forth and do more!
  
'''WIRECAD USES THIRD PARTY LIBRARIES THAT MAY REQUIRE YOU TO PURCHASE DEVELOPER COPIES'''.<br/>PLEASE DO NOT IGNORE THIS STATEMENT. THESE ARE GREAT LIBRARIES AND IF YOU ARE PLANNING TO DEVELOP A COMMERCIAL PLUGIN FOR WIRECAD YOU WILL WANT TO HAVE THEM. If you are developing a small project or line of business function for your own use you may not need to purchase licenses. Here is an example: If you want your plugin to have the same look and feel, or create a custom form with the same gridview or treeview as WireCAD you will need to purchase the Developer Express library. If you are developing a custom form that needs to show its own drawing engine you will need to purchase the VectorDraw developer framework. If, on the other hand, you are able to use the WireCAD baseforms object, are happy with the WinForms controls and can develop using the WireCAD drawing engine then you can get started without spending a dime.
 
  
  
 +
==DEBUGGING YOUR PLUGIN==
  
== WireCAD 7 APIs ==
+
Invariably you will need to stop the execution of your plugin and examine the variables
 +
and logic structure to figure out why it is not working as you expect.
  
WireCAD7.exe API. This is the API for the main WireCAD executable<br/>[http://www.wirecad.com/api/70/exe/index.html WireCAD7.exe API]
+
The following instructions assume you are using the Visual Studio IDE for C#. Further, that
 +
you have built your project and made sure it is loading in the WireCAD plugin framework by
 +
looking at the loaded plugins list in '''Plugins>Plugin Manager...'''
 +
 
 +
NOTE: The following will work for anything other than the initial Load() method. To debug that
 +
read on.
 +
 
 +
Steps:
 +
#Open your project in the Visual Studio IDE.
 +
#Run WireCAD.
 +
#In VS click '''Debug>Attach to Process...'''
 +
#Select WireCAD9.exe.
 +
#Place a breakpoint in the code where you want to stop execution. Do this by clicking in the gutter of the text editor(very left hand edge. A red dot will appear).
 +
#Execute your command. The debugger will pause at the line and highlight the paused line. In the interface you will find two very helpful tool windows - Locals and Autos. These windows list the variables in play at the time of the breakpoint.
 +
#On the IDE Debug menu you will find commands to continue execution:
 +
##'''Continue''' - runs from the break point until it hits the next breakpoint if any.
 +
##'''Step Into''' - continues execution of the next line. If the next line calls another function you will be stepped into that function.
 +
##'''Step Over''' - continues execution of the next line. If the next line calls another function that function will execute in it entirety and you will step to the next line in the current code block.
 +
 +
While you cannot edit and continue you will be able to understand the changes you need to make
 +
to fix the issue you are having.
 +
8.Stop the debugger. Fix your code. Lather, rinse, repeat.
 +
 +
 
 +
==DEBUGGING THE LOAD() METHOD OF THE IPLUGINCORE INTERFACE==
 +
 
 +
The load method or the HasPermissionToRun methods of the IPluginCore interface require some
 +
special consideration if we are to debug them. The reason for this is that the WireCAD loading
 +
process will call these methods before we have a chance to attach the debugger to the process.
 +
 
 +
This section will outline two approaches:
 +
 
 +
===PAUSE EXECUTION USING MESSAGEBOX===
 +
Place a '''MessageBox.Show("Pause");''' command in the Load or the HasPermissionToRun method.
 +
This modal dialog will pause execution for you to attach the debugger as shown above.<br>
 +
like this:<br>
 +
public void Load(IWorkspace ws)
 +
{
 +
  MessageBox.Show("Pausing plugin load so you can attach the debugger");
 +
  ....... Your code here
 +
}
 +
 
 +
===START WIRECAD IN THE DEBUGGER PROCESS===
 +
The other approach is to start WireCAD in the debugger from your project. While this seams like a
 +
good approach it suffers from a major drawback. When you want to fix your code you must stop the
 +
debugging session. Since WireCAD is running in the same process it will stop as well. Thus requiring
 +
you to start WireCAD every time you want to make a fix.
 +
 
 +
Steps:
 +
#Open your project in the IDE.
 +
#Close WireCAD.
 +
#Open the Project Properties window - '''Project>YourProjectName Properties...'''
 +
#Select the Debug section.
 +
#Select the '''Start External Program''' radio button.
 +
#Browse to the WireCAD9.exe at: C:\Users\Public\Documents\WireCAD\WireCAD9\bin\WireCAD9.exe
 +
#Place your breakpoint.
 +
#Click '''Debug>Start Debugging''' (F5).
 +
This will start the debugging session by launching WireCAD first. As WireCAD loads it will eventually
 +
come to your Load() method and hit your breakpoint.
 +
 
 +
 
 +
 +
When you are finished with your examination close WireCAD and let it shutdown. Ending the debugging
 +
session with the '''Debug>Stop Debugging''' (Shift+F5) acts like Kill Process and will not allow WireCAD
 +
to store session state.
 +
 +
 
 +
 
 +
==ADDITIONAL RESOURCES==
 +
 
 +
C# is the language of choice for developing in WireCAD. There are tons of resources
 +
online to learn this language.
 +
 
 +
For WireCAD specific issues:
 +
www.wirecad.com/wiki
 +
support@wirecad.com
 +
Please don't submit support tickets for SDK issues. Use the support email.
 +
 
 +
Developer Express is the library we use for many of the UI elements. They have
 +
a brilliant web site with documentation and support. If you are going to go
 +
deep on WireCAD development you will probably want to purchase a license.
 +
www.developerexpress.com
 +
 
 +
VectorDraw is the drawing engine we use. While their site is minimal they do offer
 +
registered developers lots of sample code.
 +
www.vdraw.com
  
WireCAD7 Project Database Data Access Layer (DAL)<br/>[http://www.wirecad.com/api/70/projectdal/index.html Project DAL]
 
  
WireCAD7 Global Database Data Access Layer (DAL)<br/>[http://www.wirecad.com/api/70/globaldal/index.html Global Database DAL]
 
  
 
== WireCAD 8 APIs ==
 
== WireCAD 8 APIs ==
  
WireCAD8.exe API. This is the API for the main WireCAD executable<br/>[http://www.wirecad.com/api/80/exe/index.html WireCAD7.exe API]
+
WireCAD8.exe API. This is the API for the main WireCAD executable<br/>[http://www.wirecad.com/api/80/exe/index.html WireCAD8.exe API]
  
 
WireCAD 8 Project Database Data Access Layer (DAL)<br/>[http://www.wirecad.com/api/80/projectdal/index.html Project DAL]
 
WireCAD 8 Project Database Data Access Layer (DAL)<br/>[http://www.wirecad.com/api/80/projectdal/index.html Project DAL]
  
 
WireCAD 8 Global Database Data Access Layer (DAL)<br/>[http://www.wirecad.com/api/80/globaldal/index.html Global Database DAL]
 
WireCAD 8 Global Database Data Access Layer (DAL)<br/>[http://www.wirecad.com/api/80/globaldal/index.html Global Database DAL]
 +
 +
== WireCAD 9 APIs ==
 +
 +
WireCAD9.exe API. This is the API for the main WireCAD executable<br/>[http://www.wirecad.com/api/90/exe/index.html WireCAD9.exe API]
 +
 +
WireCAD 9 Project Database Data Access Layer (DAL)<br/>[http://www.wirecad.com/api/90/projectdal/index.html Project DAL]
 +
 +
WireCAD 9 Global Database Data Access Layer (DAL)<br/>[http://www.wirecad.com/api/90/globaldal/index.html Global Database DAL]

Latest revision as of 19:06, 5 December 2016

INTRODUCTION

Welcome to the WireCAD SDK examples. These examples show you how to
interact, via your own code, with WireCAD. These examples assume that
you understand the basics of C# programming syntax and structure
(the examples are in C# but you may use any .NET programming language
that you are comfortable with).
If you do not understand it don't let that deter you. It is really
very easy to understand. Microsoft has tons of examples. Just get on
the web.

If you have WireCAD SDK specific questions email support@wirecad.com
along with as much code as you can and an explanation of what you are
trying to do. We will try to help. If you need more help or if you are
developing a commercial plugin for WireCAD you may want to consider
purchasing custom programming services from us.
Please call the office for more information.


Getting Started

The examples can be found in c:\users\public\documents\WireCAD\WireCAD9\WireCAD SDK\

You will want to download a .net ready integrated development environment(IDE)
like Visual Studio for c# or SharpDevelop. Visual Studio has free versions.
SharpDevelop is open source.

We recommend the Visual Studio for the ability to attach a debugger to your
running process. Also use the WireCADv9TemplateInstaller.vsix to install several
starter projects in Visual Studio that you can use from the File>New Project wizard.

The first place to go with any programming effort is the ubiquitous
"Hello World" example in the Basic folder.

NOTE: there are two types of WireCAD plugin.

  1. The automatically discovered (AD) plugin that loads silently and may or may not interact with the user.
  2. Plugins that require a WireCAD .wpi manifest file that describes where the plugin can be found, how to call it, what icon to display and on which toolbar or menu, etc.

Both plugins implement the WireCAD.IPluginCore interface.

AD plugins are named YourPluginName.Plugin.Dll and are placed in the:
C:\users\public\documents\WireCAD\WireCAD9\bin folder.

Standard WireCAD plugins have no naming requirements
but must be accompanied by a .wpi file in the:
C:\users\public\documents\WireCAD\WireCAD9\Plugins\Active Plugins folder.

To create a wpi file you can use the utility in Plugins>Plugin Manager [New PI Info] in WireCAD

Take some time to read through the code. The WireCAD.IPluginCore interface is very simple,
yet you can access most of the WireCAD object model through the WireCAD.Workspace Object - including drawing,
data access, grids, GUI, reports, etc.

You can also create your own forms and functions to interact with the
WireCAD objects.


THIRD PARTY LIBRARIES

WIRECAD USES THIRD PARTY LIBRARIES THAT MAY REQUIRE YOU TO PURCHASE DEVELOPER
COPIES. PLEASE DO NOT IGNORE THIS STATEMENT. THESE ARE GREAT LIBRARIES AND
IF YOU ARE PLANNING TO DEVELOP A COMMERCIAL PLUGIN FOR WIRECAD YOU WILL WANT
TO HAVE THEM. If you are developing a small project or line of business function
for your own use you may not need to purchase licenses. Here is an example:
If you want your plugin to have the same look and feel, or create a custom form
with the same gridview or treeview as WireCAD you will need
to purchase the Developer Express library. If you are developing a custom form
that needs to show its own drawing engine you will need to purchase the
VectorDraw developer framework. If, on the other hand, you are able to use
the WireCAD baseforms object, are happy with the WinForms controls and can
develop using the WireCAD drawing engine then you can get started without
spending a dime.



BUILDING YOUR FIRST PLUGIN

STEPS:

  1. Open your IDE
  2. Click File>Open Project or Solution and browse to the basic hello world.csproj project file in the examples\basic\hello world folder
  3. Click Build>Build Solution (Ctrl+Shft+B) to build the project.
  4. Check that the file C:\Users\Public\Documents\WireCAD\WireCAD9\bin\helloworld.plugin.dll exists.If it does not then you need to check the project build path in the project properties section and point it to the WireCAD bin folder above. If you get any reference errors check Project>Hello World Properties...[Reference Paths] section points to C:\Users\Public\Documents\WireCAD\WireCAD9\bin\. If it does not then modify it and make sure that your reference errors disappear.
  5. You now need to force WireCAD to load the shiny new plugin. Either relaunch WireCAD (tedious) or click Plugins>Plugin Manager ... then click the [Rescan and Reload All Plugins] button. Make sure that the helloworld.plugin appears in the Auto Discovered Plugins list.
  6. Now enter hw in the commandline and click [Enter]. This will launch the command that the plugin registered in its Load() method.
  7. Make some changes and click Build>Build Solution (Ctrl+Shft+B) to build the project again. If your changes are outside the load() method you will not need to force a reload. Just call the command again by typing hw in the commandline and click [Enter].


There you have it. You have just built your first WireCAD plugin. Now go forth and do more!


DEBUGGING YOUR PLUGIN

Invariably you will need to stop the execution of your plugin and examine the variables and logic structure to figure out why it is not working as you expect.

The following instructions assume you are using the Visual Studio IDE for C#. Further, that you have built your project and made sure it is loading in the WireCAD plugin framework by looking at the loaded plugins list in Plugins>Plugin Manager...

NOTE: The following will work for anything other than the initial Load() method. To debug that read on.

Steps:

  1. Open your project in the Visual Studio IDE.
  2. Run WireCAD.
  3. In VS click Debug>Attach to Process...
  4. Select WireCAD9.exe.
  5. Place a breakpoint in the code where you want to stop execution. Do this by clicking in the gutter of the text editor(very left hand edge. A red dot will appear).
  6. Execute your command. The debugger will pause at the line and highlight the paused line. In the interface you will find two very helpful tool windows - Locals and Autos. These windows list the variables in play at the time of the breakpoint.
  7. On the IDE Debug menu you will find commands to continue execution:
    1. Continue - runs from the break point until it hits the next breakpoint if any.
    2. Step Into - continues execution of the next line. If the next line calls another function you will be stepped into that function.
    3. Step Over - continues execution of the next line. If the next line calls another function that function will execute in it entirety and you will step to the next line in the current code block.

While you cannot edit and continue you will be able to understand the changes you need to make to fix the issue you are having. 8.Stop the debugger. Fix your code. Lather, rinse, repeat.


DEBUGGING THE LOAD() METHOD OF THE IPLUGINCORE INTERFACE

The load method or the HasPermissionToRun methods of the IPluginCore interface require some special consideration if we are to debug them. The reason for this is that the WireCAD loading process will call these methods before we have a chance to attach the debugger to the process.

This section will outline two approaches:

PAUSE EXECUTION USING MESSAGEBOX

Place a MessageBox.Show("Pause"); command in the Load or the HasPermissionToRun method. This modal dialog will pause execution for you to attach the debugger as shown above.
like this:

public void Load(IWorkspace ws)
{
  MessageBox.Show("Pausing plugin load so you can attach the debugger");
  ....... Your code here
}

START WIRECAD IN THE DEBUGGER PROCESS

The other approach is to start WireCAD in the debugger from your project. While this seams like a good approach it suffers from a major drawback. When you want to fix your code you must stop the debugging session. Since WireCAD is running in the same process it will stop as well. Thus requiring you to start WireCAD every time you want to make a fix.

Steps:

  1. Open your project in the IDE.
  2. Close WireCAD.
  3. Open the Project Properties window - Project>YourProjectName Properties...
  4. Select the Debug section.
  5. Select the Start External Program radio button.
  6. Browse to the WireCAD9.exe at: C:\Users\Public\Documents\WireCAD\WireCAD9\bin\WireCAD9.exe
  7. Place your breakpoint.
  8. Click Debug>Start Debugging (F5).

This will start the debugging session by launching WireCAD first. As WireCAD loads it will eventually come to your Load() method and hit your breakpoint.


When you are finished with your examination close WireCAD and let it shutdown. Ending the debugging session with the Debug>Stop Debugging (Shift+F5) acts like Kill Process and will not allow WireCAD to store session state.


ADDITIONAL RESOURCES

C# is the language of choice for developing in WireCAD. There are tons of resources online to learn this language.

For WireCAD specific issues: www.wirecad.com/wiki support@wirecad.com Please don't submit support tickets for SDK issues. Use the support email.

Developer Express is the library we use for many of the UI elements. They have a brilliant web site with documentation and support. If you are going to go deep on WireCAD development you will probably want to purchase a license. www.developerexpress.com

VectorDraw is the drawing engine we use. While their site is minimal they do offer registered developers lots of sample code. www.vdraw.com


WireCAD 8 APIs

WireCAD8.exe API. This is the API for the main WireCAD executable
WireCAD8.exe API

WireCAD 8 Project Database Data Access Layer (DAL)
Project DAL

WireCAD 8 Global Database Data Access Layer (DAL)
Global Database DAL

WireCAD 9 APIs

WireCAD9.exe API. This is the API for the main WireCAD executable
WireCAD9.exe API

WireCAD 9 Project Database Data Access Layer (DAL)
Project DAL

WireCAD 9 Global Database Data Access Layer (DAL)
Global Database DAL