Вы находитесь на странице: 1из 74

Customising Delcam Products With VB.

NET
Contents
Page
1.

Introduction

2.

Installing the PowerSolutionDOTNetOLE Library

Requirements
What is the .NET Framework?
Installing PowerSolutionDOTNetOLE

Accessing Help
3.

4.

Getting Started With The PowerSolutionDOTNetOLE Library

Adding a Reference to PowerSolutionDOTNetOLE

Fixing a Broken Reference

Upgrading the PowerSolutionDOTNetOLE Library

Accessing PowerSolutionDOTNetOLE Classes

Working With PowerMILL the clsPowerMILLOLE Class

Introduction

5.

6.

7.

PowerMILL Tutorial 1

PowerMILL Tutorial 2

22

Working With PowerSHAPE the clsPowerSHAPEOLE Class

31

Introduction

31

Tutorial 1 Basic Automation of PowerSHAPE

32

Tutorial 2 Simplifying You Code With the clsPoint3D Class

38

Tutorial 3 Working With PowerSHAPE Entities

45

Further Examples

51

Working With INI Files and the Registry

52

Ini Files

52

The Registry

54

Working with CopyCAD the clsCopyCADOLE Class

55

Connecting to CopyCAD
Executing Macro Commands
Executing Macro Commands And Getting Command Window
Information
8.

9.

10.

Multi-Application Interfaces

56

Resizing an Application

57

Showing Multiple Applications

58

PowerSHAPE OLE Methods

62

Accessing the OLE Methods

62

Connecting to a PSMODEL

63

The Composite ID

63

Creating Wireframe Entities

64

Creating Solid Entities

67

Solid Booleans

68

Summary

69

Deploying your VB.NET Applications

PowerSolution Automation
From VB6 To VB.NET

56

Showing an Application in a VB.NET Form

70

Adding an Installation Project

70

Customising the Installation

72

Building the Installation

74

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 1 of 74

1. Introduction

1.1. Overview
This manual is intended for those who are already experienced with VB.NET programming, or for those with
experience with VB6 looking to switch over to VB.NET.
This documentation does not cover the basics of working with VB.NET and the VB.NET development
environment. Where necessary, refer to the VB.NET Basic training manual for more details.
The tutorial is based on the new set of DLL libraries, called PowerSolutionDOTNetOLE, which replaces the
previous ActiveX controls PowerSolutionOLE.ocx.
The PowerSolutionDOTNetOLE library can be used within any .NET programming language (e.g. C#.NET,
VB.NET), but cannot be used with other programming languages not based on the .NET Framework, e.g.
VB6.
The scope of this manual is limited to showing the use of these libraries in VB.NET only.
The following chapters cover the use of these libraries to automate PowerMILL and PowerSHAPE and cover
some of the common tasks often required when developing applications to run alongside Delcam products.
Useful tips on VB.NET programming language are also included, and are identified within frames like as
shown below.

VB.NET Top Tip #1

1.2. What is the PowerSolutionDOTNetOLE Library?


The PowerSolutionDOTNetOLE library is a DLL that gives extended functionality to .NET projects, providing
a more direct and user friendly method of developing applications to work with PowerMILL, PowerSHAPE
and CopyCAD.
The library also contains additional objects to help with common programming steps often used when
developing solutions based around Delcam products, such as working with 3D coordinates, working with
the registry and INI files, and working with temporary files.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 2 of 74

2. Installing the PowerSolutionDOTNetOLE Library

2.1. Requirements
The PowerSolutionDOTNetOLE library can be used for developing within any .NET programming language.
All current versions of VB.NET and Visual Studio .NET are supported.
To develop applications using these libraries, all current release versions of VB.NET or Visual Studio .NET
are supported.
However the libraries are supported only by the Microsoft .NET Framework v1.1 and above.
When deploying applications that use these libraries, the .NET Framework v1.1 is required on the PCs that
will run the application too.

2.2. What is the .NET Framework?


The .NET Framework is a collection of tools and utilities required to execute a .NET application. Similar in
principal to the runtime DLL required to run VB6 applications, but on a much larger scale.
And where in the past with VB6 you would have to distribute many DLLs or OCXs for the different controls
your application used, and ensure the correct version is installed, much of this is now covered in the .NET
framework.
Information on how to check what version of the .NET framework you have installed, and how to download
and install the latest version can found at
http://msdn.microsoft.com/netframework/downloads/framework1_1
The same princpal applies to any applications you may develop using the PowerSolutionDOTNetOLE library,
where the client PC must have these libraries installed.
The Deploying Your Application section explains how to handle this in more detail.

2.3. Installing PowerSolutionDOTNetOLE


The latest version of the PowerSolutionDOTNetOLE library installation is available from the main Delcam
web-site. Updates to the library will be posted there, so check regularly for any new versions.

To download the latest version, browse to


http://www.delcam.com/vb/DOTNet/Introduction.htm

And click on the link to download the class libraries.

Unzip the downloaded file to a temporary folder.

Double click the Setup.Exe

Follow the instructions to complete the installation.

2.4. Accessing Help


Documentation provided with the library can be accessed via the short-cut menus
START Programs Delcam PowerSolutionDOTNetOLE

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 3 of 74

3. Getting Started With The PowerSolutionDOTNetOLE Library

3.1. Adding a Reference to PowerSolutionDOTNetOLE


First create a new VB.NET project (see the Basic VB.NET manual for details on creating a new project).
Within the development environment, you should see the Solution
Explorer frame as shown. If it is not displayed, show it by selecting
from the menus, View Solution Explorer (or click CTRL+SHIFT+L).

Right click on the References node and select, Add


Reference.

This form is used to link to external controls,


libraries, etc. similar to the Add Components
form in VB6 where you select OCXs to
integrate in your application.
Click the

button.

Now browse to the location where the


PowerSolutionDOTNetOLE library is installed
(e.g. by default it will be C:\Program
Files\Delcam PLC\PowerSolutionDOTNetOLE
API Classes).
Select the file PowerSolutionDOTNetOLE.dll
and click Open.
Click OK to accept the references.
If you expand the References node you will see the new reference to
PowerSolutionDOTNetOLE that has been created.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 4 of 74

Select the PowerSolutionDOTNetOLE reference in


the explorer and look at the properties window
(Click F4 if it is not visible).
Ensure the Copy Local property is set to TRUE. It is
set to true by default, but it is important to point out
that it should not be changed.
If set to True, a local copy of the DLL will be stored
with your project. This means that the version of
the DLL you have installed at the time of building
your application will be distributed with your
application. This ensures you do not get any
compatability problems, missing DLL problems, or
un-registered DLL problems often seen with VB6.

3.2. Fixing a Broken Reference


The information regarding the reference to the library is stored with the project. If this reference is broken,
you will not be able to compile your project and the task manager will show that your code cannot find the
reference to the library.
This can occur if the DLL is has been deleted.
A broken reference can be identified in the explorer and will appear as
shown.

To fix the problem, remove the reference from your


project by Right Clicking the PowerSolutionDOTNetOLE
node, and selecting Remove.
Then follow the steps in the section for Adding a
Reference to PowerSolutionDOTNetOLE above.

3.3. Upgrading the PowerSolutionDOTNetOLE Library


Because your application will have a local copy of the DLL alongside the executable, the version that was
installed at the time of adding the reference to your VB.NET project will be used. Installing an updated
version of the library will have no immediate effect on your existing applications. They will run as normal,
using the older version of the DLL. If you wish to use functionality in a new version of the DLL, all you need
to do is open your VB.NET application and work with it as normal. The reference will automatically update
to use the new DLL, and a new Local Copy of the DLL made with your executable.

3.4. Accessing PowerSolutionDOTNetOLE Classes


The first difference you will see between the PowerSolutionOLE ActiveX control used in VB6 and the
PowerSolutionDOTNetOLE library, is how you access the functionality.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 5 of 74

In VB6, after adding the reference to the ActiveX control to your project, you would add controls to your
form depending upon what product you wish to connect to. The disadvantage of this is that when you work
with multiple forms, you have to add the object to every form, and handle the OLE connections
independantly on each form. This also made it tedious to use the OLE connection objects from within purecode, such as Modules or Classes.
The PowerSolutiontDOTNetOLE classes which allow you to connect to each product are now accessed
directly from within your code. In addition, the classes are Shared, which means you can make an OLE
connection to PowerMILL for example, any from then onwards, any other Form, Class or Module will
automatically use the same OLE connection.
To use any of the classes, you can reference the full Namespace each time, e.g.
From the Design view of the main form in your application, double click the title bar. This will take you
automatically to the Form_Load event source code.
If you type:
PowerSolutionDOTNetOle
Then press the . key, the list of available classes, etc. will be displayed, e.g

So for example to connect to PowerMILL and execute a macro command, you may use

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


MyBase.Load
PowerSolutionDOTNetOLE.clsPowerMILLOLE.Connect()
PowerSolutionDOTNetOLE.clsPowerMILLOLE.Execute("CREATE TOOL ; BALLNOSED")
End Sub

This however could mean a lot of typing, and make your source code more difficult to read. You can
therefore create a SHORT-CUT to any particular class by using the IMPORTS statement.
On the very first line of source code for any Form, Class or Module, you can setup these short-cuts.
e.g.

Imports PMILL = PowerSolutionDOTNetOLE.clsPowerMILLOLE


Imports PSHAPE = PowerSolutionDOTNetOLE.clsPowerSHAPEOLE

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 6 of 74

You can then access the classes directly using the short-cut you define.
e.g.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


MyBase.Load
PMILL.Connect()
PMILL.Execute("CREATE TOOL ; BALLNOSED")
End Sub

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 7 of 74

4. Working With PowerMILL the clsPowerMILLOLE Class

4.1. Introduction
The clsPowerMILLOLE class allows you to connect and work directly with PowerMILL.
A summary of the functionality available in the class is listed in the table below.
The use of many of these functions is covered in the following tutorials, as indicated in the table below. For
information on functions not covered in the following tutorials, see the on-line help provided as part of the
PowerSolutionDOTNetOLE installation.

Name
GUIDisplayed
IsConnected
Visible
CloseOLEConnections
Connect
ConnectToNew
DialogsOff
DialogsOn
DoesGroupExistInInfoList

Execute
ExecuteEx
GetActiveEntityName
GetEntityList
GetEntityParameterInfo

GetEntitySize

GetLastCreatedEntityName
ParseParameterInfoForSetting

SetWindowState
StartAndConnectToPowerMILL
Version

PowerSolution Automation
From VB6 To VB.NET

clsPowerMILLOLE Class Members


Description
Used to hide/show the menus, toolbars, etc. in PowerMILL
Used to check wether an OLE connection has been made to
PowerMILL
Sets wether the PowerMILL application window is visible or
not
Disconnects the OLE link to PowerMILL
Creates the OLE link to PowerMILL
Creates a new OLE instance of PowerMILL, regardless of
wether PowerMILL is already running
Turns off the popup dialog messages
Turns on the popup dialog message
Used to check if a group of settings exist within the list of
parameter information extracted from an entity in the
current project
Executes one or more macro commands
Executes a macro command and returns the results printed
to the command window
Returns the name of the active entity for the type of entity
you specify
Returns information on the list of entities for the type of
entity you specify
Returns an array of parameters stored for the specific
entity specified. Used in conjunction with the
DoesGroupExistInInfoList and
ParseParameterInfoForSetting functions, to extract specific
parameters for an entity
Returns the min/max sizes of any entity of the type
specified (excluding tools, groups, stockmodel, workplane
and ncprogram)
Returns the name of the last entity in the list, for the entity
type specified
Searches through the array extracted using the
GetEntityParameterInfo for the specified group and setting,
and returns the value in the correct data type.
Sets wether the PowerMILL application window is
minimised, maximised, etc.
Connects to PowerMILL if its already running, and if not,
automatically start a new session and connect to that.
Returns the version number of the session of PowerMILL
connected to

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

More
Info.
Tutorial 2

Tutorial 2

Tutorial 1
Tutorial 2
Tutorial 1
Tutorial 1
Tutorial 2

Tutorial 1
Tutorial 1
Tutorial 1
Tutorial 1
Tutorial 2

Tutorial 1

Tutorial 2

Tutorial 2

Print Date: 11/07/2005


Page 8 of 74

4.2. PowerMILL Tutorial 1


This PowerMILL tutorial will lead you through creating a utility to take a contour toolpath, move it to the top
of the block or model, then copy it multiple times down to the bottom of the block or model, or a specified
distance.
The completed project is available from the Examples\PowerMILL_Tutorial_1a\ directory.
The methods covered in this tutorial include: Connect, Execute, ExecuteEx, DialogsOff, DialogsOn,
GetEntityList, GetActiveEntityName, and GetEntitySize.
A sample PowerMILL project to use when testing the application is available from the Examples\ PowerMILL
Tutorial 1 Test Project directory.
Open this, or a similar project in PowerMILL to help test your application.
4.2.1. Setting up the User Interface
This first section involves setting up the user interface, starting the connection to PowerMILL, and
Start a new Windows Application VB.NET project, and add the reference to the PowerSolutionDOTNetOLE
library.
In the Form Designer view, setup the interface as shown below, changing the specific properties of each
control as shown

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 9 of 74

View the code for your applications main form by right clicking the
form node in the Solution Explorer, and selecting the View Code
menu.

Setup the short-cut to the clsPowerMILL class using the IMPORTS statement at the top of the code

Imports PowerSolutionDOTNetOLE.clsPowerMILLOLE
Imports PMILL = PowerSolutionDOTNetOLE.clsPowerMILLOLE
Public Class Form1
Inherits System.Windows.Forms.Form
Windows Form Designer generated code
End Class

4.2.2. Connecting to PowerMILL the Connect Method


The Connect method is used to setup the OLE connection with an application.
The use of this method is identical for the clsPowerMILL, clsPowerSHAPE and clsCopyCAD classes.
It must be called before any other operations can be performed.
The method will also return True or False, depending upon wether the OLE connection was made
successfully. In VB6, you would have to attempt to Connect, then check the connnection state afterwards.
Here you can do it with a single line.
Bring up the Click event source code for the Apply command button, and add the following to check the OLE
connection and warn the user if necessary

Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdApply.Click
'Setup the OLE connection and check it
If PMILL.Connect = False Then
'Warn the user
MsgBox("Ensure PowerMILL is running.")
'Exit the sub routine
Return
End If
End Sub

Note that every time the Apply button is clicked, the Connect method will be used. This will not cause
problems, if an OLE connection already exists, calling the Connect method will simply re-use this connection
automatically.
Note: The full listing for the finished cmdApply_Click event can be found in the final section for this tutorial.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 10 of 74

4.2.3. Executing Commands the Execute Method


This method is used to execute macro commands within an application in the same way the Execute
method worked with the VB6 Active X control. The use of this method is also identical for the
clsPowerMILL, clsPowerSHAPE and clsCopyCAD classes.
You can execute single macro commands using this method, e.g

PMILL.Execute("EDIT BLOCKTYPE LIMITS")


PMILL.Execute("EDIT BLOCK RESETLIMIT 0")
PMILL.Execute("EDIT BLOCK RESET")

An enhancement over the VB6 method, is you can group macro commands together, using the Execute
method with a list of strings in the same line. The following will execute the same commands as above

PMILL.Execute("EDIT BLOCKTYPE LIMITS", "EDIT BLOCK RESETLIMIT 0", "EDIT BLOCK RESET")

4.2.4. Executing Command and Retrieving Information the ExecuteEx Method


This method is identical to the VB6 method, and is used to execute a single macro command, and return
any information printed to the command window.
e.g.
Dim Toolpaths As String
Toolpaths = PMILL.ExecuteEx("PRINT ENTITY TOOLPATH")

Care should be taken since some macro commands, rather than printing to the command window by
default, will raise a popup window. To avoid this, you should first turn off dialog messages, which will force
all information to be directed to the command window.
This is achieved using the DialogsOff method. E.g.

Dim ToolpathSize As String


PMILL.DialogsOff()
ToolpathSize = PMILL.ExecuteEx("SIZE TOOLPATH 'Orig Toolpath'")
PMILL.DialogsOn()

Note that we use the DialogsOn method to turn dialog message back on again. This is necessary so that
when the user works with PowerMILL manually, he will see any warning messages.

Declaring and Initialising Variables


