Using VBdotNET With PowerSolution Products
Using VBdotNET With PowerSolution Products
NET
Contents
Page
1.
Introduction
2.
Requirements
What is the .NET Framework?
Installing PowerSolutionDOTNetOLE
Accessing Help
3.
4.
Introduction
5.
6.
7.
PowerMILL Tutorial 1
PowerMILL Tutorial 2
22
31
Introduction
31
32
38
45
Further Examples
51
52
Ini Files
52
The Registry
54
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
58
62
62
Connecting to a PSMODEL
63
The Composite ID
63
64
67
Solid Booleans
68
Summary
69
PowerSolution Automation
From VB6 To VB.NET
56
70
70
72
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.
PowerSolution Automation
From VB6 To VB.NET
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.
PowerSolution Automation
From VB6 To VB.NET
button.
PowerSolution Automation
From VB6 To VB.NET
PowerSolution Automation
From VB6 To VB.NET
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
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.
PowerSolution Automation
From VB6 To VB.NET
You can then access the classes directly using the short-cut you define.
e.g.
PowerSolution Automation
From VB6 To VB.NET
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
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
PowerSolution Automation
From VB6 To VB.NET
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
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
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")
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.
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.
PowerSolution Automation
From VB6 To VB.NET
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
PowerSolution Automation
From VB6 To VB.NET
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
PowerSolution Automation
From VB6 To VB.NET
Here we are using the name of the active toolpath we retrieved earlier, and storing the extents in the 6
Double variables.
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
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.
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.
PowerSolution Automation
From VB6 To VB.NET
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).
'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
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
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
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
PowerSolution Automation
From VB6 To VB.NET
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
PowerSolution Automation
From VB6 To VB.NET
PowerSolution Automation
From VB6 To VB.NET
End If
NewToolpaths(NewToolpaths.Length - 1) = New_Names(i)
Next
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
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
PMILL.ConnectToNew()
To Hide PowerMILL
PMILL.Visible = False
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
PMILL.GUIDisplayed = False
PMILL.Execute("SPLITTER TABBROWSER WIDTH 1")
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
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.
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
PowerSolution Automation
From VB6 To VB.NET
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
PowerSolution Automation
From VB6 To VB.NET
Access the Click event code for the cmdApply button. Then add the following
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
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
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
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
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
More
Info.
Tutorial 1
Tutorial 1
Tutorial 1
Tutorial 3
View the code for the project, and add the IMPORTS statement below to link to the clsPowerSHAPEOLE
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
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.
Add the following to the Apply button click event code to create the rectangle.
PowerSolution Automation
From VB6 To VB.NET
PowerSolution Automation
From VB6 To VB.NET
PowerSolution Automation
From VB6 To VB.NET
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.
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.
PowerSolution Automation
From VB6 To VB.NET
PowerSolution Automation
From VB6 To VB.NET
X, Y, Z As Double
10
50
35
To save on the amount of typing, add to the Declarations section of your code
Imports PowerSolutionDOTNetOLE
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
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
PowerSolution Automation
From VB6 To VB.NET
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
PowerSolution Automation
From VB6 To VB.NET
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()
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)
PowerSolution Automation
From VB6 To VB.NET
P1.GetPolar(Angle, Radius)
Dim Angle As Double, Radius As Double
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)
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
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
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
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
PowerSolution Automation
From VB6 To VB.NET
Compare this with the code you would need using the Evaluate method!!!
PowerSolution Automation
From VB6 To VB.NET
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
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.
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
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
PowerSolution Automation
From VB6 To VB.NET
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.
Here we loop through the array (we can use the Length property for the array to find out how many items
are stored).
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.
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
PowerSolution Automation
From VB6 To VB.NET
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.
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.
PowerSolution Automation
From VB6 To VB.NET
0)
0)
0)
0)
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
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
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
e.g
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
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
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
If the INI file you specify does not exist, this method will automatically create it.
PowerSolution Automation
From VB6 To VB.NET
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")
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
CCAD.Connect()
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")
PowerSolution Automation
From VB6 To VB.NET
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.
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
Double click the Form to bring up the Form_Load event code, and add the following
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
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
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
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.
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
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
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
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
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
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
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
PowerSolution Automation
From VB6 To VB.NET
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
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)
X and Y
X and Y
X and Y
Either 1
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)
PowerSolution Automation
From VB6 To VB.NET
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)
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
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
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)
PowerSolution Automation
From VB6 To VB.NET
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
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
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
PowerSolution Automation
From VB6 To VB.NET
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
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
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
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
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