A feature of VB.NET is that you can now declare a variable and assign its value in a single line of
code. E.g.
Dim Toolpaths As String = PMILL.ExecuteEx("PRINT ENTITY TOOLPATH")

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 11 of 74

4.2.5. Getting the Name of the Active Entity GetActiveEntityName method


This method is used to find the name of the active entity for a particular entity type. It returns a string
containing the name of the entity. You use the same method for all entity types, but supply the parameter
to specify which entity type to check.
Add the following to the cmdApply click event source code.

Dim ActiveToolpath As String = PMILL.GetActiveEntityName(enumPowerMILLEntityType.pmToolpath)

After you typed PMILL.GetActiveEntityName( you should have seen the list of options you can use to
specify the type of entity to work with, e.g.

The same list of entity types is used for other methods that we will cover later.
If no entity of the type specified is active or no entities exist, the string returned will be empty. Therefore
you can use this method to store the name of the active entity, and also to check if an entity is active or
not. Add the following

'Check a toolpath is active


If ActiveToolpath = "" Then
'Warn the user and exit the sub routine if no toolpath is active
MsgBox("Ensure a toolpath is activated.")
Return
End If

Test your application at any time by running it using the F5 key.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 12 of 74

The Return Statement


Another change in VB.NET is the Return statement. This is used to either jump immediately out of a
sub routine (like Exit Sub), and also to set the value that is returned by a function.
In VB6, you had to assign the value to return using the name of the function e.g.
Function AddNumber(A As Double, B As Double) As Integer
Dim Result As Double
Result = A + B
AddNumber = Result
End Function
In VB.NET, you can simply use the return statement, e.g.
Function AddNumber(A As Double, B As Double) As Integer
Return (A + B)
End Function

4.2.6. Retreiving Entity Size Information the GetEntitySize method


This method is used to retrieve the min/max size of a toolpath, boundary, pattern, block, featureset or
model.
You use the same method for all entity types, but similar to the GetActiveEntityName method, specify what
entity type to work with.
As well as the entity type, you should specify the name of the entity (or an empty string if sizing the block
or model), and also give 6 variables which will be used to store the size information.
e.g.

Dim Xmin, Xmax, Ymin, Ymax, Zmin, Zmax As Double


PMILL.GetEntitySize(enumPowerMILLEntityType.pmPattern, "1", Xmin, Xmax, Ymin, Ymax, Zmin,
Zmax)

The GetEntitySize method will also return True or False, depending upon wether the entity being sized
exists. You can therefore use this method to determine if a block or model exists, which you will see below.
In our application, we first need to find the min/max z for the active toolpath to determine how far we need
to move it to the start point. Add the following to the Apply buttons click event

'Variables to store toolpath min and max z


Dim TP_Xmin, TP_Xmax, TP_Ymin, TP_Ymax, TP_Zmin, TP_Zmax As Double
'Get the toolpath extents.
'If the active toolpath has not been calculated (i.e. only batched),
'we can detect this
'because the GetEntitySize method will return False
If PMILL.GetEntitySize(enumPowerMILLEntityType.pmToolpath, ActiveToolpath, _
TP_Xmin, TP_Xmax, TP_Ymin, TP_Ymax, TP_Zmin, TP_Zmax) = False Then
MsgBox("The active toolpath has not been calculated.")
Return
End If

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 13 of 74

Here we are using the name of the active toolpath we retrieved earlier, and storing the extents in the 6
Double variables.

Declaring Multiple Variables In One Line


In VB6, you could declare multiple variables in a single line, but had to specify the variable type with
each variable, e.g.
Dim A As Double, B As Double, C As Double
In VB.NET you can simply put the variable type at the end of the statement, and all variables listed
will use that type, e.g.
Dim A, B, C, D As Double

Next, we need to store the block size if the user has selected to start or end the toolpath at the top or
bottom of the block. And likewise if the user has selected to use the model extents. Add the following to
the Apply buttons click event

'Variables we'll store the start and end coordinate of the toolpath to create
Dim StartZ, EndZ As Double
'If either the start or end of the tooplath should use the Block, we get its size...
If optStartBlock.Checked = True Or optEndBlock.Checked = True Then
'Variables to store block size
Dim Blk_XMin, Blk_XMax, Blk_YMin, Blk_YMax, Blk_ZMin, Blk_ZMax As Double
'Get the block size, checking that a block is defined at the same time
'Note we use an empty string as the entity name
If PMILL.GetEntitySize(enumPowerMILLEntityType.pmBlock, "", _
Blk_XMin, Blk_XMax, Blk_YMin, Blk_YMax, Blk_ZMin, Blk_ZMax) = False Then
'Warn the user and exit if no block is defined
MsgBox("No block is currently defined.")
Return
End If
'Store whichever extents we need to use for the new toolpath
If optStartBlock.Checked = True Then
StartZ = Blk_ZMax
End If
If optEndBlock.Checked = True Then
EndZ = Blk_ZMin
End If
End If
'If either the start or end of the toolpath should use the Model, we get its size...
If optStartModel.Checked = True Or optEndModel.Checked = True Then
'Variables to store Model size
Dim Mdl_XMin, Mdl_XMax, Mdl_YMin, Mdl_YMax, Mdl_ZMin, Mdl_ZMax As Double
'Get the Model size, checking that a Model is defined at the same time
If PMILL.GetEntitySize(enumPowerMILLEntityType.pmModel, "", _
Mdl_XMin, Mdl_XMax, Mdl_YMin, Mdl_YMax, Mdl_ZMin, Mdl_ZMax) = False Then
'Warn the user and exit if no Model is defined
MsgBox("No Model is currently defined.")
Return
End If
'Store whichever extents we need to use for the new toolpath
If optStartModel.Checked = True Then
StartZ = Mdl_ZMax
End If
If optEndModel.Checked = True Then
EndZ = Mdl_ZMin

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 14 of 74

End If
End If
'If the user has specified to use a distance from the top,
'calculate the bottom position...
If optEndDistance.Checked = True Then
EndZ = StartZ - CDbl(txtDistance.Text)
End If

Note we use the CDbl() VB.NET function above to convert the value in the textbox to a Double variable
type.
We now know where the toolpath is currently positioned, where the new toolpath should start from, and
where it should end.
We are

now ready to add the commands to build the new toolpath. The steps involved are
Store the current list of toolpaths in the project
Move the toolpath from its current position to the required start point
Make multiple copies of the toolpath down Z using the required stepdown, until we reach the
required bottom point.
Extract the new list of toolpaths in the project and determine which are the newly transformed
toolpaths.
Append all the toolpaths together

4.2.7. Extracting the list of entities in the PowerMILL explorer the GetEntityList method
This method is used to extract the list information of a particular entity type.
This is similar to the GetToolpathList, GetPatternList and GetWorkplaneList methods in the VB6 ActiveX
control, except that all entity types are now supported (except for the block).
This method is used for all entity types, with you specifying the entity type to work with. You should also
specify 3 variables which will hold the number of entities found, an array of names of the entities, and the
index of the entity in the array that is the active entity.
e.g.

Dim Num As Integer, Names() As String, Active As Integer


PMILL.GetEntityList(enumPowerMILLEntityType.pmToolpath, Num, Names, Active)
MsgBox("The active toolpath is called '" & Names(Active) & "'")

We can now use this to store the names of the toolpaths in the current project before we start transforming
the active toolpath. Well use it again towards the end to get the new list of toolpaths.
Add the following the cmdApply_Click event.

Dim Orig_Num As Integer, Orig_Names() As String, Orig_Active As Integer


PMILL.GetEntityList(enumPowerMILLEntityType.pmToolpath, Orig_Num, Orig_Names, Orig_Active)

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 15 of 74

Changes To Data Types And Arrays

The declaration of certain variable types has changed between VB6 and VB.NET. The Integer type in
VB6 is now the Short type in VB.NET (values -32,768 through 32,767). The Long type in VB6 is now
the Integer type in VB.NET (values -2,147,483,648 through 2,147,483,647).
e.g.
In VB6:
In VB.NET is now:

Dim A As Integer
Dim A As Short

In VB6:
In VB.NET is now:

Dim B As Long
Dim A As Integer

The way arrays work now have also changed. In VB6 arrays could be bound between any specified
limits, whereas in VB.NET, arrays are ALWAYS bound from 0.
e.g.
In VB6:
Dim C(1 To 10) As Integer
Would give you 10 values in an array from C(1) up to C(10).
In VB.NET this is invalid, and you can only specify the upper bound.
e.g.
In VB.NET:
Dim C(9) As Integer
Gives you 10 values in an array from C(0) to C(9).

4.2.8. Transforming the Toolpath


We can now add the code necessary to send the macro commands to transform the toolpath.
First we need to transform the active toolpath to the start position. Add the following code

'We first move the toolpath up in Z so that it lies on the required start position...
Dim StartZMove As Double = StartZ - TP_Zmin
PMILL.Execute("EDIT TOOLPATH TRANSFORM POINTX 0")
PMILL.Execute("EDIT TOOLPATH TRANSFORM POINTY 0")
PMILL.Execute("EDIT TOOLPATH TRANSFORM POINTZ " & StartZMove.ToString("0.###"))
PMILL.Execute("EDIT TOOLPATH TRANSFORM DELETE N")
PMILL.Execute("PROCESS TPXFORM")

Notice the use of StartZMove.ToString above. It is necessary to convert numbers to strings when being
sent as part of a macro command. This statement converts the real number offset required to move the
toolpath to the start position, to a string to 3 decimal places.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 16 of 74

Variable Types As Classes

One major improvement with VB.NET is how variable types are now actually classes. Which means
you can access special functions that work with that particular variable type.

Where in VB6 you had to know which string handling function to use, and pass in the variable to work
with, in VB.NET you can access these functions directly from the variable.
For example, in VB6 to convert a real number to a string, you could use the Format function, e.g.
Dim A As Double
A =10 / 3
Msgbox Format(A, 0.######)
In VB.NET, you can use the ToString function available in the String variable type class, e.g.
Dim A As Double = 10 / 3
Msgbox A.ToString(0.######)
When you hit the . symbol after the variable name, the list of available functions is seen.
This principal applies to all variables and objects in VB.NET, and worth looking into further as it can
significantly speed up your software development.

We can now loop through transforming of the toolpath down in Z until we reach the required bottom
position. Add the following code
'Extract the stepdown from the form, removing the negative sign if specified
Dim Stepdown As Double = CDbl(txtStepdown.Text)
Stepdown = Math.Abs(Stepdown)
'Now loop through transforming the toolpath until we reach the bottom...
Dim CurZ As Double = StartZ - Stepdown
'Keep track of where we're at
Do While CurZ > EndZ
PMILL.Execute("EDIT TOOLPATH TRANSFORM POINTZ " & -Stepdown.ToString("0.######"))
PMILL.Execute("PROCESS TPXFORM")
CurZ -= Stepdown
Loop

Note the use of the Math.Abs function to return the Absolute value of a number. The Math class is part of
the .NET Framework and is where you can find other mathematical functions, e.g. Math.Sin, Math, Sqrt,
Math.Cos.

Shorthand Operators
New to VB.NET are the operators +=, -=, *= and /=
These are a shorthand methods of modifying variables, for example when incrementing a variable. In
the previous block code this has been used. E.g.
In VB6:
CurZ = CurZ Stepdown
In VB.NET: CurZ -= Stepdown

PowerSolution Automation
From VB6 To VB.NET

or
or

I=I+1
I += 1

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 17 of 74

There is no advantage to using the short-hand method other than personal perference of wether it
makes your code more readable.
4.2.9. Appending the Toolpaths
The final stage is to append the transformed toolpaths to give the finished result. We need to first
determine what toolpaths have been created by extracting the new list of toolpaths, and determining the
difference between the old and new lists.
Add the following to the cmdApply_Click code

'Get the new list of entities...


Dim New_Num As Integer, New_Names() As String, New_Active As Integer
PMILL.GetEntityList(enumPowerMILLEntityType.pmToolpath, New_Num, New_Names, New_Active)
'Variable to hold the names of the toolpaths that have been created by transforming...
Dim NewToolpaths(-1) As String
'Loop through the new list of toolpaths, and find which ones were not in the
'original list. These are the ones we will store...
For i As Integer = 0 To New_Num - 1
'Flag to store wether the toolpath already existed...
Dim Fnd As Boolean = False
For t As Integer = 0 To Orig_Num - 1
'Check if name found in original list
If Orig_Names(t) = New_Names(i) Then
'Set flag and exit this inner loop
Fnd = True
Exit For
End If
Next
'If the name was not found, it must be a new toolpath
'So we store its name...
If Fnd = False Then
ReDim Preserve NewToolpaths(NewToolpaths.Length)
NewToolpaths(NewToolpaths.Length - 1) = New_Names(i)
End If
Next

Now we have the array of toolpaths to append together. We start with the first new toolpath, and append
the remainder. We can then delete these toolpaths after they have been appended.
Add the following code to finish the application

'We now append the toolpaths together.


'The first toolpath in the array is the one we append to
For i As Integer = 1 To NewToolpaths.Length - 1
PMILL.Execute("EDIT TOOLPATH '" & NewToolpaths(0) & "' APPEND '" & NewToolpaths(i) & "'")
PMILL.Execute("DELETE TOOLPATH '" & NewToolpaths(i) & "'")
Next

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 18 of 74

4.2.10. Full Listing


The full listing for the finished application is shown below

Imports PowerSolutionDOTNetOLE.clsPowerMILLOLE
Imports PMILL = PowerSolutionDOTNetOLE.clsPowerMILLOLE
Public Class Form1
Inherits System.Windows.Forms.Form
Windows Form Designer generated code
Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles cmdApply.Click
'Setup the OLE connection and check it
If PMILL.Connect = False Then
'Warn the user
MsgBox("Ensure PowerMILL is running.")
'Exit the sub routine
Return
End If
'Retrieve the name of the active toolpath
Dim ActiveToolpath As String =
PMILL.GetActiveEntityName(enumPowerMILLEntityType.pmToolpath)
'Check a toolpath is active
If ActiveToolpath = "" Then
'Warn the user and exit the sub routine if no toolpath is active
MsgBox("Ensure a toolpath is activated.")
Return
End If

'Variables to store toolpath min and max z


Dim TP_Xmin, TP_Xmax, TP_Ymin, TP_Ymax, TP_Zmin, TP_Zmax As Double
'Get the toolpath extents.
'If the active toolpath has not been calculated (i.e. only batched), we can detect
this
'because the GetEntitySize method will return False
If PMILL.GetEntitySize(enumPowerMILLEntityType.pmToolpath, ActiveToolpath, _
TP_Xmin, TP_Xmax, TP_Ymin, TP_Ymax, TP_Zmin, TP_Zmax) = False Then
MsgBox("The active toolpath has not been calculated.")
Return
End If
'Variables we'll store the start and end coordinate of the toolpath to create
Dim StartZ, EndZ As Double
'If either the start or end of the tooplath should use the Block, we get its size...
If optStartBlock.Checked = True Or optEndBlock.Checked = True Then
'Variables to store block size
Dim Blk_XMin, Blk_XMax, Blk_YMin, Blk_YMax, Blk_ZMin, Blk_ZMax As Double
'Get the block size, checking that a block is defined at the same time
'Note we use an empty string as the entity name
If PMILL.GetEntitySize(enumPowerMILLEntityType.pmBlock, "", _
Blk_XMin, Blk_XMax, Blk_YMin, Blk_YMax, Blk_ZMin, Blk_ZMax) = False Then
'Warn the user and exit if no block is defined
MsgBox("No block is currently defined.")
Return
End If
'Store whichever extents we need to use for the new toolpath
If optStartBlock.Checked = True Then
StartZ = Blk_ZMax
End If
If optEndBlock.Checked = True Then
EndZ = Blk_ZMin
End If
End If
'If either the start or end of the toolpath should use the Model, we get its size...

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 19 of 74

If optStartModel.Checked = True Or optEndModel.Checked = True Then


'Variables to store Model size
Dim Mdl_XMin, Mdl_XMax, Mdl_YMin, Mdl_YMax, Mdl_ZMin, Mdl_ZMax As Double
'Get the Model size, checking that a Model is defined at the same time
If PMILL.GetEntitySize(enumPowerMILLEntityType.pmModel, "", _
Mdl_XMin, Mdl_XMax, Mdl_YMin, Mdl_YMax, Mdl_ZMin, Mdl_ZMax) = False Then
'Warn the user and exit if no Model is defined
MsgBox("No Model is currently defined.")
Return
End If
'Store whichever extents we need to use for the new toolpath
If optStartModel.Checked = True Then
StartZ = Mdl_ZMax
End If
If optEndModel.Checked = True Then
EndZ = Mdl_ZMin
End If
End If
'If the user has specified to use a distance from the top, calculate the bottom
position...
If optEndDistance.Checked = True Then
EndZ = StartZ - CDbl(txtDistance.Text)
End If
Dim Orig_Num As Integer, Orig_Names() As String, Orig_Active As Integer
PMILL.GetEntityList(enumPowerMILLEntityType.pmToolpath, Orig_Num, Orig_Names,
Orig_Active)
'We first move the toolpath up in Z so the bottom of it lies on the required start
position...
Dim StartZMove As Double = StartZ - TP_Zmin
PMILL.Execute("EDIT TOOLPATH TRANSFORM POINTX 0")
PMILL.Execute("EDIT TOOLPATH TRANSFORM POINTY 0")
PMILL.Execute("EDIT TOOLPATH TRANSFORM POINTZ " & StartZMove.ToString("0.######"))
PMILL.Execute("EDIT TOOLPATH TRANSFORM DELETE N")
PMILL.Execute("PROCESS TPXFORM")
'Extract the stepdown from the form, removing the negative sign if specified
Dim Stepdown As Double = CDbl(txtStepdown.Text)
Stepdown = Math.Abs(Stepdown)
'Now loop through transforming the toolpath until we reach the bottom...
Dim CurZ As Double = StartZ - Stepdown
'Keep track of where we're at
Do While CurZ > EndZ
PMILL.Execute("EDIT TOOLPATH TRANSFORM POINTZ " & -Stepdown.ToString("0.######"))
PMILL.Execute("PROCESS TPXFORM")
CurZ -= Stepdown
Loop
'Get the new list of entities...
Dim New_Num As Integer, New_Names() As String, New_Active As Integer
PMILL.GetEntityList(enumPowerMILLEntityType.pmToolpath, New_Num, New_Names,
New_Active)
'Variable to hold the names of the toolpaths that have been created by transforming...
Dim NewToolpaths(-1) As String
'Loop through the new list of toolpaths, and find which ones were not in the
'original list. These are the ones we will store...
For i As Integer = 0 To New_Num - 1
'Flag to store wether the toolpath already existed...
Dim Fnd As Boolean = False
For t As Integer = 0 To Orig_Num - 1
'Check if name found in original list
If Orig_Names(t) = New_Names(i) Then
'Set flag and exit this inner loop
Fnd = True
Exit For
End If
Next
'If the name was not found, it must be a new toolpath
'So we store its name...
If Fnd = False Then
ReDim Preserve NewToolpaths(NewToolpaths.Length)

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 20 of 74

End If
NewToolpaths(NewToolpaths.Length - 1) = New_Names(i)
Next

'We now append the toolpaths together.


'The first toolpath in the array is the one we append to
For i As Integer = 1 To NewToolpaths.Length - 1
PMILL.Execute("EDIT TOOLPATH '" & NewToolpaths(0) & "' APPEND '" & NewToolpaths(i)
& "'")
PMILL.Execute("DELETE TOOLPATH '" & NewToolpaths(i) & "'")
Next
End Sub

4.2.11. Further Enhancements


As an additional exercise, the following work may be attempted

Write the code for the Close button to work it should exit the application.
Write code to enhance the interface so that the Distance text box is only enabled when the distance
Radio Button is selected.
Find potential ways to make the application fail, and write validation code to make it fool proof.

The finished project with some of these enhancements included is included in the folder Examples\PowerMILL_Tutorial_1a\

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 21 of 74

4.3. PowerMILL Tutorial 2


This PowerMILL tutorial leads you through creating a utility for batch processing PowerMILL projects. It
shows how you can develop an application to work with PowerMILL as an engine with no user interface.
The completed project is available from the Examples\PowerMILL_Tutorial_2a directory.
The methods introduced in this tutorial include: GUIDisplayed, Visible, ConnectToNew,
DoesGroupExistInInfoList, GetEntityParameterInfo, ParseParameterInfoForSetting.
4.3.1. Setting up the User Interface
Start a new Windows Application VB.NET project, and add the reference to the PowerSolutionDOTNetOLE
library.
In the Form Designer view, setup the interface as shown below, changing the specific properties of each
control as shown

Setup the short-cut to the clsPowerMILL class using the IMPORTS statement at the top of the code

Imports PowerSolutionDOTNetOLE.clsPowerMILLOLE
Imports PMILL = PowerSolutionDOTNetOLE.clsPowerMILLOLE
Public Class Form1
Inherits System.Windows.Forms.Form
Windows Form Designer generated code
End Class

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 22 of 74

4.3.2. Using PowerMILL as an Engine


It is possible to develop applications that use PowerMILLs functionality, but limit the user interface to that
you provide in your VB.NET project. It is also possible to use PowerMILLs functionality without even
displaying PowerMILL, for example to run an automatic routine in the background.
In this tutorial, we will be displaying PowerMILL, but driving it completely from the VB.NET application, and
preventing the user working manually in PowerMILL.
Creating a New PowerMILL Application The ConnectToNew method
The ConnectToNew method creates a new instance PowerMILL and connects your VB.NET application
directly to it, e.g.

PMILL.ConnectToNew()

By default, the new instance of PowerMILL will not be visible.


Provided you do not make PowerMILL visible, when the OLE connection is reset (i.e. either by using the
CloseOLEConnections method, or when your application exits), PowerMILL will also close down
automatically.
If you do make PowerMILL visible, when you application exits, the PowerMILL session will remain open, in
which case if you want to close it, you need to send the appropriate macro commands to do so.
To control the visibility of the PowerMILL application, use the Visible property, e.g.
To Show PowerMILL
PMILL.Visible = True

To Hide PowerMILL
PMILL.Visible = False

Hiding PowerSHAPEs User Interface The GUIDisplayed method


You can hide all menus and toolbars in any session of PowerMILL your application is connected to. You can
control the visibility of the menus and toolbars using the GUIDisplayed property, e.g.
To hide the user interface
PMILL.GUIDisplayed = False

To show the user interface


PMILL.GUIDisplayed = True

Note that when the user interface is hidden, the HTML browser window is still available. You need to
execute the relavent macro command to hide the browser window if you do not want it visible. E.g.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 23 of 74

PMILL.GUIDisplayed = False
PMILL.Execute("SPLITTER TABBROWSER WIDTH 1")

Controlling the PowerMILL Application Window the SetWindowState method


You can control the window state of PowerMILLs application window, by maximising, minimising, or
resetting its size, and by bringing PowerMILL to the foreground. E.g.
To maximise PowerMILL
PMILL.SetWindowState(PowerSolutionDOTNetOLE.clsGlobalEnumerations.enum_WindowStateType.psMaxim
ise)

The SetWindowState method will list the options available.

We can now write the code in our application to Initialise PowerMILL when our application starts. We will
connect to a new session, make PowerMILL visible, hide the user interface, and the maximise PowerMILL.
Bring up the Form1_Load event source code (you can do this by double clicking on the Form in the design
view).
Add the following
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
'Connect to new PowerMILL session
PMILL.ConnectToNew()
'Hide the GUI
PMILL.GUIDisplayed = False
PMILL.Execute("SPLITTER TABBROWSER WIDTH 1")
'Show PowerMILL's application window
PMILL.Visible = True
'Maximise PowerMILL
PMILL.SetWindowState(PowerSolutionDOTNetOLE.clsGlobalEnumerations.enum_WindowStateType.psMaxim
ise)
End Sub

If you now run the application, you will see how PowerMILL starts automatically. However if you click the
CROSS on the top right corner of the form to close it, youll notice the PowerMILL remains open. This is
because we have made it Visible after starting it.
We therefore need to send the commands to quit PowerMILL when our application quits.
We can do this in the Form Closing event.
Bring up the Form Closing event code. You
can do this from the soure code view, select
the (Form1 events) option from the left-hand
drop down list

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 24 of 74

Then from the right hand drop down list select the
Closing event

Now add the following Execute method to send the macro commands to quit PowerMILL.

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
PMILL.Execute("QUIT QUIT QUIT EXIT YES")
End Sub

We can now write the event code for the Close button on the form. Double click the Close button in the
design view. This will bring up the Click event source code. Add the following to close the form

Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


cmdClose.Click
Me.Close()
End Sub

4.3.3. Selecting the Projects


We need to implement the buttons to allow the user to add the projects to the list view. Here we can use
the new FolderBrowseDialog control that is now readily available in VB.NET.
Upon clicking the Add Project button, we need to display the folder browser, get the users selection, check
the folder is a PowerMILL project, and if so, add it to the listview.
Bring up the Click event source code for the cmdAddProject button, and add the following

Private Sub cmdAddProject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdAddProject.Click
'If the user selected a folder, we can add it
If dlgProjectDirectory.ShowDialog() = DialogResult.OK Then
'Check if the folder is PowerMILL project.
'We do this simply by looking for a *.pmlprj file in the folder...
Dim FndFiles() As String
FndFiles = IO.Directory.GetFiles(dlgProjectDirectory.SelectedPath, "*.pmlprj")
If FndFiles.Length = 0 Then
MsgBox("The selected folder is not a PowerMILL project.")
Return
End If
'Add the folder to the list view
Dim Item As ListViewItem = lvwProjects.Items.Add(dlgProjectDirectory.SelectedPath)
'Set status to be blank
Item.SubItems.Add("-")
End If
End Sub

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 25 of 74

The line
If dlgProjectDirectory.ShowDialog() = DialogResult.OK Then

shows the folder browser dialog, and checks the user has selected a directory.
The section
Dim FndFiles() As String
FndFiles = IO.Directory.GetFiles(dlgProjectDirectory.SelectedPath, "*.pmlprj")
If FndFiles.Length = 0 Then
MsgBox("The selected folder is not a PowerMILL project.")
Return
End If

is how we determine wether the directory is a PowerMILL project. We make use of the IO class which is
part of the .NET framework, using the method GetFiles. This returns an array of filenames in the specified
directory, and filtered by *.pmlprj.
If no files are found, we know it is not a PowerMILL project.
Finally, the section
Dim Item As ListViewItem = lvwProjects.Items.Add(dlgProjectDirectory.SelectedPath)
'Set status to be blank
Item.SubItems.Add("-")

adds the details to the listview. First adding the main label (the project directory), and then adding to the
2nd column in the row.
4.3.4. Processing the Projects
The final stage is to implement the Apply button to process the projects. The steps we need to automate
are

Clear any existing project in PowerMILL


Loop through all selected folders
Open each project in PowerMILL
Check there are toolpaths in the project
Check that there are toolpaths needing to be batched
Do the batch processing
And repeat for the other projects

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 26 of 74

Access the Click event code for the cmdApply button. Then add the following

Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


cmdApply.Click
For i As Integer = 0 To lvwProjects.Items.Count 1
Dim ProjDir As String = lvwProjects.Items(i).SubItems(0).Text
'First close down any projects in PowerMILL...
PMILL.Execute("PROJECT RESET YES")
'Now open the current project...
PMILL.Execute("PROJECT OPEN '" & ProjDir & "'")
'We check there are toolpaths to process...
Dim TP_Num As Integer, TP_Names() As String, TP_Active As Integer
PMILL.GetEntityList(enumPowerMILLEntityType.pmToolpath, TP_Num, TP_Names, TP_Active)
If TP_Num = 0 Then
lvwProjects.Items(i).SubItems(1).Text = "Failed - No toolpaths in project"
GoTo SkipProcess
End If
SkipProcess:
Next
End Sub

Here we loop through all the projects in the list view. For each project, we use the GetEntityList method to
extract the list of toolpaths in the project. If no toolpaths are found, we put the warning in the 2nd column
of the listview.
We now need code to loop through each toolpath, and determine wether they need to be calculated.
Extracting Entity Information - Get GetEntityParameterInfo, ParseParameterInfoForSetting and
DoesGroupExistInInfoList methods.
These three methods are used in combination in order to extract information about any entity in the
PowerMILL explorer.
The first step is always to retrieve the array of parameter information. For this, we use the
GetEntityParameterInfo method.
Firstly though, switch to PowerMILL and open the example project stored in Examples\ PowerMILL Tutorial
1 Test Project.
Now show the command window (from the menus - VIEW, TOOLBAR, COMMAND).
Enter the following macro command and press Enter

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 27 of 74

If you expand the command window, you will see a long


string of information as shown here.
This output contains all of the parameter information for
a toolpath. It would be possible to extract this
information using the ExecuteEx method, and then write
code to interogate it to find any particular setting for an
entity.
However, the GetEntityParameterInfo,
ParseParameterInfoForSetting and
DoesGroupExistInInfoList methods, do this work for you.
The GetEntityParameterInfo method is used to firstly
extract this information and break it up into separate
lines (stored as a string array).
The ParseParameterInfoForSetting method is then used
to search within a particular group of settings for a
specific setting name, and return the data in the format
required.
The DoesGroupExistInInfoList method is used simply to
check if a particular group exists in the output. This can
be used to identify the type of entity. For example each
toolpath type will have differently named groups.

The Example project installed with the PowerSolutionDOTNetOLE library (C:\Program Files\Delcam
PLC\PowerSolutionDOTNetOLE API Classes\Help\Examples Code\PowerMILL_Example1) shows an example
of using these three methods to identify toolpath types.
Here we need to use the methods to find out wether the toolpath has been calculated. If you look through
the list of settings, you will see the group highlighted here.

We can use this information to determine if a toolpath has been calculated or batched.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 28 of 74

Add the code highlighted below to the sub routine

Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


cmdApply.Click
If lvwProjects.Items.Count = 0 Then
MsgBox("Select the projects to process.")
Return
End If
'We now loop through all the projects selected
For i As Integer = 0 To lvwProjects.Items.Count - 1
Dim ProjDir As String = lvwProjects.Items(i).SubItems(0).Text
'First close down any projects in PowerMILL...
PMILL.Execute("PROJECT RESET YES")
'Now open the current project...
PMILL.Execute("PROJECT OPEN '" & ProjDir & "'")
'We check there are toolpaths to process...
Dim TP_Num As Integer, TP_Names() As String, TP_Active As Integer
PMILL.GetEntityList(enumPowerMILLEntityType.pmToolpath, TP_Num, TP_Names, TP_Active)
If TP_Num = 0 Then
lvwProjects.Items(i).SubItems(1).Text = "Failed - No toolpaths in project"
GoTo SkipProcess
End If
Dim NumToBatch As Integer = 0
For t As Integer = 0 To TP_Num - 1
'We now check wether the toolpaths have already been calculated.
'We do this by checking the parameters of the toolpath
'Get full array of parameter info...
Dim Params() As String = _
PMILL.GetEntityParameterInfo(enumPowerMILLEntityType.pmToolpath, TP_Names(t))
'Check the specific parameter for wether it has been calculated.
'Each toolpath has a parameter group ':dmkMcParToolpathStatus'
Dim Computed As Boolean = PMILL.ParseParameterInfoForSetting(Params, _
":dmkMcParToolpathStatus", "COMPUTED", enumEntitySettingDataType.parBoolean)
Dim Batched As Boolean = PMILL.ParseParameterInfoForSetting(Params, _
":dmkMcParToolpathStatus", "BATCHED", enumEntitySettingDataType.parBoolean)
If Computed = False And Batched = True Then
NumToBatch += 1
End If
Next
If NumToBatch = 0 Then
lvwProjects.Items(i).SubItems(1).Text = "No batched toolpaths to process"
GoTo SkipProcess
End If
'Now we can batch process...
PMILL.Execute("BATCH PROCESS")
'At this point we could save the project...
'We've commented out the line for testing purposes
'so we don't overwrite the test projects
'PMILL.Execute("PROJECT SAVE")
'Update status...
lvwProjects.Items(i).SubItems(1).Text = "Completed"
Application.DoEvents()
SkipProcess:
Next
End Sub

Here we loop through all the toolpaths found, and store the array of entity information in the string array
Params().
We then call the ParseParameterInfoForSetting method, passing in the array of information, the group
to search within, and the specific setting to find. We also give the parameter for the data type we expect to

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 29 of 74

get back. For example here we want a boolean result. The method will automatically convert the setting
information to boolean, for example ON = True, YES = True, OFF = False, and NO = False.
We keep count of all toolpaths that require calculation, and warn if no toolpaths need to be processed.
Otherwise we send the macro command to start batch processing.
Note that the command to save the project has been commented out. This is so we can re-use the example
projects to test the application. As a real application, you can uncomment this line to save the projects after
batch processing.
4.3.5. Further Enhancements
As an additional exercise, the following work may be attempted

Write the code to check that projects have been selected before batch processing
Implement the Remove Project button to remove a project from the list view.

The finished project with some of these enhancements included is included in the folder Examples\PowerMILL_Tutorial_2a\

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 30 of 74

5. Working with PowerSHAPE the clsPowerSHAPEOLE Class

5.1. Introduction
The clsPowerSHAPEOLE class allows you to connect and work directly with PowerSHAPE.
A summary of the most commonly used functionality available in the class is listed in the table below.
The following tutorials do not cover all of the methods below. In this case further information can be found
in the on-line help, or in the example project installed with the PowerSolutionDOTNetOLE library.

Name
CloseAllModels
CloseOLEConnections
Connect
ConnectAsPSSurfacer
CreateRelativeWorkplane
CreateWorkplane
DistanceBetweenObjects
Evaluate
Execute
FindNearestPoint
GetCreatedEntities
GetCurrentUnits
GetSelectedEntities
ImportModel
IsPSConnected
OpenModel
OpenModelIfNone
SelectAllOnLevel
SelectAllWorkplanes
SelectEntityList
SetDialogMode
SetUnits
SetWindowState
ShowEverythingOnLevel
Version
GuiDisplayed
Visible

PowerSolution Automation
From VB6 To VB.NET

clsPowerSHAPEOLE Class Members


Description

More
Info.

Closes all models open in PowerSHAPE without prompting


and without saving.
Reset all OLE connections to PowerSHAPE
Make a connection to the PowerSHAPE application
Makes the OLE connection when you are working with
PSSurfacer
Creates a workplane relative to the active workplane using
the axes specified.
Creates a workplane relative to WORLD using the axes
specified.
Returns the minimum distance between 2 entities
Extract object information from PowerSHAPE
Execute macro commands in PowerSHAPE
Given a surface and point, returns the nearest point on the
surface relative to WORLD
Returns the list of entities created with the last macro
command
Returns the current units set for the active model
Returns the list of entities currently selected
Imports a specified file into PowerSHAPE
Checks wether an OLE connection to PowerSHAPE exists
Opens a PSMODEL from the path specified
Opens a new PSMODEL if none is currently open
Shows then selects everything on a specified level
Selects all visible workplanes
Select all entities from the array of entities specified
Sets the status of popup messages
Sets the current units for the current model
Controls the window state of the PowerSHAPE application
Shows and unblanks everything on a specific level.
Returns the version of PowerSHAPE connected to
Property to control wether the user interface is visible in
PowerSHAPE
Property to control the visibility of the main PowerSHAPE
application window

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Tutorial 1

Tutorial 1
Tutorial 1

Tutorial 3

Print Date: 11/07/2005


Page 31 of 74

5.2. Tutorial 1 Basic Automation of PowerSHAPE


This first tutorial shows the basics of connecting to PowerSHAPE, executing macro command, and extracting
object information from the model.
The princpals in working with PowerSHAPE are identical to what you will be familiar with in VB6.
This tutorial re-creates the old RoundRectangle utility. The completed project is available in the
Examples\PowerSHAPE_Tutorial_1a\ directory
5.2.1. Setting up the User Interface
Start a new Windows Application VB.NET project, and add the reference to the PowerSolutionDOTNetOLE
library.
In the form designer, setup the interface below.

View the code for the project, and add the IMPORTS statement below to link to the clsPowerSHAPEOLE
class

Imports PSHAPE = PowerSolutionDOTNetOLE.clsPowerSHAPEOLE


Public Class Form1
Inherits System.Windows.Forms.Form
Windows Form Designer generated code
End Class

Here we setup the short-cut PSHAPE to link to the clsPowerSHAPEOLE class. Similar to linking to the
PowerMILL class, we can now access all methods using the PSHAPE short-cut.
5.2.2. Connecting to PowerSHAPE the Connect method
This is identical to the Connect method for the clsPowerMILLOLE class. It must be called before any other
operations can be performed.
The method will return True or False depending upon wether a connection could be made.
Double click the Apply button on the design view, to bring up the cmdApply_Click event source code.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 32 of 74

Add the following

Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdApply.Click
If PSHAPE.Connect() = False Then
MsgBox("Ensure PowerSHAPE is running.")
Return
End If
End Sub

This creates the OLE connection whilst verifying the connection was made.

If you are running PS-Surfacer instead, you must use the similar method ConnectAsPSSurfacer. Other
than this, all other principals are the same.

5.2.3. Executing Macro Commands The Execute method


The Execute method is used to send macro commands into PowerSHAPE. The user of this method is
identical to the clsPowerMILLOLE Execute method.
So you can send single macro commands

PSHAPE.Execute("CREATE LINE SINGLE")


PSHAPE.Execute("0 0 0")
PSHAPE.Execute("100 0 0")
PSHAPE.Execute("SELECT")

Or use a single call passing in the list of commands

PSHAPE.Execute("CREATE LINE SINGLE", "0 0 0", "100 0 0", "SELECT")

Add the following to the Apply button click event code to create the rectangle.

'Get the coordinates for the lines of the rectangle


Dim Width, Length, Radius As Double
Width = CType(txtWidth.Text, Double)
Length = CType(txtLength.Text, Double)
Radius = CType(txtRadius.Text, Double)
'Store coordinates for top line of rectangle
Dim TopLineMinX, TopLineMaxX, TopLineY As Double
TopLineMinX = (-Length / 2) + Radius
TopLineMaxX = (Length / 2) - Radius
TopLineY = Width / 2
'Store coordinates for right line of rectangle
Dim RightLineX, RightLineMinY, RightLineMaxY As Double
RightLineX = Length / 2
RightLineMinY = (-Width / 2) + Radius
RightLineMaxY = (Width / 2) - Radius
'Store coordinates for bottom line of rectangle
Dim BottomLineMinX, BottomLineMaxX, BottomLineY As Double
BottomLineMinX = (-Length / 2) + Radius
BottomLineMaxX = (Length / 2) - Radius
BottomLineY = -Width / 2

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 33 of 74

'Store coordinates for left line of rectangle


Dim LeftLineX, LeftLineMinY, LeftLineMaxY As Double
LeftLineX = -Length / 2
LeftLineMinY = (-Width / 2) + Radius
LeftLineMaxY = (Width / 2) - Radius
'Create the lines for the rectangle
PSHAPE.Execute("CREATE LINE SINGLE")
PSHAPE.Execute(TopLineMinX.ToString("0.######") & " " & _
TopLineY.ToString("0.######"))
PSHAPE.Execute("ABS " & TopLineMaxX.ToString("0.######") & " " & _
TopLineY.ToString("0.######"))
PSHAPE.Execute(RightLineX.ToString("0.######") & " " & _
RightLineMinY.ToString("0.######"))
PSHAPE.Execute("ABS " & RightLineX.ToString("0.######") & " " & _
RightLineMaxY.ToString("0.######"))
PSHAPE.Execute(BottomLineMinX.ToString("0.######") & " " & _
BottomLineY.ToString("0.######"))
PSHAPE.Execute("ABS " & BottomLineMaxX.ToString("0.######") & " " & _
BottomLineY.ToString("0.######"))
PSHAPE.Execute(LeftLineX.ToString("0.######") & " " & _
LeftLineMinY.ToString("0.######"))
PSHAPE.Execute("ABS " & LeftLineX.ToString("0.######") & " " & _
LeftLineMaxY.ToString("0.######"))
PSHAPE.Execute("SELECT")
'Create the radii for the rectangle...
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(TopLineMinX.ToString("0.######") & " " & _
LeftLineMaxY.ToString("0.######"))
PSHAPE.Execute("ABS " & LeftLineX.ToString("0.######") & " " & _
LeftLineMaxY.ToString("0.######"))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute("ABS " & TopLineMinX.ToString("0.######") & " " & _
TopLineY.ToString("0.######"))
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(TopLineMaxX.ToString("0.######") & " " & _
RightLineMaxY.ToString("0.######"))
PSHAPE.Execute("ABS " & TopLineMaxX.ToString("0.######") & " " & _
TopLineY.ToString("0.######"))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute("ABS " & RightLineX.ToString("0.######") & " " & _
RightLineMaxY.ToString("0.######"))
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(BottomLineMaxX.ToString("0.######") & " " & _
RightLineMinY.ToString("0.######"))
PSHAPE.Execute("ABS " & RightLineX.ToString("0.######") & " " & _
RightLineMinY.ToString("0.######"))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute("ABS " & BottomLineMaxX.ToString("0.######") & " " & _
BottomLineY.ToString("0.######"))
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(BottomLineMinX.ToString("0.######") & " " & _
LeftLineMinY.ToString("0.######"))
PSHAPE.Execute("ABS " & BottomLineMinX.ToString("0.######") & " " & _
BottomLineY.ToString("0.######"))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute("ABS " & LeftLineX.ToString("0.######") & " " & _
LeftLineMinY.ToString("0.######"))
PSHAPE.Execute("SELECT CLEARLIST")

We first extract the user input using the commands

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 34 of 74

Dim Width, Length, Radius As Double


Width = CType(txtWidth.Text, Double)
Length = CType(txtLength.Text, Double)
Radius = CType(txtRadius.Text, Double)

The CType Function


In the code above, we use the CType function to convert the values in the text boxes to real
numbers. We could have used the CDbl function also. To convert from one data type to another,
individual functions like CDbl can beused.
The CType function however is a general function you can use to convert any variable or object to
any another type. You just specify in the second parameter the type you want to convert to. This
way you only need remember the CType function, rather than all the individual ones. Its just a
matter of personal preference wether you use this

We the then create variables to hold the coordinates of the rectangle.


And finally we send the macro commands to create the lines and arcs of the rectangle.
There is a lot of code shown here. What is particularly cumbersome is sending coordinate information to
PowerSHAPE. The syntax is awkward, especially when having to convert from real numbers to strings.
You will see in Tutorial 2 how the PowerSolutionDOTNetOLE library can be used to simplify much of your
code, and cut down the amount of work you need to do for storing coordinate information, and sending it to
PowerSHAPE.
The final step to our application is to convert the entities to give us a single composite curve. This is
covered in the next section.
5.2.4. Extracting Object Information The Evaluate method
The Evaluate method is used to extract any object information from the current PSMODEL. It works in a
similar way to the ActiveX control used in VB6.
You need to supply the object information command to the method, and the returned value will be based on
the type of information. E.g. It could be a string, real number, integer number, or an array of numbers.
For example, to extract the current modelling tolerance, you could use

Dim Tol As Double = PSHAPE.Evaluate("TOLERANCE.GENERAL")

The object information being TOLERANCE.GENERAL.


The list of object information variables you can use is available from the on-line help installed with
PowerSHAPE.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 35 of 74

In our application here, we need to use the object information to determine the names of each entity we
create, so that we can select them all later to convert to a composite curve.
Whenever a line or arc is created, it will be selected, so we can use the SELECTED.NAME[0] object
information to find out the name of this entity.
e.g.

Dim Selected As String = pshape.Evaluate("SELECTION.NAME[0]")

Add all of the code highlighted below to complete the tutorial. Notice that we store the names of all the
lines and arcs as we create them. We then select all the entities and convert to a composite curve.

Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdApply.Click
If PSHAPE.Connect() = False Then
MsgBox("Ensure PowerSHAPE is running.")
Return
End If
'Get the coordinates for the lines of the rectangle
Dim Width, Length, Radius As Double
Width = CType(txtWidth.Text, Double)
Length = CType(txtLength.Text, Double)
Radius = CType(txtRadius.Text, Double)
'Store coordinates for top line of rectangle
Dim TopLineMinX, TopLineMaxX, TopLineY As Double
TopLineMinX = (-Length / 2) + Radius
TopLineMaxX = (Length / 2) - Radius
TopLineY = Width / 2
'Store coordinates for right line of rectangle
Dim RightLineX, RightLineMinY, RightLineMaxY As Double
RightLineX = Length / 2
RightLineMinY = (-Width / 2) + Radius
RightLineMaxY = (Width / 2) - Radius
'Store coordinates for bottom line of rectangle
Dim BottomLineMinX, BottomLineMaxX, BottomLineY As Double
BottomLineMinX = (-Length / 2) + Radius
BottomLineMaxX = (Length / 2) - Radius
BottomLineY = -Width / 2
'Store coordinates for left line of rectangle
Dim LeftLineX, LeftLineMinY, LeftLineMaxY As Double
LeftLineX = -Length / 2
LeftLineMinY = (-Width / 2) + Radius
LeftLineMaxY = (Width / 2) - Radius
'Create the lines for the rectangle
'Store for the names of lines
Dim Lines(3) As String
PSHAPE.Execute("CREATE LINE SINGLE")
PSHAPE.Execute(TopLineMinX.ToString("0.######") & " " & _
TopLineY.ToString("0.######"))
PSHAPE.Execute("ABS " & TopLineMaxX.ToString("0.######") & " " & _
TopLineY.ToString("0.######"))
Lines(0) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute(RightLineX.ToString("0.######") & " " & _
RightLineMinY.ToString("0.######"))
PSHAPE.Execute("ABS " & RightLineX.ToString("0.######") & " " & _
RightLineMaxY.ToString("0.######"))
Lines(1) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute(BottomLineMinX.ToString("0.######") & " " & _
BottomLineY.ToString("0.######"))
PSHAPE.Execute("ABS " & BottomLineMaxX.ToString("0.######") & " " & _
BottomLineY.ToString("0.######"))
Lines(2) = PSHAPE.Evaluate("SELECTION.NAME[0]")

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 36 of 74

PSHAPE.Execute(LeftLineX.ToString("0.######") & " " & _


LeftLineMinY.ToString("0.######"))
PSHAPE.Execute("ABS " & LeftLineX.ToString("0.######") & " " & _
LeftLineMaxY.ToString("0.######"))
Lines(3) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute("SELECT")

'Create the radii for the rectangle...


'Store for the names of arcs
Dim Arcs(3) As String
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(TopLineMinX.ToString("0.######") & " " & _
LeftLineMaxY.ToString("0.######"))
PSHAPE.Execute("ABS " & LeftLineX.ToString("0.######") & " " & _
LeftLineMaxY.ToString("0.######"))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute("ABS " & TopLineMinX.ToString("0.######") & " " & _
TopLineY.ToString("0.######"))
Arcs(0) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(TopLineMaxX.ToString("0.######") & " " & _
RightLineMaxY.ToString("0.######"))
PSHAPE.Execute("ABS " & TopLineMaxX.ToString("0.######") & " " & _
TopLineY.ToString("0.######"))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute("ABS " & RightLineX.ToString("0.######") & " " & _
RightLineMaxY.ToString("0.######"))
Arcs(1) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(BottomLineMaxX.ToString("0.######") & " " & _
RightLineMinY.ToString("0.######"))
PSHAPE.Execute("ABS " & RightLineX.ToString("0.######") & " " & _
RightLineMinY.ToString("0.######"))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute("ABS " & BottomLineMaxX.ToString("0.######") & " " & _
BottomLineY.ToString("0.######"))
Arcs(2) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(BottomLineMinX.ToString("0.######") & " " & _
LeftLineMinY.ToString("0.######"))
PSHAPE.Execute("ABS " & BottomLineMinX.ToString("0.######") & " " & _
BottomLineY.ToString("0.######"))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute("ABS " & LeftLineX.ToString("0.######") & " " & _
LeftLineMinY.ToString("0.######"))
Arcs(3) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute("SELECT CLEARLIST")
'Select all created entities
For i As Integer = 0 To 3
PSHAPE.Execute("ADD LINE '" & Lines(i) & "'")
PSHAPE.Execute("ADD ARC '" & Arcs(i) & "'")
Next
'And finally create a composite curve...
PSHAPE.Execute("CONVERT COMPCURVE")
End Sub

5.2.5. Further Development


As an additional exercise, add validation of the text boxes to ensure the user hasnt entered invalid values.
The completed project in Examples\PowerSHAPE_Tutorial_1a directory includes this validation.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 37 of 74

5.3. Tutorial 2 Simplifying You Code With the clsPoint3D Class


In this tutorial, we will modify the Round Rect utility created in Tutorial 1, to help highlight the use of two
new classes available in the PowerSolutionDOTNetOLE library, which can significantly speed up your
development, simplify your code, and handle common tasks. Open up the project created in Tutorial 1.
5.3.1. Handling 3D Coordinates
The first of the new classes we will look at is the clsPoint3D class.
You can define multiple objects based on this class, and use them for storing 3D coordinate or 3D vector
information. For example, if you want to store a 3D coordinate, you could use
Dim
X =
Y =
Z =

X, Y, Z As Double
10
50
35

But with the clsPoint3D class, you simply use


Dim Point1 As New PowerSolutionDOTNetOLE.clsPoint3D(10, 50, 35)

To save on the amount of typing, add to the Declarations section of your code
Imports PowerSolutionDOTNetOLE

You can use simply use


Dim Point1 As New clsPoint3D(10, 50, 35)

This way you have a single object holding information on the 3D point.
This is most convenient when working with arrays of 3D points too.
You can edit the values, or retrieve information about the point simply by accessing the properties and
methods of the object.
For example to move the X coordinate of the point, you could use
Point1.X += 50

In Tutorial 1, we stored the coordinates for the rectangle using for example
Dim TopLineMinX, TopLineMaxX, TopLineY As Double
TopLineMinX = (-Length / 2) + Radius
TopLineMaxX = (Length / 2) - Radius
TopLineY = Width / 2

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 38 of 74

Using the clsPoint3D class, we would use instead


Dim TopStart As New clsPoint3D((-Length / 2) + Radius, Width / 2, 0)
Dim TopEnd As New clsPoint3D((Length / 2) - Radius, Width / 2, 0)

So far, we see the advantage is purely convenience. Storing a coordinate in a single variable, rather than
having separate X, Y and Z variables.
However the clsPoint3D class has additional methods built-in to handle common operations.
Some of the most commonly used methods are shown below
String Handling
Probably the most useful method with respect to working with PowerSHAPE, allows you to quickly convert
the 3D coordinate to a string suitable to be passed into PowerSHAPE, or maybe written to an ASCII text file.
This is the SerialisedString method.
Previously, if we wanted to send a coordinate to PowerSHAPE from a variable, we would have something
like
Dim X, Y, Z As Double
X = 30
Y = 50
Z = -20
PSHAPE.Execute("ABS " & X.ToString("0.######") & _
" " & Y.ToString("0.######") & _
" " & Z.ToString("0.######"))

The SerialisedString method automatically does this formatting. Parameters for this method allow you
specify wether to automatically add the ABS prefix, specify what decimal separator to use, and specify how
many decimal places to output. It will then return a string which can use directly with the Execute method
in PowerSHAPE. The code below can replace all of that in the previous block
Dim XYZ As New clsPoint3D(30, 50, -20)
PSHAPE.Execute(XYZ.SerialisedString(True))

If you omit all parameters from this method, it will default to a format appropriate for PowerSHAPE.
Modify the cmdApply_Click event code in the project created in Tutorial 1 to that below

Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdApply.Click
If PSHAPE.Connect() = False Then
MsgBox("Ensure PowerSHAPE is running.")
Return
End If
'Get the coordinates for the lines of the rectangle
'Validate the user input...
Dim Width, Length, Radius As Double
Try
Width = CType(txtWidth.Text, Double)
If Width <= 0 Then Throw New Exception("Width must be greater than 0")
Catch
MsgBox("Invalid width specified.")
Return

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 39 of 74

Try
End Length
Try
= CType(txtLength.Text, Double)
If Length <= 0 Then Throw New Exception("Length must be greater than 0")
Catch
MsgBox("Invalid length specified.")
Return
End Try
Try
Radius = CType(txtRadius.Text, Double)
If Radius <= 0 Then Throw New Exception("Radius must be greater than 0")
Catch
MsgBox("Invalid radius specified.")
Return
End Try
If (2 * Radius) >= Length Or (2 * Radius) >= Width Then
MsgBox("The radius is too large to fit in the specified rectangle's corners.")
Return
End If

Dim
X =
Y =
Z =

X, Y, Z As Double
10
50
35

Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim

TopStart As New clsPoint3D((-Length / 2) + Radius, Width / 2, 0)


TopEnd As New clsPoint3D((Length / 2) - Radius, Width / 2, 0)
RightStart As New clsPoint3D(Length / 2, (-Width / 2) + Radius, 0)
RightEnd As New clsPoint3D(Length / 2, (Width / 2) - Radius, 0)
BottomStart As New clsPoint3D((-Length / 2) + Radius, -Width / 2, 0)
BottomEnd As New clsPoint3D((Length / 2) - Radius, -Width / 2, 0)
LeftStart As New clsPoint3D(-Length / 2, (-Width / 2) + Radius, 0)
LeftEnd As New clsPoint3D(-Length / 2, (Width / 2) - Radius, 0)
TopLeftArcCentre As New clsPoint3D(TopStart.X, LeftEnd.Y, 0)
TopRightArcCentre As New clsPoint3D(TopEnd.X, RightEnd.Y, 0)
BottomLeftArcCentre As New clsPoint3D(BottomStart.X, LeftStart.Y, 0)
BottomRightArcCentre As New clsPoint3D(BottomEnd.X, RightStart.Y, 0)

'Create the lines for the rectangle


'Store for the names of lines
Dim Lines(3) As String
PSHAPE.Execute("CREATE LINE SINGLE")
PSHAPE.Execute(TopStart.SerialisedString, TopEnd.SerialisedString(True))
Lines(0) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute(RightStart.SerialisedString, RightEnd.SerialisedString(True))
Lines(1) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute(BottomStart.SerialisedString, BottomEnd.SerialisedString(True))
Lines(2) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute(LeftStart.SerialisedString, LeftEnd.SerialisedString(True))
Lines(3) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute("SELECT")
'Create the radii for the rectangle...
'Store for the names of arcs
Dim Arcs(3) As String
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(TopLeftArcCentre.SerialisedString)
PSHAPE.Execute(LeftEnd.SerialisedString(True))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute(TopStart.SerialisedString(True))
Arcs(0) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(TopRightArcCentre.SerialisedString)
PSHAPE.Execute(TopEnd.SerialisedString(True))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute(RightEnd.SerialisedString(True))
Arcs(1) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(BottomRightArcCentre.SerialisedString)
PSHAPE.Execute(RightStart.SerialisedString(True))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute(BottomEnd.SerialisedString(True))
Arcs(2) = PSHAPE.Evaluate("SELECTION.NAME[0]")

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 40 of 74

PSHAPE.Execute(BottomLeftArcCentre.SerialisedString)
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(BottomStart.SerialisedString(True))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute(LeftStart.SerialisedString(True))
Arcs(3) = PSHAPE.Evaluate("SELECTION.NAME[0]")
PSHAPE.Execute("SELECT CLEARLIST")
'Select all created entities
For i As Integer = 0 To 3
PSHAPE.Execute("ADD LINE '" & Lines(i) & "'")
PSHAPE.Execute("ADD ARC '" & Arcs(i) & "'")
Next
'And finally create a composite curve...
PSHAPE.Execute("CONVERT COMPCURVE")
End Sub

Vector Maths
The clsPoint3D class has built-in methods for calculating unit vectors, vector addition, vector subtraction,
vector cross products, vector dot products, and scalar vectors. More details on these methods are available
from the on-line help. Here are a couple of examples
e.g. To convert a 3D point to a unit vector
Dim V1 As New clsPoint3D(10, 4, 3)
V1.ConvertToUnitVector()

e.g. To add two vectors together


Dim V1 As New clsPoint3D(10, 4, 3)
Dim V2 As New clsPoint3D(-5, 9, 25)
Dim V3 As clsPoint3D = clsPoint3D.VectorAddition(V1, V2)

Geometry Functions
Methods are available to allow you to compare points, and to transform points from different coordinate
systems.
e.g. To find the mid-point between two points
Dim P1 As New clsPoint3D(10, 4, 3)
Dim P2 As New clsPoint3D(-5, 9, 25)
Dim MidPoint As clsPoint3D = clsPoint3D.MidPoint(P1, P2)

e.g. To find the distance between two points


Dim P1 As New clsPoint3D(10, 4, 3)
Dim P2 As New clsPoint3D(-5, 9, 25)
Dim Distance As Double = clsPoint3D.DistanceBetweenPoints(P1, P2)

e.g. To convert from cartesian to polar coordinates


Dim P1 As New clsPoint3D(10, 4, 3)

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 41 of 74

P1.GetPolar(Angle, Radius)
Dim Angle As Double, Radius As Double

e.g. To transform a point from World coordinate to a workplane of know axes


Dim
Dim
Dim
Dim
Dim
Dim

P1 As New clsPoint3D(10, 4, 3)
Origin As New clsPoint3D(100, 30, -30)
XAxis As New clsPoint3D(0.707, 0.707, 0)
YAxis As New clsPoint3D(-0.707, 0.707, 0)
ZAxis As New clsPoint3D(0, 0, 1)
TransP As clsPoint3D = P1.TransformToWkpl(True, Origin, XAxis, YAxis, ZAxis)

Note on the clsPoint3D class


It is worth pointing out that the clsPoint3D class is completely independent to PowerSHAPE or PowerMILLs
OLE classes. It does not rely on having an OLE connection to any of the Delcam products, nor even to have
any Delcam products running.
So declaring a clsPoint3D object does not have connection to physical entities, such as the point entity in
PowerSHAPE.
5.3.2. Using the clsPoint3D Object With Object Information
As weve already seen, the contructor for the clsPoint3D object allows you to create the object by specifying
the X, Y and Z values.
A 2nd constructor also allows you to define a clsPoint3D object directly from object information extracted
from PowerSHAPE.
For example, to get the min/max bounding box of the current selection, we could use the Evaluate method,
e.g.
Dim Info As Object
Info = PSHAPE.Evaluate("SELECTION.MIN_RANGE_EXACT")
Dim X, Y, Z As Double
X = CDbl(Info(0))
Y = CDbl(Info(1))
Z = CDbl(Info(2))

This can be cumbersome. When getting coordinate information from PowerSHAPE, the Evaluate method
will return an array. Which we then need to convert to the real variables.
Using the clsPoint3D class, we can declare a clsPoint3D object directly from the object information. The
following line replaces the code in the previous block

Dim XYZ As New clsPoint3D("SELECTION.MIN_RANGE_EXACT")

This can be used to retrieve coordinates of any object information command that returns information as an
XYZ (i.e. The location of a point, or the vector of a curve point). The only point to note is that before you
can use this method, you must have first used the clsPowerSHAPEOLE.Connect method to ensure an
OLE connection has been made to PowerSHAPE first.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 42 of 74

We will now use this to add a button to our Round Rect form which will set the length and width values
based on the current selection size in PowerSHAPE.

Modify the Round Rect form as shown, adding the new Button
(set its name to be cmdFromSelection).
Double click the button to bring up the Click event source code
for this button.

The first step is to ensure something is actually selected. Add the following to the cmdFromSelection_Click
code

Private Sub cmdFromSelection_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles cmdFromSelection.Click
If PSHAPE.Connect() = False Then
MsgBox("Ensure PowerSHAPE is running.")
Return
End If
If PSHAPE.Evaluate("SELECTION.NUMBER") = 0 Then
MsgBox("Select the entities to size to first.")
Return
End If
End Sub

Here we use the SELECTION.NUMBER Object information to find out if anything is selected.
Note that we have also added the Connect method here. This is because we only had the Connect method
used in the cmdApply_Click event code. So we need to add it here too to ensure we have the OLE
connection.
Alternatively we could have used the Connect method in the Form_Load event instead, so that the OLE
connection is made as soon as our application starts.

The next step is to extract the min/max limits of the selection, and use this to set the length and width.
Add the following to the cmdFromSelection_Click event code

Dim MinBound As New clsPoint3D("SELECTION.MIN_RANGE_EXACT")


Dim MaxBound As New clsPoint3D("SELECTION.MAX_RANGE_EXACT")
txtLength.Text = (MaxBound.X - MinBound.X).ToString("0.###")
txtWidth.Text = (MaxBound.Y - MinBound.Y).ToString("0.###")

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 43 of 74

Compare this with the code you would need using the Evaluate method!!!

Dim MinSize As Object


MinSize = PSHAPE.Evaluate("SELECTION.MIN_RANGE_EXACT")
Dim MinX As Double = CDbl(MinSize(0))
Dim MinY As Double = CDbl(MinSize(1))
Dim MaxSize As Object
MaxSize = PSHAPE.Evaluate("SELECTION.MAX_RANGE_EXACT")
Dim MaxX As Double = CDbl(MaxSize(0))
Dim MaxY As Double = CDbl(MaxSize(1))
txtLength.Text = (MaxX - MinX).ToString("0.###")
txtWidth.Text = (MaxY - MinY).ToString("0.###")

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 44 of 74

5.4. Tutorial 3 Working With PowreSHAPE Entities


In this tutorial, we will look at working with entities in the PSMODEL. We will introduce a new class within
the PowerSolutionDOTNetOLE library to help simplify how we work with the Selection list and Interact with
entities (the clsEntityType class).
We will also introduce some methods of the clsPowerSHAPEOLE class that we have not looked at so far that
make use of this new clsEntityType class.
Firstly, create a new Windows Application. For now, simply add
a Button to the form, named cmdApply, as shown
Import the example file \Examples\PowerSHAPE Tutorial 3
Examples\2d_insert.dgk into PowerSHAPE, which we will use to
test our code.

Add the reference to the PowerSolutionDOTNetOLE library, and


add the IMPORTS statement shown below

Imports PSHAPE = PowerSolutionDOTNetOLE.clsPowerSHAPEOLE


Imports PowerSolutionDOTNetOLE

5.4.1. Entity Selection


One common operation in a VB application is to work with the current selection of entities in the PSMODEL.
We will first look at the long-hand method of achieving this using the Evaluate method, and then see how
using the clsEntityType class can simplify our development.
Double click the cmdApply button to access its Click event code.
Add the following code. This will simply detect wether a single surface is selected.

Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdApply.Click
PSHAPE.Connect()
Dim SurfaceName as String
If PSHAPE.Evaluate("SELECTION.NUMBER") <> 0 Then
MsgBox("Select a single surface.")
Return
ElseIf PSHAPE.Evaluate("SELECTION.TYPE[0]") = "Surface" Then
MsgBox("A surface is not selected.")
Return
Else
SurfaceName = PSHAPE.Evaluate("SELECTION.NAME[0]")
End If
End Sub

This isnt too tedius. However you do need to remember the object information syntax, and note that we
need to check the entity type against the string Surface. If we miss-spell this, or even get the case
incorrect, our application will fail. E.g. the following two comparisons would fail

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 45 of 74

ElseIf PSHAPE.Evaluate("SELECTION.TYPE[0]") = "surface" Then


ElseIf PSHAPE.Evaluate("SELECTION.TYPE[0]") = "SURFACE" Then

Things get a lot more complicated too if instead we want to store the full list of selected entities and check
they are all a particular type of entity. Modify the cmdApply_Click event code as follows. This will store the
entity list, and then leave only the composite curves selected.

Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdApply.Click
PSHAPE.Connect()
Dim Names(-1) As String
Dim Types(-1) As String
Dim Number As Integer = PSHAPE.Evaluate("SELECTION.NUMBER")
ReDim Names(Number)
ReDim Types(Number)
For i As Integer = 0 To Number - 1
Names(i) = PSHAPE.Evaluate("SELECTION.NAME[" & i.ToString & "]")
Types(i) = PSHAPE.Evaluate("SELECTION.TYPE[" & i.ToString & "]")
Next
PSHAPE.Execute("SELECT CLEARLIST")
For i As Integer = 0 To Number - 1
If Types(i) <> "CompCurve" Then
PSHAPE.Execute("SELECT ADD " & Types(i) & " '" & Names(I) & "'")
End If
Next
End Sub

Note we need two arrays, one to store the names, the other to store the types. Similar to working the 3D
points, this can be tedious since you have to manage all of the arrays. It is easier if we have this
information stored as a single object, this is where the clsEntityType object comes in.
This object provides a way to store basic entity information, as well as providing easier methods of working
with the entity which we will see later.
Now modify the cmdApply_Click event code as follows

Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdApply.Click
PSHAPE.Connect()
Dim Entities(-1) As clsEntityType
Entities = PSHAPE.GetSelectedEntities()
PSHAPE.Execute("SELECT CLEARLIST")
For i As Integer = 0 To Entities.Length - 1
If Entities(i).Type = enum_EntityType.CompCurve Then
PSHAPE.Execute("ADD COMPCURVE '" & Entities(i).Name & "'")
End If
Next
End Sub

This much shorter block of code will do exactly the same as the previous block of code. We will look at
each part of this code

Dim Entities(-1) As clsEntityType

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 46 of 74

Here will simply declare the array of clsEntityType objects

Entities = PSHAPE.GetSelectedEntities()

Here we use the clsPowerSHAPEOLE method GetSelectedEntities. This method returns an array of
clsEntityType objects, in this case, we set the array Entities to contain this result.
At this point, we now have an array of clsEntityType objects, each member of the array will now hold basic
information on each entity.

For i As Integer = 0 To Entities.Length - 1

Here we loop through the array (we can use the Length property for the array to find out how many items
are stored).

If Entities(i).Type = enum_EntityType.CompCurve Then

Here we check the type of the entity. The Type property of the clsEntityType class will return an
Enumeration value based on the type of the entity. In other words each entity type has a NUMBER
associated with it, but to make your code clearer, these numbers are held as an enumeration (similar to a
constant). enum_EntityType.CompCurve for example is actually the number 3.
This way you avoid the potential problems we saw earlier when checking against a STRING for the entity
type.

PSHAPE.Execute("ADD COMPCURVE '" & Entities(i).Name & "'")

In this line, we use the same macro command we saw earlier, but we can get the name of the entity
directly from the clsEntityType objects Name property. We will see later how even this can be simplified by
using the SelectObject method of the clsEntity class.
5.4.2. Working with Entities
Where the clsEntityType class can be a significant aid to your programming, is when you are automating the
creation of objects, and you need to keep track of all entities you create.
Now in this tutorial will will go back to our Round Rect utility, and modify it to create a 3D block from the
composite curve we create.
Close the current project, and open the Round Rect project from Tutorial 2.
In this tutorial, we kept track of each entity we create by storing their names, e.g

Dim Lines(3) As String


PSHAPE.Execute("CREATE LINE SINGLE")
PSHAPE.Execute(TopStart.SerialisedString, TopEnd.SerialisedString(True))
Lines(0) = PSHAPE.Evaluate("SELECTION.NAME[0]")

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 47 of 74

We could use the clsEntityType object instead. After the line is created, we know it will be selected.
Therefore we can use an alternative Constructor of the clsEntityType class to quickly store this selected
object, e.g.

Dim Line As New clsEntityType(enum_ObjectList.Selection, 0)

Using this princpal, we can modify the cmdApply_Click event to store all of the entities are clsEntityType
objects instead. Modify the routine as below. The old code has been commented out so you can compare
the two methods.

Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdApply.Click
If PSHAPE.Connect() = False Then
MsgBox("Ensure PowerSHAPE is running.")
Return
End If
'Get the coordinates for the lines of the rectangle
'Validate the user input...
Dim Width, Length, Radius As Double
Try
Width = CType(txtWidth.Text, Double)
If Width <= 0 Then Throw New Exception("Width must be greater than 0")
Catch
MsgBox("Invalid width specified.")
Return
End Try
Try
Length = CType(txtLength.Text, Double)
If Length <= 0 Then Throw New Exception("Length must be greater than 0")
Catch
MsgBox("Invalid length specified.")
Return
End Try
Try
Radius = CType(txtRadius.Text, Double)
If Radius <= 0 Then Throw New Exception("Radius must be greater than 0")
Catch
MsgBox("Invalid radius specified.")
Return
End Try
If (2 * Radius) >= Length Or (2 * Radius) >= Width Then
MsgBox("The radius is too large to fit in the specified rectangle's corners.")
Return
End If
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim

TopStart As New clsPoint3D((-Length / 2) + Radius, Width / 2, 0)


TopEnd As New clsPoint3D((Length / 2) - Radius, Width / 2, 0)
RightStart As New clsPoint3D(Length / 2, (-Width / 2) + Radius, 0)
RightEnd As New clsPoint3D(Length / 2, (Width / 2) - Radius, 0)
BottomStart As New clsPoint3D((-Length / 2) + Radius, -Width / 2, 0)
BottomEnd As New clsPoint3D((Length / 2) - Radius, -Width / 2, 0)
LeftStart As New clsPoint3D(-Length / 2, (-Width / 2) + Radius, 0)
LeftEnd As New clsPoint3D(-Length / 2, (Width / 2) - Radius, 0)
TopLeftArcCentre As New clsPoint3D(TopStart.X, LeftEnd.Y, 0)
TopRightArcCentre As New clsPoint3D(TopEnd.X, RightEnd.Y, 0)
BottomLeftArcCentre As New clsPoint3D(BottomStart.X, LeftStart.Y, 0)
BottomRightArcCentre As New clsPoint3D(BottomEnd.X, RightStart.Y, 0)

Dim RectEntities(7) As clsEntityType


'Create the lines for the rectangle
'Store for the names of lines
'Dim Lines(3) As String
PSHAPE.Execute("CREATE LINE SINGLE")
PSHAPE.Execute(TopStart.SerialisedString, TopEnd.SerialisedString(True))
'Lines(0) = PSHAPE.Evaluate("SELECTION.NAME[0]")
RectEntities(0) = New clsEntityType(enum_ObjectList.Selection, 0)
PSHAPE.Execute(RightStart.SerialisedString, RightEnd.SerialisedString(True))
'Lines(1) = PSHAPE.Evaluate("SELECTION.NAME[0]")

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 48 of 74

RectEntities(1) = New clsEntityType(enum_ObjectList.Selection, 0)


PSHAPE.Execute(BottomStart.SerialisedString, BottomEnd.SerialisedString(True))
'Lines(2) = PSHAPE.Evaluate("SELECTION.NAME[0]")
RectEntities(2) = New clsEntityType(enum_ObjectList.Selection, 0)
PSHAPE.Execute(LeftStart.SerialisedString, LeftEnd.SerialisedString(True))
'Lines(3) = PSHAPE.Evaluate("SELECTION.NAME[0]")
RectEntities(3) = New clsEntityType(enum_ObjectList.Selection, 0)
PSHAPE.Execute("SELECT")
'Create the radii for the rectangle...
'Store for the names of arcs
'Dim Arcs(3) As String
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(TopLeftArcCentre.SerialisedString)
PSHAPE.Execute(LeftEnd.SerialisedString(True))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute(TopStart.SerialisedString(True))
'Arcs(0) = PSHAPE.Evaluate("SELECTION.NAME[0]")
RectEntities(4) = New clsEntityType(enum_ObjectList.Selection,
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(TopRightArcCentre.SerialisedString)
PSHAPE.Execute(TopEnd.SerialisedString(True))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute(RightEnd.SerialisedString(True))
'Arcs(1) = PSHAPE.Evaluate("SELECTION.NAME[0]")
RectEntities(5) = New clsEntityType(enum_ObjectList.Selection,
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(BottomRightArcCentre.SerialisedString)
PSHAPE.Execute(RightStart.SerialisedString(True))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute(BottomEnd.SerialisedString(True))
'Arcs(2) = PSHAPE.Evaluate("SELECTION.NAME[0]")
RectEntities(6) = New clsEntityType(enum_ObjectList.Selection,
PSHAPE.Execute("CREATE ARC SWEPT")
PSHAPE.Execute(BottomLeftArcCentre.SerialisedString)
PSHAPE.Execute(BottomStart.SerialisedString(True))
PSHAPE.Execute("CLOCKWISE")
PSHAPE.Execute(LeftStart.SerialisedString(True))
'Arcs(3) = PSHAPE.Evaluate("SELECTION.NAME[0]")
RectEntities(7) = New clsEntityType(enum_ObjectList.Selection,
PSHAPE.Execute("SELECT CLEARLIST")

0)

0)

0)

0)

'Select all created entities


'For i As Integer = 0 To 3
'
PSHAPE.Execute("ADD LINE '" & Lines(i) & "'")
'
PSHAPE.Execute("ADD ARC '" & Arcs(i) & "'")
'Next
PSHAPE.SelectEntityList(True, RectEntities)
'And finally create a composite curve...
PSHAPE.Execute("CONVERT COMPCURVE")
End Sub

In this case, we have stored all entities in the single array RectEntities. Having an array of entities, allows
us to use the clsPowerSHAPEOLE.SelectEntityList method. This method takes an array of clsEntityType
objects, and will select them all in PowerSHAPE. The first parameter specifies wether the selection is
cleared first.
e.g.
PSHAPE.SelectEntityList(True, RectEntities)

This will clear the selection, and select all entities stored in the RectEntities array
There is no performance gain to using the clsEntityType class, but it can simplify your code.
And it can be simplified even further if you want to extract object information.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 49 of 74

For example, if we wanted to extract some information regarding the final composite curve we have
created, we could use for example
Dim CurveName As String = PSHAPE.Evaluate("SELECTION.NAME[0]")
Dim CurveLength As Double
CurveLength = CType(PSHAPE.Evaluate("COMPCURVE['" & CurveName & "'].LENGTH"), Double)
Dim Pt1X, Pt1Y, Pt1Z As Double
Dim PointInfo As Object = PSHAPE.Evaluate("COMPCURVE['" & CurveName & "'].POINT[1]")
Pt1X = CType(PointInfo(0), Double)
Pt1Y = CType(PointInfo(1), Double)
Pt1Z = CType(PointInfo(2), Double)
MsgBox("Composite curve data:" & vbCrLf & _
"Length = " & CurveLength.ToString & vbCrLf & _
"Start Point = " & Pt1X.ToString("0.######") & ", " & _
Pt1Y.ToString("0.######") & ", " & _
Pt1Z.ToString("0.######"))

Here we extract the curve name, then find its length, and the coordinate of the first point.
To simplify this, we can use the clsEntityType object in a number of ways. Firstly, to store the curve itself
Dim Curve As New clsEntityType(enum_ObjectList.Selection, 0)

Note that this just saves information about the entity type and its name. It doesnt actually store any of the
object information about the curve at this point.
We can then use the GetObjectInfo method to extract the object information, e.g
Dim CurveLength As Double = Curve.GetObjectInfo("LENGTH")

What this command actually does, is automatically build up the object information command for you. Since
the clsEntityType object already has information on the object type and its name, it will automatically add
this for you, so you only need to provide the object information string itself, e.g. Length. The method will
also call the Evaluate method automatically, and return the value.
To extract 3D point object information, we can also make use of an alternative constructor of the
clsPoiint3D class, e.g
Dim Pt As New clsPoint3D(Curve, "POINT[1]")

Here we pass in the clsEntityType object, and then the object information string we require.
So the complete block of code which replaces the long-hand method at the top of the page would be
Dim Curve As New clsEntityType(enum_ObjectList.Selection, 0)
Dim CurveLength As Double = Curve.GetObjectInfo("LENGTH")
Dim Pt As New clsPoint3D(Curve, "POINT[1]")
MsgBox("Composite curve data:" & vbCrLf & _
"Length = " & CurveLength.ToString & vbCrLf & _
"Start Point = " & Pt.SerialisedString(, ","))

Note: The clsEntityType object is really just a wrapper to hide away the code you would normally use
when working with the Evaluate method. It is not linked directly to any entity in PowerSHAPE, and the
object information is not stored directly in the object.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 50 of 74

5.5. Further Examples


The Tutorials folder contains three other application for PowerSHAPE which show examples of using the
methods and classes we have covered so far.
Comments have been added to the source code to help you understand their workings.

RepointSurface
This application will smooth a surface by repointing the laterals or longitudinals in the
surface and then building a new surface from them.
You can test the application using the file Tutorial\Examples\RepointSurfaceExample.dgk

InputLaterals
Another old application revamped to VB.NET. This will insert multiple laterals or
longitudinals into a surface.
The file Tutorial\Examples\InputLateralExample.dgk can be used to test it.

TextWrapper
This utility can be used to create text wrapped along an arc, or along an existing curve.
The file Tutorial\Examples\TextWrapperExample.dgk can be used to test it.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 51 of 74

6. Working with Ini Files and The Registry


Previously available with VB6, were separate code modules which allowed you easy access to functions that
worked with INI files or the Registry.
These functions have now been enhanced and integrated into the PowerSolutionDOTNetOLE library.

6.1. INI Files


INI Files are text based files which can be used to store default settings for applications. For example,
below is a sample of the Win.INI file
[drivers]
wave=mmdrv.dll
timer=timer.drv
[mci]
[driver32]
[386enh]
woafont=app850.FON
EGA80WOA.FON=EGA80850.FON
EGA40WOA.FON=EGA40850.FON
CGA80WOA.FON=CGA80850.FON
CGA40WOA.FON=CGA40850.FON
INI Files are made up of groups, defined by a label inside of square brackets (e.g. [drivers]), followed by a
number of identifiers and values (e.g. wave=mmdrv.dll).
The PowerSolutionDOTNetOLE.clsIniFile class provides two shared methods to allow you to read and write
from such files.
You can access the methods using the full reference to PowerSolutionDOTNetOLE.clsIniFile, or you can use
the IMPORTS state to create a short-cut to them, e.g

Imports INI = PowerSolutionDOTNetOLE.clsIniFile

6.1.1. Reading From an Ini File


To read a value from a group in an INI file, you use the GetIniValue method.
This method requires 4 parameters

The path to the INI file to read from


The Group name to search within
The specific identifier for the setting to retrieve
A default value to return if the specific setting is not found

e.g

Dim Stepover As Double = INI.GetIniValue(Application.StartupPath & "\Application.ini", _


"Toolpath Options", "Stepover", CDbl(5))

Here we look for the ini file called Application.ini stored in the same path as the executable. We look for a
group called Toolpath Options, and for a setting called Stepover. Finally, we specify a default value of 1.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 52 of 74

Note that we force the type of the default value to be a double. The type of the variable you give as the
default value will determine the type of the data returned by this function. So if we simply used

Dim Stepover As Double = INI.GetIniValue(Application.StartupPath & "\Application.ini", _


"Toolpath Options", "Stepover", 5)

because 5 on its own is an integer, it would mean the value returned back would be an integer.
6.1.2. Writing to an INI File
It can be useful to allow the users settings to be stored when your application exits. In this case you can
use the WriteIniValue method with the following parameters

The
The
The
The

path to the INI file to write to


Group name to write the value within
specific identifier for the setting to write
value to write with the setting

INI.WriteIniValue(Application.StartupPath & "\Application.ini", _


"Toolpath Options", "Stepover", Stepover)

If the INI file you specify does not exist, this method will automatically create it.

6.2. The Registry


It can be useful to read from the registry in order to extract system information, for example to determine
where certain products are installed, to determine regional settings, and so on.
The registry can also be used to store default settings for an application as an alternative to using INI
Files.
The PowerSolutionDOTNetOLE.clsRegistry class contains 4 methods to help you work with the registry. You
can access these shared methods by using the full reference to PowerSolutionDOTNetOLE.clsRegistry or
setup a short-cut using for example

Imports REG = PowerSolutionDOTNetOLE.clsRegistry

6.2.1. Reading from the Registry


There are two methods for reading from the registry.
ReadRegistry
This method allows you to read from anywhere in the registry. For example to find out the current regional
setting for the decimal separator, you could use
Dim Separator As String = REG.ReadRegistry(Microsoft.Win32.Registry.CurrentUser, _
"Control Panel\International", _
"sDecimal")

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 53 of 74

The first parameter specifies the main registry group to search within, e.g. HKEY_LOCAL_MACHINE,
HKEY_CURRENT_USER, etc.
The next parameter is the path to the key you want to search within.
The final parameter is the specific variable within the key you want to extract the value from.
So the above command is checking the registry setting
[HKEY_CURRENT_USER\Control Panel\International]
"sDecimal"="."
ReadDcamRegistry
This method provides a short-hand way to read registry values from the
HKEY_LOCAL_MACHINE\SOFTWARE\Delcam region of the registry. For example to determine the version
of PowerSHAPE last installed, you could use the previous method
Dim Version As String = REG.ReadRegistry(Microsoft.Win32.Registry.LocalMachine, _
"SOFTWARE\Delcam\Exec\PowerSHAPE", _
"CurrentVersion")

Or to simplify this, use the ReadDcamRegistry method


Dim Version As String = REG.ReadDcamRegistry("Exec\PowerSHAPE", "CurrentVersion")

You simply pass the path starting from the HKEY_LOCAL_MACHINE\SOFTWARE\Delcam location.
6.2.2. Writing To The Registry
There are two methods similar to the reading from the registry methods, which can be used to write to the
registry.
WriteRegistry
This method allows you to write to any location in the registry. For example to write application settings for
the current user, you could use
REG.WriteRegistry(Microsoft.Win32.Registry.CurrentUser, _
"SOFTWARE\MyCompany\MyApplication", _
"DefaultStepover", _
Stepover)

Similar to the ReadRegistry method, we give the root group to start in, then the path to the key, next the
key value to store, and finally the value to write to it.
WriteDcamRegistry
This method can be used to write directly to the HKEY_LOCAL_MACHINE\SOFTWARE\Delcam path in the
registry, whereby you only need to specify the path relative from this location (similar to the
ReadDcamRegistry method), e.g.

REG.WriteDcamRegistry("MyApplication", _
"ToolLibraryPath", _
"d:\library\tools.mdb")

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 54 of 74

7. Working With CopyCAD


The clsCopyCADOLE class can be used to link with CopyCAD. The use of this class is similar to the
clsPowerMILLOLE and clsPowerSHAPEOLE classes, therefore this section only summarises each method
available in this class.
Firstly, we can setup a link to this class using the statement

Imports CCAD = PowerSolutionDOTNetOLE.clsCopyCADOLE

7.1. Connecting to CopyCAD


To setup the OLE connection, we use the Connect method in exactly the same way we do with the
PowerMILL and PowerSHAPE connections, e.g

CCAD.Connect()

7.2. Executing Macro Commands


To execute macro commands, we use the Execute method. As with the Execute method for PowerSHAPE
and PowerMILL, you can send a single command, or multiple commands as a list of strings, e.g..

CCAD.Execute("LIMIT
CCAD.Execute("PLANE
CCAD.Execute("PLANE
CCAD.Execute("LIMIT

TO PLANE")
SELECT Z")
POINT Z 0.05")
APPLY")

Or

CCAD.Execute("LIMIT TO PLANE", "PLANE SELECT Z", "PLANE POINT Z 0.05", "LIMIT APPLY")

7.3. Executing Macro Commands And Getting Command Window Information


This methods is similar to the ExecuteEx method in PowerMILL. This method will execute a macro
command, but also return a string containing information that was printed to the command window as a
result of the macro command.
e.g.

Dim ModelInfo As String = CCAD.ExecuteAndReturnCMDLine("MODEL EDIT PRINTSELECTED Model1")

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 55 of 74

8. Multi-Application Interfaces
In cases where you are developing an application that will work with more than one application, the
PowerSolutionDOTNetOLE library contains a method to allow you to integrate the main Delcam products
within a single VB.NET interface.
This could also be used if you wish to connect to just one application, but develop your own specific
interface for the user.
This tutorial will lead you through building an application integratiing PowerMILL and PowerSHAPE.
Firstly, start a new VB.NET Windows Application.
And Add the reference to the PowerSolutionDOTNetOLE library.

8.1. Showing an Application in a VB.NET Form


The clsProcessAquisition class wraps up the code necessary to grab ANY current process running in
Windows, and to show that processs window within a VB.NET control.
The process can be shown in any VB.NET control (e.g. the Form, a Panel, or even a command Button!!!).
Add the IMPORTS statement as below

Imports PowerSolutionDOTNetOLE

We will first show the principal by aquiring the PowerMILL window. Ensure PowerMILL is running.
Now add the following in the Declarations section of the Form code

Dim PmillAquisition As clsProcessAquisition

Double click the Form to bring up the Form_Load event code, and add the following

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


MyBase.Load
PmillAquisition = New clsProcessAquisition("pmill", Me)
End Sub

The initialisation of the PmillAquisition object here will grab the process of the name pmill, and display it in
the control Me. Me refers to the form itself, but if we want to display PowerMILL in another control,
such as a panel, we substitute the name of that control instead well see this shortly.
When you aquire an application, it will be taken from the Desktop, and shown in the control you specify.
However, when you close your VB application, it is essential you release the product back to the Desktop. If
you do not do this, when your VB application quits, any process you have grabbed will either remain
invisible, or crash.
Therefore bring up the Form1_Closing event code, and add the following

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 56 of 74

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As


System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Not PmillAquisition Is Nothing Then
PmillAquisition.ReleaseProcessToDesktop()
End If
End Sub

Here we use the ReleaseProcessToDesktop method to remove the process from our VB interface, and
display it back on the main Windows desktop.
Test the application now and you should see PowerMILL displayed within the VB form

8.2. Resizing an Application


If you try to resize your VB form, the PowerMILL window will not change. To overcome this, we can detect
when the window containing PowerMILL is resized, and then force the PowerMILL window size to match it.
Since were containing PowerMILL on the Form itself, bring up the Form1_Resize event, and add the
following

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles


MyBase.Resize
If Not PmillAquisition Is Nothing Then
PmillAquisition.SetApplicationSizeToParent()
End If
End Sub

Here we use the SetApplicationSizeToParent method. This will change the aquired products window to
match that of the control it is contained within.
Test your application now, and you should see the PowerMILL window match your application window.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 57 of 74

A small part of the window will be cropped off, but this is because the full extents of the SIZE of a form
cannot be used. Therefore it is better to add another container to your form first, such as a Panel, and to
show the external products within that.

8.3. Showing Multiple Applications


We can now use the same principal to aquire any number of external applications. A useful method of
containing more than one application is using the Tab control.
Add a tab control object to your form (named tabApplicationWindows), and set its Dock property to
FILL.
Access the TabPages collection, and add two tabs, one named tabPowerSHAPE, the other tabPowerMILL.
Then on each tab, add a Panel object, with its Dock property set to FILL. Name the panels
pnlPowerSHAPE and pnlPowerMILL, according to the tab page you place them on.
The interface should appear something like

Modify the source as follows

Imports PowerSolutionDOTNetOLE
Imports PSHAPE = PowerSolutionDOTNetOLE.clsPowerSHAPEOLE
Imports PMILL = PowerSolutionDOTNetOLE.clsPowerMILLOLE
Public Class Form1
Inherits System.Windows.Forms.Form
Dim PmillAquisition As clsProcessAquisition
Dim PshapeAquisition As clsProcessAquisition
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
PmillAquisition = New clsProcessAquisition("pmill", pnlPowerMILL)
PshapeAquisition = New clsProcessAquisition("powershape", pnlPowerSHAPE)
End Sub
'When closing the application, we MUST release the applications back to the desktop,
otherwise they will crash
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Not PshapeAquisition Is Nothing Then
PshapeAquisition.ReleaseProcessToDesktop()
End If
If Not PmillAquisition Is Nothing Then
PmillAquisition.ReleaseProcessToDesktop()
End If
End Sub

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 58 of 74

'When the parent object holding a process is resized,


'we ensure the process window is resized too
Private Sub pnlPowerSHAPE_Resize(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles pnlPowerSHAPE.Resize
If Not PshapeAquisition Is Nothing Then
PshapeAquisition.SetApplicationSizeToParent()
End If
End Sub
'When the parent object holding a process is resized,
'we ensure the process window is resized too
Private Sub pnlPowerMILL_Resize(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles pnlPowerMILL.Resize
If Not PmillAquisition Is Nothing Then
PmillAquisition.SetApplicationSizeToParent()
End If
End Sub
End Class

Ensure both PowerMILL and PowerSHAPE are running, and test your application now.
You can use the tabs to switch between PowerSHAPE and PowerMILL applications.
At this point, our application is displaying the products, but the OLE connection still has not been made. We
use the clsPowerMILLOLE and clsPowerSHAPEOLE classes as weve seen in earlier sections to work with the
products.
Add the Imports statements below

Imports PSHAPE = PowerSolutionDOTNetOLE.clsPowerSHAPEOLE


Imports PMILL = PowerSolutionDOTNetOLE.clsPowerMILLOLE

Then modify the Form_Load event code as follows

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


MyBase.Load
PmillAquisition = New clsProcessAquisition("pmill", pnlPowerMILL)
PshapeAquisition = New clsProcessAquisition("powershape", pnlPowerSHAPE)
PMILL.Connect()
PSHAPE.Connect()
'Now we hide the interfaces...
PMILL.GUIDisplayed = False
PMILL.Execute("SPLITTER TABBROWSER WIDTH 1")
PSHAPE.GUIDisplayed = False
End Sub

Here we have setup the OLE connections, and hidden the user interface from the main products.
One problem at present, is that if the products are not already running, the VB application will crash (an
Exception will be thrown).

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 59 of 74

Error Handling
There has been significant improvements in error handling with VB.NET. In VB6, we would use a
combination of On Error Resume Next and checking the Err.Number or use On Error Goto.

This can still be used in VB.NET, but the introduction of TRYCATCH blocks give greater flexibility.
You can use a TRY block to execute a block of code, and set a CATCH block with code to handle what
to do if an error occurs within the TRY block.

To handle any errors that may occur within the Form_load event, we will use a TRYCATCH block. Modify
your Form_Load event code as follows
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Try
'This will grab the process window and put it in whatever
'control you pass to the function.
'An exception will be thrown if the aquisition fails.
'So we use the TRY...CATCH block to trap for
'these errors
PshapeAquisition = New clsProcessAquisition("powershape", pnlPowerSHAPE)
PmillAquisition = New clsProcessAquisition("pmill", pnlPowerMILL)
'Note that at this point, we are simply displaying the applications.
'We haven't yet setup the OLE link
'to them. So we do that now...
PMILL.Connect()
PSHAPE.Connect()
'Now we hide the interfaces...
PMILL.GUIDisplayed = False
PMILL.Execute("SPLITTER TABBROWSER WIDTH 1")
PSHAPE.GUIDisplayed = False
Catch ex As Exception
'We ensure we release any products that have already been aquired before the
exception occurred.
If Not PshapeAquisition Is Nothing Then
PshapeAquisition.ReleaseProcessToDesktop()
PshapeAquisition = Nothing
End If
If Not PmillAquisition Is Nothing Then
PmillAquisition.ReleaseProcessToDesktop()
PmillAquisition = Nothing
End If
'Show the error message
MsgBox(ex.Message)
'End the application
End
End Try
End Sub

Here the code within the TRY block will execute, but if at any point an error occurs, the program will jump
immediately to the CATCH block.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 60 of 74

So here we attempt to aquire the application windows. If this fails, rather than our application crashing, we
handle this within the CATCH block. In this case we make sure any applications that have already been
aquired before the error occurred, are released back to the desktop, before we finally warn the user and
exit our application.
This project can be used as a starting point for any application you are developing to integrate multiple
products. The full source code can be found in the Tutorials\IntegratedApplicationExample folder.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 61 of 74

9. PowerSHAPE OLE Methods


So far we have seen how automating PowerSHAPE can be achieved by sending in the relavent macro
commands.
However there are special OLE methods built-in to PowerSHAPEs OLE object which allow us to bypass the
macro command methods, and create or manipulate entities directly.
Only a small number of the methods available are covered here.

9.1. Accessing the OLE Methods


Here we will show how to access the OLE methods using the clsPowerSHAPEOLE class.
Create a new Windows Application, and add the reference to the PowerSolutionDOTNetOLE application.
Next, add a new reference, this time browse for the file
\dcam\product\powershapeXXXX\sys\exec\PowerSHAPENT.tlb
The reference list in the VB.NET solution explorer should appear as

Add the imports statement

Imports PSHAPE = PowerSolutionDOTNetOLE.clsPowerSHAPEOLE


Imports PowerSolutionDOTNetOLE

In the general declarations section, add

Dim DOC As PowershapeNT.Document

Note that if you havent added the PowerSHAPENT.TLB reference, you will not be able to declare this type
of object. It is this typelibrary file that defines what this particular type of object contains, and allows us to
declare it in our application.
What is PowerSHAPENT.Document?
So far, when we use the Execute or Evaluate methods, we are actually working with the main PowerSHAPE
Application OLE connection. Which means once we setup the connection, any commands are associated
with PowerSHAPE, and so work with whatever model is currently active.
The PowerSHAPENT.Document object however, is linked to a specific PSMODEL open in PowerSHAPE. So
any commands we use from this object, will be applied directly to whatever model we connect to.
Therefore we have two levels of OLE connections. The main OLE connection to PowerSHAPE, and individual
OLE connections to specific models.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 62 of 74

9.2. Connecting to a PSMODEL


We must always first setup the main PowerSHAPE connection. Then we can connect to the active model.
Bring up the Form_Load event code, and add the following

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


MyBase.Load
PSHAPE.Connect()
PSHAPE.ReconnectToActiveDocument()
DOC = PSHAPE.DOCOLE
End Sub

The line
PSHAPE.ReconnectToActiveDocument

Should be used every time we want to refresh the connection to a PSMODEL. For example if you open a
new model, and want to connect to that, you should use the above command.
The line
DOC = PSHAPE.DOCOLE

connects our PowerSHAPE.Document object to the OLE connection to the PSMODEL.


We are now ready to use the methods available in the PowerSHAPE.Document object.
If you type
DOC.
You will see the list of the methods that are available,
as shown.

9.3. The Composite ID


Before we continue, we need to introduce a new concept for PowerSHAPE known as the Composite ID.
When working with entities in PowerSHAPE, we are mainly familiar with identifying an entity by its type and
its name. However internally, PowerSHAPE identifies each entity by a single integer numbe. This number is
the Composite ID. Many of the Document object methods work based on the Composite ID.
Rather than returning the name and type of an entity you create, most methods will return the Composite
ID. We will see later than the clsEntityType class can help us determine the Composite ID when we know
its name and type, or to determine the name and type of an object when we know its Composite ID.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 63 of 74

9.4. Creating Wireframe Entities


The first methods we will look at is the Create2DLine and Create2DArc methods. We will compare the
macro command method with the Document method to show the benefits of using these.
Open the example VB.NET project Tutorials\ PowerSHAPEOLEMethods
If you run this application, and click the Macro Method button. This will create 10 round rectangles at
random positions.
Once complete, clear the entities, and then click the OLE Method button. The speed increase should be
apparent.
Now to look at how we achieve this.
Look at the soure code for the cmdOLEMethod_Click event

Private Sub cmdOLEMethod_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdOLEMethod.Click
Dim RP1, RP2, RP3, RP4, RP5, RP6, RP7, RP8 As clsPoint3D
Dim RC1, RC2, RC3, RC4 As clsPoint3D
For i As Integer = 0 To 10
Dim CentreOffset As New clsPoint3D(100 * Rnd(), 100 * Rnd(), 0)
RP1 = P1.VectorAddition(CentreOffset)
RP2 = P2.VectorAddition(CentreOffset)
RP3 = P3.VectorAddition(CentreOffset)
RP4 = P4.VectorAddition(CentreOffset)
RP5 = P5.VectorAddition(CentreOffset)
RP6 = P6.VectorAddition(CentreOffset)
RP7 = P7.VectorAddition(CentreOffset)
RP8 = P8.VectorAddition(CentreOffset)
RC1 = C1.VectorAddition(CentreOffset)
RC2 = C2.VectorAddition(CentreOffset)
RC3 = C3.VectorAddition(CentreOffset)
RC4 = C4.VectorAddition(CentreOffset)
DOC.Create2DLine(RP1.X,
DOC.Create2DLine(RP3.X,
DOC.Create2DLine(RP5.X,
DOC.Create2DLine(RP7.X,
DOC.Create2DArc(RP8.X,
DOC.Create2DArc(RP2.X,
DOC.Create2DArc(RP4.X,
DOC.Create2DArc(RP6.X,

RP1.Y,
RP3.Y,
RP5.Y,
RP7.Y,
RP8.Y,
RP2.Y,
RP4.Y,
RP6.Y,

RP2.X,
RP4.X,
RP6.X,
RP8.X,
RC1.X,
RC2.X,
RC3.X,
RC4.X,

RP2.Y)
RP4.Y)
RP6.Y)
RP8.Y)
RC1.Y,
RC2.Y,
RC3.Y,
RC4.Y,

RP1.X,
RP3.X,
RP5.X,
RP7.X,

RP1.Y,
RP3.Y,
RP5.Y,
RP7.Y,

0)
0)
0)
0)

Next
PSHAPE.RebuildDisplay()
End Sub

Much of this code is just to setup the coordinates for the rectangle, setting the random position of the
points.
The first line of interest is
DOC.Create2DLine(RP1.X, RP1.Y, RP2.X, RP2.Y)

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 64 of 74

Here the Create2DLine method is used. We give four parameters, the X and Y coordinate of the start point
of the line, and the X and Y coorindate of the end point.
This will create a line in the PSMODEL we are connected to, but it creates the entity directly in the PSMODEL
database. No macro commands are involved, and even the graphics will not update, hence the signigicant
speed improvement.
The next line of interest is
DOC.Create2DArc(RP8.X, RP8.Y, RC1.X, RC1.Y, RP1.X, RP1.Y, 0)

This is used to create an arc on the XY plane. Here we give 7 parameters

X and Y
X and Y
X and Y
Either 1

coorindate of the start point of the arc.


coordinate of the centre point of the arc.
coordinate of the end point of the arc
or 0 , depending upon the direction of the arc (1 = Counter Clockwise, 0 = Clockwise)

The final line in the code


PSHAPE.Execute("DISPLAY REBUILD")

Is the only time we use a macro command, and this will rebuild the display. We must do this in order to
see the new entities we have created with the OLE methods.

Now click the Create Curve button. This will create a single round rectangle, but convert it to a composite
curve.
Now look at the cmdCreateCurve_Click source code
Private Sub cmdCreateCurve_Click(ByVal sender
System.EventArgs) Handles cmdCreateCurve.Click
Dim LineIds(3) As Integer
LineIds(0) = DOC.Create2DLine(P1.X, P1.Y,
LineIds(1) = DOC.Create2DLine(P3.X, P3.Y,
LineIds(2) = DOC.Create2DLine(P5.X, P5.Y,
LineIds(3) = DOC.Create2DLine(P7.X, P7.Y,
Dim ArcIds(3) As Integer
ArcIds(0) = DOC.Create2DArc(P8.X,
ArcIds(1) = DOC.Create2DArc(P2.X,
ArcIds(2) = DOC.Create2DArc(P4.X,
ArcIds(3) = DOC.Create2DArc(P6.X,

P8.Y,
P2.Y,
P4.Y,
P6.Y,

As System.Object, ByVal e As

P2.X,
P4.X,
P6.X,
P8.X,

C1.X,
C2.X,
C3.X,
C4.X,

P2.Y)
P4.Y)
P6.Y)
P8.Y)

C1.Y,
C2.Y,
C3.Y,
C4.Y,

P1.X,
P3.X,
P5.X,
P7.X,

P1.Y,
P3.Y,
P5.Y,
P7.Y,

0)
0)
0)
0)

Dim Ids(7) As Object


Ids(0) = ArcIds(0)
Ids(1) = LineIds(0)
Ids(2) = ArcIds(1)
Ids(3) = LineIds(1)
Ids(4) = ArcIds(2)
Ids(5) = LineIds(2)
Ids(6) = ArcIds(3)
Ids(7) = LineIds(3)
Dim VarIds As Object = Ids
DOC.CreateCompositeCurve(Ids.Length, VarIds, 1, 1)
PSHAPE.Execute("DISPLAY REBUILD")
End Sub

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 65 of 74

Notice that for each entity we create, we store an integer value (the Composite ID of the entity).
We need to use the CreateCompositeCurve OLE method, specifying the Composite IDs of the entities to
create the composite curve from, but first we must setup the data correctly.
1. The array must list the entities in the correct order to form a valid composite curve
2. We must ensure the entities are already in a consistent direction
3. We must pass the list of entities as a VARIANT object
So to achieve this, we first setup an array of VARIANTS to hold the 8 composite IDs making up our
rectangle
Dim Ids(7) As Object

We then populate this array in the correct order for the composite curve. I.e. Top left arc, top line, top
right arc, right line, bottom right arc, bottom line, bottom left arc, left line.
Ids(0)
Ids(1)
Ids(2)
Ids(3)
Ids(4)
Ids(5)
Ids(6)
Ids(7)

=
=
=
=
=
=
=
=

ArcIds(0)
LineIds(0)
ArcIds(1)
LineIds(1)
ArcIds(2)
LineIds(2)
ArcIds(3)
LineIds(3)

We then define a single VARIANT object linked to this array


Dim VarIds As Object = Ids

And then we can call the CreateCompositeCurve method, retrieving its Composite ID too
Dim CurveID As Integer = DOC.CreateCompositeCurve(Ids.Length, VarIds, 1, 1)

We give 4 parameters
The number of entities to build the composite curve from
The variant object containing the array of composite ids
A flag to mark wether the curve is closed (1 = Closed, 0 = Open)
A flag to mark wether the curve is planar (1 = planar, 0 = none-planar)
And we REBUILD the DISPLAY so we can see the results.
If we wanted to work with this entity using normal macro commands, we need to know its type and name,
since macro commands do not work with Composite IDs. In this case the final two lines show how we can
use one of the contructors of the clsEnitityType class to convert from any Composite ID to the familiar
format of entity type and name.
Dim CurveEntity As New clsEntityType(CurveID)
MsgBox("The new curve is called '" & CurveEntity.Name & "'")

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 66 of 74

9.5. Creating Solid Entities


There are a number of OLE methods to allow us to create solid primitive entities, and these give the same
significant speed improvements as the previous wireframe OLE methods.
Run the application, and click the Create Solids button. 50 solids of various types will be created in random
positions.
Bring up the code for the cmdCreateSolids_Click event
The first section just sets up a random temporary workplane
'Setup the temporary workplane information for our new primitive
'Get a random origin
Dim Origin As New clsPoint3D(100 * Rnd(), 100 * Rnd(), 100 * Rnd())
'Get a random Z axis
Dim ZAxis As New clsPoint3D(Rnd, Rnd, Rnd)
'Make sure the Z axis is a unit vector
ZAxis.ConvertToUnitVector()
'From the Z Axis clsPoint3D object, we can calculate suitable
'X and Y axes using the clsPoint3D.GetXYVectors method
Dim XAxis, Yaxis As clsPoint3D
ZAxis.GetXYVectors(XAxis, Yaxis)

We use the clsPoint3D object to store the Origin, X, Y and Z Axes.


Various OLE methods require workplane information to specify where the entity will be created. The way
we specify this workplane information is the same for all methods.
The information must be supplied as a Variant object, this object consisting of an array made up of the
Origin, Z axis and Y axis. This is shown in the code

Dim Wkpl(8) As Object


Wkpl(0) = Origin.X
Wkpl(1) = Origin.Y
Wkpl(2) = Origin.Z
Wkpl(3) = ZAxis.X
Wkpl(4) = ZAxis.Y
Wkpl(5) = ZAxis.Z
Wkpl(6) = Yaxis.X
Wkpl(7) = Yaxis.Y
Wkpl(8) = Yaxis.Z
'Then setup a single variant object linked to this array...
Dim VarWkpl As Object = Wkpl

Once we have this workplane object defined, we can use the various solid creation methods.
To create a cylinder, we give the workplane position information, and the radius and length.
DOC.CreateCylinder(VarWkpl, 10, 30)

To create a block, we give the workplane position, and the length, width and height of the block.
DOC.CreateBlock(VarWkpl, 15, 10, 4)

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 67 of 74

To create a cone, we give the workplane information, the base radius, top radius, and the height.
DOC.CreateCone(VarWkpl, 10, 4, 4)

To create a torus, we give the workplane information, the major and minor radii.
DOC.CreateTorus(VarWkpl, 20, 2)

To create a plane, we give the workplane position, the length, and the width.
DOC.CreatePlane(VarWkpl, 5, 8)

9.6. Solid Booleans


As well as creating solid entities, we can perform boolean operations between solids entities too.
Run the application, and click the Solid Boolean button. Here you will see a solid model built.
Look at the cmdSolidBoolean_Click event code

Private Sub cmdSolidBoolean_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles cmdSolidBoolean.Click
Dim ZAxis As New clsPoint3D(0, 0, 1)
Dim YAxis As New clsPoint3D(0, 1, 0)
Dim Wkpl(8) As Object
Wkpl(3) = ZAxis.X
Wkpl(4) = ZAxis.Y
Wkpl(5) = ZAxis.Z
Wkpl(6) = YAxis.X
Wkpl(7) = YAxis.Y
Wkpl(8) = YAxis.Z
Dim VarWkpl As Object
'Set the local origin for the plate solid
Dim PlateOrigin As New clsPoint3D(0, 0, 0)
Wkpl(0) = PlateOrigin.X
Wkpl(1) = PlateOrigin.Y
Wkpl(2) = PlateOrigin.Z
VarWkpl = Wkpl
'Create the solid block for the plate
Dim BlockID As Integer = DOC.CreateBlock(Wkpl, 100, 50, 30)
'Set the origin for the pocket solid
Dim PocketOrigin As New clsPoint3D(0, 0, 10)
Wkpl(0) = PocketOrigin.X
Wkpl(1) = PocketOrigin.Y
Wkpl(2) = PocketOrigin.Z
VarWkpl = Wkpl
'Create the pocket solid we will remove later
Dim PocketID As Integer = DOC.CreateBlock(Wkpl, 50, 30, 20.5)
'Create the cylinders for the solid holes
Dim HoleIDs(3) As Integer
For i As Integer = 0 To 3
'Set the origin for each hole
Dim HoleOrigin As New clsPoint3D(0, 0, -0.5)
If i = 0 Then
HoleOrigin.X = -40
HoleOrigin.Y = 15
ElseIf i = 1 Then
HoleOrigin.X = -40

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 68 of 74

HoleOrigin.Y = -15
ElseIf i = 2 Then
HoleOrigin.X = 40
HoleOrigin.Y = 15
ElseIf i = 3 Then
HoleOrigin.X = 40
HoleOrigin.Y = -15
End If
Wkpl(0) = HoleOrigin.X
Wkpl(1) = HoleOrigin.Y
Wkpl(2) = HoleOrigin.Z
VarWkpl = Wkpl
'Create the cylinders to create the holes from
HoleIDs(i) = DOC.CreateCylinder(Wkpl, 4, 31)
Next
'We
'We
'We
Dim

now do the boolean operations...


pass in the composite ID of the main solid, and the solid to remove from it.
store the ID of the new resulting solid
MasterId As Integer = DOC.SubtractObject(BlockID, PocketID)

'And repeat for the holes...


For i As Integer = 0 To 3
MasterId = DOC.SubtractObject(MasterId, HoleIDs(i))
Next
'And rebuild the display to see the results...
PSHAPE.Execute("DISPLAY REBUILD")
End Sub

The first part of this routine simply uses the OLE methods weve seen already to create the solid entities.
The first line of interest is

Dim MasterId As Integer = DOC.SubtractObject(BlockID, PocketID)

Here we use the SubtractObject method. This does a solid removal. We specify the main solids Composite
ID, and then the Composite ID of the solid to remove from it. One advantage of using this method (as well
as speed), is that it will work with inactive solids.
We also store the Composite ID of the new solid created as a result of the boolean operation.
The following code loops through each of the cylinders and removes them from the master solid
For i As Integer = 0 To 3
MasterId = DOC.SubtractObject(MasterId, HoleIDs(i))
Next

For other boolean operations, the procedure is identical, but using the
methods.

IntersectObject,

and

AddObject

9.7. Summary
Only a small number of the OLE methods have been covered here. Although the principal for using the
other available methods is similar to that above.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 69 of 74

10. Deploying your VB.NET Applications


In VB6, you may have used the Package and Deployment Wizard to build installation packages for your
applications.
VB.NET provides a much enhanced tool to make the building of installation packages.
One major advantage of VB.NET, is that you can add an installation project to your application solution, and
have VB.NET build the installation automatically when you build your VB.NET code.

10.1. Adding an Installation Project


Open any VB.NET application created so far when working through the tutorials.
In the notes below, we work with the tutorial in Tutorials\PowerSHAPE_Tutorial_3b.
Right click on the Solution node in the project Solution Explorer window, and
select Add, New Project.

From the Add New Project dialog, select Setup and


Deployment Projects, Setup Wizard.
Click the Browse button, and set the directory to the directory
where your main application is saved.
Then set the Name of the setup project, e.g. Round Rectangle
Install.
Click OK.

The Setup Project Wizard will begin.


Click Next.
Select the option to create a setup for a windows application
Then click Next.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 70 of 74

Next, select what you want to actually build the install for. Usually
the only option you need to select is the Primary Output from your
application (i.e. the executable). So check this option.
If you also want to include the Source code for your application to
be installed along with the executable, you can do so by checkinhg
the Source Files option.
Click Next.

From the next page, you can select additional files to include. This
could be help files, INI files, or any files necessary to make your
application run.
Use the ADD button to select the files to include in the installation.
Then click Next.

When the final page of the wizard appears, click the Finish button.
The install project will now appear in the solution along with your application.
Notice that the Detected Dependencies node shows any additional DLLs or
references required to make your application run. These dependencies will be
automatically packaged along with your application.
In this case, the PowerSolutionDOTNetOLE.dll will be intalled along with our
application.
Notice the icon beside the dotnetfxredist_x86 dependency. This shows that
this particular dependency will not actually be distributed with your application.
This particular dependency will appear with all your VB.NET applications, and is
actually the .NET framework. This cannot be packaged automatically with your
application, and must be installed separately before you can install your
application.
Therefore when distributing any applications to customers, you should either send then the .NET framework
redistributable separately, or ensure the customer installs this manually via the Microsoft Windows Update
web site.
If the customer does not have the .NET framework installed and attempts to run a VB.NET installation, a
warning will also appear directing them to the URL from which they can download and install it.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 71 of 74

10.2. Customising the Installation


You can change the properties to change the way the installation appears.
Click on the main node for the install project in the solution explorer

Then check the properties window


Here you can change information such as the Product Name that will
appear when the install runs, as well as entering support or contact
information.

Right click on the main project node and select, View, File System.

The main window will show a layout of what is actually going to be included in the install

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 72 of 74

The Application Folder folder shows what files will be installed. You can drag and drop additional files into
this window, or even create sub-folder structures that will be setup automatically when the installation is
run.
The Users Desktop Folder (which is blank by default), can be used to specify what will be placed on the
desktop during the install. For example you can create short-cuts to the Primary Output from your
application.
The Users Program Menu folder allows you to setup the menu structure in the START->PROGRAMS menu,
allowing you to setup short-cuts to your application.
Click on the Users Program Menu node.
The right hand panel will be blank by default.
Right click in this panel and select Add, Folder
Change the name of this to Delcam

This will now update the left hand tree.

Right click on the Delcam node, and choose Add, Folder again, and change the name to Round Rectangle.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 73 of 74

Then click on this new Round Rectangle node.


In the right hand panel, right click and select
You now need to select what the short-cut is linked to.

From the Select Item In Project box, open the


Application Folder, and select the Primary output
option, followed by OK.
You can then rename the name of the short-cut as
it will appear in the users menu.

10.3. Building the Installation


You are now ready to build the installation. Right click the Install project
in the solution explorer, and select, Build.

Note that your main application will be rebuilt automatically first too.
You can test the installation from with VB.NET by right clicking on the install project and selecting, Install.

However, at present the build-mode for the application is set to DEBUG. This is shown in
the drop down list on the main toolbar
This mode should be used while you are developing. This mode allows you to step through your code and
debug any run-time errors etc.
However this mode makes the executable larger, and also slower to execute (especially noticable if reading
and writing from files or doing lots of mathematical calculations).
Therefore when you have finished development, before building the installation, change to
Release mode.
Now rebuild the installation.
The files you need to distribute for the installation will be contained in a sub-folder called Release within
the folder that you created the Install Project itself.

PowerSolution Automation
From VB6 To VB.NET

Copyright 2005 Delcam plc


Small Heath Business Park
Birmingham, B10 0HJ, United Kingdom

Print Date: 11/07/2005


Page 74 of 74

Вам также может понравиться