PowerMILL User Guide
PowerMILL User Guide
PowerMILL User Guide
www.delcam-services.com
Acknowledgements
This documentation references a number of registered trademarks and these are the
property of their respective owners. For example, Microsoft and Windows are either
registered trademarks or trademarks of Microsoft Corporation in the United States.
Contents
Custom Software Core ........................................................................................... 1
Introduction ............................................................................................................. 4
What is Custom Software Core? ................................................................... 4
Installing CSC ................................................................................................ 5
Learning to code with CSC ............................................................................ 6
Examples .............................................................................................................. 18
Introduction
What is Custom Software Core?
Custom Software Core, hereafter referred to as CSC, is an easy to use coding
alternative to direct use of the macro language supplied by PowerSHAPE and
PowerMILL.
The power of CSC can be harnessed from within the Microsoft Visual Studio
programming environment and used for creating both Delcam Automation addins and
standalone executables. The programmer can choose to develop in either C# or VB.net.
Advantages of the CSC approach to application development are as follows:
The developer is able to leverage all of the power provided by the VB.net and C#
programming languages.
Notes have been written in both C# and VB.net and have been colour coded as
follows:
C#
VB.net
You will need a licensed copy of Microsoft Visual Studio 2010 or later to make use
of Custom Software Core
We recommend that, if running a 32Bit version of PowerMILL, you compile your
applications as 32Bit; likewise, if you are running a 64Bit version of PowerMILL,
compile in 64Bit.
Installing CSC
Ensure you have downloaded the CSC installer onto your PC from the Delcam website,
a link to which can be found in the same location as the link for this document.
http://www.delcam.com/downloads/custom-core/index.asp
To install the software, double click the installer and follow the instructions as required.
Once your install is complete, you must ensure you have extracted and saved the
example files for CSC in an accessible location on your local drive before proceeding.
These files will be used throughout the remainder of the documentation.
Creating a Project
1
Select Visual C# or Visual Basic (based on your preference) from the options on
the left, then select Console Application (Figure 1).
Your main project source file will contain the following code:
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;
namespace Example1
{
class Program
{
static void Main(string[] args)
{
}
}
}
Module Module1
Sub Main()
End Sub
End Module
The next step is to set references to custom software core. Figure 2 shows a
reference diagram detailing the dependencies for each reference.
Delcam.Utilities
Delcam.Geometry
Delcam.ProductInterface
Delcam.ProductInterface.
PowerSHAPE
Delcam.ProductInterface.
PowerMILL
To add the required references, right click on References within your solution in the
Solution Explorer on the left and then select Add then Reference (Figure 3).
From within the window that now appears, select Assemblies and then Extensions
from the list.
Delcam.Geometry
Delcam.ProductInterface
Delcam.ProductInterface.PowerMILL
Delcam.Utilities
With the references added, insert the following using directive at the top of your
source file:
using Delcam.ProductInterface.PowerMILL;
Imports Delcam.ProductInterface.PowerMILL
Connecting to PowerMILL
The following section demonstrates how CSC can be used to communicate with a
running instance of PowerMILL.
1
To access the PowerMILL instance, add the following line to the main method of
your source file:
PMAutomation powerMill = new PMAutomation
(Delcam.ProductInterface.InstanceReuse.UseExistingInstance);
Dim powerMill As New PMAutomation(Delcam.ProductInterface.
InstanceReuse.UseExistingInstance)
While typing this line IntelliSense gives a number of options. For example,
after InstanceReuse we have options to: create a new instance (in addition to
any existing instance of PowerMILL); Create a single instance (close any
PowerMILL instances already open and create a new one) or
UseExistingInstance (attach to a running instance of PowerMILL) see Figure 4.
Now attach to the PowerMILL active project by adding the following code to the
main method of your source file:
The PMProject object (session) can now be used to perform a number of operations
on PowerMILL (Figure 5).
At this point it may be desirable to disable PowerMILL dialogs so that code is free to
run without user prompts.
powerMill.DialogsOff();
powerMill.DialogsOn();
powerMill.DialogsOff()
powerMill.DialogsOn()
Importing/Exporting a Model
To import a solid/surface, create a Delcam.FileSystem.File object and add this to the
session.
1
Cylinder.dgk will be located in the path to which you extracted your example
files earlier and may be different to that specified above.
2
Operations can now be performed upon the model. For example, should you wish to
find the maximum size of the model in X, use the bounding box method shown
here:
Delcam.Geometry.MM sizeX = myModel.BoundingBox.MaxX;
Dim sizeX As Delcam.Geometry.MM = myModel.BoundingBox.MaxX
If we wished to select the model (to perform an operation only on selected items,
for example) we can use the code:
myModel.AddToSelection(true);
myModel.AddToSelection(True)
This method can also be applied to importing a DMT file as a block to machine
using:
session.CreateBlock(blockFile);
session.CreateBlock(blockFile)
Assume there exists within the session a single tool about which you require
information. Firstly you must instantiate a PMTool object within your code and
assign to it the tool about which information is required. This is achieved with the
following code:
PMTool tool = session.Tools[0];
Dim tool As PMTool = session.Tools(0)
You will need to know the index of the tool to create an instance of it or,
alternatively, the name of the tool, which can be used to achieve the same
result thus: session.Tools.get_Item(<name>).
2
We are now able to perform a number of operations on the tool; for example, we
can change the diameter of the tool as follows:
tool.Diameter = 20.0;
tool.Diameter = 20.0
Alternatively, if you want to know the diameter of the tool, use the following:
Delcam.Geometry.MM toolDiam = tool.Diameter;
Dim toolDiam As Delcam.Geometry.MM = tool.Diameter
You will need to know the index of the toolpath to create an instance of it or,
alternatively, the name of the toolpath, which can be used to achieve the
same result thus: session.Toolpaths.get_Item(<name>).
5
We are now able to perform a number of operations on the toolpath; for example,
we can set the name of the toolpath using:
toolpath.Name = "Key Toolpath";
toolpath.Name = "Key Toolpath"
To check if the toolpath has been calculated and to calculate it if it has not, use the
following:
if (toolpath.IsCalculated == false)
{
toolpath.Calculate();
}
If toolpath.IsCalculated = False Then
toolpath.Calculate()
End If
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;
Delcam.ProductInterface.PowerMILL;
namespace PMillWalkthrough
{
class Program
{
static void Main(string[] args)
{
PMAutomation powerMill = new
PMAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance)
;
}
}
}
Imports Delcam.ProductInterface.PowerMILL
Module Module1
Sub Main()
Dim powerMill As New
PMAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance)
End Sub
End Module
Now load a PowerMILL project and create a PMProject object with which to
manipulate it.
Delcam.FileSystem.Directory projectDirectory = new
Delcam.FileSystem.Directory(@"C:\Custom Software Core Data\CSC
PowerMILL Examples\Boundary Example");
powerMill.LoadProject(projectDirectory);
PMProject session = powerMill.ActiveProject;
Dim projectDirectory As New Delcam.FileSystem.Directory("C:\Custom
Software Core Data\CSC PowerMILL Examples\Boundary Example")
powerMill.LoadProject(projectDirectory)
Dim session As PMProject = powerMill.ActiveProject
The Boundary Example folder will be located in a path relative to that which you
extracted your example files to earlier and may be different to that specified
above.
3
Now initialise a CSC boundary object with the single boundary available in the
PowerMILL project.
PMBoundary myBoundary = session.Boundaries[0];
Dim myBoundary As PMBoundary = session.Boundaries(0)
You will need to know the index of the boundary to create an instance of it or,
alternatively, the name of the boundary, which can be used to achieve the
same result thus: session.Boundaries.get_Item(<name>).
5
Now import from file the boundary that is to be used. This may be accomplished
using the following code:
Delcam.FileSystem.File boundaryPath = new
Delcam.FileSystem.File(@"C:\Users\asr\Desktop\Custom Software Core
Data\CSC PowerMILL Examples\BoundaryFile.dgk");
myBoundary.InsertFile(boundaryPath);
Dim boundaryPath As New
Delcam.FileSystem.File("C:\Users\asr\Desktop\Custom Software Core
Data\CSC PowerMILL Examples\BoundaryFile.dgk")
myBoundary.InsertFile(boundaryPath)
BoundaryFile.dgk will be located in the path to which you extracted your example
files earlier and may be different to that specified above.
6
With the new boundary applied, create an instance of the toolpath and calculate it:
PMToolpath myToolpath = session.Toolpaths[0];
myToolpath.Calculate();
Dim myToolpath As PMToolpath = session.Toolpaths(0)
myToolpath.Calculate()
To issue a macro command to create a blank pattern, for example, use the
following:
powerMill.Execute("CREATE PATTERN ;");
powerMill.Execute("CREATE PATTERN ;")
Alternatively you may wish to acquire information from PowerMILL to use within
your program. If, for example, you wished to retrieve the units PowerMILL is
currently running in, issue the following:
powerMill.ExecuteEx("PRINT PAR TERSE Units");
powerMill.ExecuteEx("PRINT PAR TERSE Units")
It is now possible to create in code an instance of the PowerMILL object that was
created with the macro command. If, for example, it was required to create a tool
within PowerMILL using a macro command and then instantiate the new tool in
code, the following could be used:
powerMill.Execute("CREATE TOOL ; ENDMILL FORM TOOL");
powerMill.Execute("EDIT TOOL '1' DIAMETER '12.0'");
powerMill.Execute("TOOL ACCEPT");
session.Refresh();
PMTool tool = session.Tools[0];
powerMill.Execute("CREATE TOOL ; ENDMILL FORM TOOL")
powerMill.Execute("EDIT TOOL '1' DIAMETER '12.0'")
powerMill.Execute("TOOL ACCEPT")
session.Refresh()
Dim tool As PMTool = session.Tools(0)
Deploying Solutions
Once your development is complete, you will need a way of deploying your
application to end users. This section will guide you through the process of creating
an installer. Note that the end user will require a licensed copy of CSC installed on
their target system in order to execute your application.
1
Begin by ensuring that the Microsoft Visual Studio Installer Projects extension is
installed within your copy of Microsoft Visual Studio. If not, select Tools followed by
Extensions and Updates; now locate the extension from within the resulting
window and install it.
Next, right click on your solution and select Add then New Project (Figure 6).
Select Other Project Types followed by Visual Studio Installer from the left-handside of the new window; then select Setup Project.
Now configure a Manufacturer and Product Name. Select Setup1 from within
Solution Explorer and edit the Manufacturer and ProductName fields in the
Properties tab as demonstrated in figure 7. Note: If the Properties tab is not visible,
select it from the View menu.
Right click the Application Folder from within the File System window to the right of
Solution Explorer. Select Add and then select Project Output from the resultant
context menus (Figure 8).
If you cannot see the File System window, select File System Editor from the
Solution Explorer toolbar (Figure 9).
From the dialog box, select Primary Output and click Ok.
You will notice references appear in the right hand box (Figure 10).
As it is a requirement that the end user install CSC, the Delcam references are not
required and should be excluded from the project. Select each in turn and set
Exclude to True in the Properties tab.
If it is desired to add a shortcut to the start menu then right click Users Programs
Menu and select Add followed by Folder; name the folder appropriately (Figure
11).
10 Right click the newly created folder and select Create New Shortcut.
11 Select the new folder and, in the empty panel to the right, right click and select
Create new shortcut.
12 In the resulting dialog, double click the Application Folder and select the item
starting with Primary output from Rename it to whatever you wish.
13 To create the installer, right click Setup1 from within Solution Explorer and select
Build. Once the operation has completed, browse to the location of the solution on
the local drive, open Setup1 and then browse to either the Release or Debug folder
- depending upon your solution settings and the installer will be available therein.
Examples
Example 1 - Using Template Files
You will often find it is easier to work with PowerMILL templates containing
predefined tools, patterns and toolpaths rather than creating these items from
macro code. Using this method will mean you can make simple changes to your
template such as changing a tool diameter and this new information will be applied
every time you run your macro rather than having to edit the code behind. As an
example we will look at starting a new session, opening a template that contains a
number of toolpaths with settings previously determined and a tool , importing a
model and re-calculating toolpaths and exporting the NC code.
1
Select Insert from the PowerMILL main menu and Template Object from the dropdown. From within the resulting dialog, browse the location to which was extracted
the supplied sample data and select Template_Example.ptf. Click Open.
From within the PowerMILL explorer tree, open the preferences form for NC
programs and set the Output Folder to a location on your desktop. All other
preferences will be set from within code.
Save the template by selecting File from the PowerMILL main menu and Save
Template Objects from the drop-down. Specify a filename and location to which to
save the template file. This can be the same as the original if so desired.
Create a new console application project and save it to a location of your choice.
Delcam.Geometry
Delcam.ProductInterface
Delcam.ProductInterface.PowerMILL
Delcam.Utilities
Add the following using directive to the top of the source file containing the main
method.
using Delcam.ProductInterface.PowerMILL;
Imports Delcam.ProductInterface.PowerMILL
When you run your code make sure PowerMILL is open as we have chosen to
use an existing instance rather than open a new one.
10 Attach to the PowerMILL active project by adding the following code to the main
method of the source file:
PMProject session = powerMILL.ActiveProject;
Dim session As PMProject = powerMILL.ActiveProject
15 Now calculate each toolpath in the template and set the correct rapid heights by
cycling through each toolpath in turn:
foreach (PMToolpath toolpath in session.Toolpaths)
{
toolpath.IsActive = true;
toolpath.Calculate();
powerMILL.Execute("FORM TOOLZHEIGHTS");
powerMILL.Execute("EDIT TOOLPATH SAFEAREA RESET");
powerMILL.Execute("RESET TOOLPATH RAPID");
powerMILL.Execute("TOOLZHEIGHTS ACCEPT");
toolpath.IsActive = false;
}
For Each toolpath As PMToolpath In session.Toolpaths
toolpath.IsActive = True
toolpath.Calculate()
powerMILL.Execute("FORM TOOLZHEIGHTS")
powerMILL.Execute("EDIT TOOLPATH SAFEAREA RESET")
powerMILL.Execute("RESET TOOLPATH RAPID")
powerMILL.Execute("TOOLZHEIGHTS ACCEPT")
toolpath.IsActive = False
Next
16 Each toolpath can now be posted. This will be accomplished by assigning sequential
names through use of a counter:
Int64 count = 1;
Dim count As Integer = 1
17 Since the NC programs already exist within the session, we need only give them an
option file, an output workplane, a name and then write them:
foreach (PMNCProgram sNCProgram in session.NCPrograms)
{
sNCProgram.MachineOptionFileName = @"C:\CSC PowerMILL
Examples\DMU160P_S840D_JM_Rev7.pmoptz";
sNCProgram.OutputWorkplaneName = "OWP";
sNCProgram.Name = "O00" + count.ToString();
sNCProgram.Write();
count = count + 1;
}
For Each sNCProgram As PMNCProgram In session.NCPrograms
sNCProgram.MachineOptionFileName = "C:\CSC PowerMILL
Examples\DMU160P_S840D_JM_Rev7.pmoptz"
sNCProgram.OutputWorkplaneName = "OWP"
sNCProgram.Name = "O00" + count.ToString()
sNCProgram.Write()
count = count + 1
Next
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;
Delcam.ProductInterface.PowerMILL;
namespace UsingTemplateFiles
{
class Program
{
static void Main(string[] args)
{
PMAutomation powerMILL = new
PMAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance)
;
PMProject session = powerMILL.ActiveProject;
powerMILL.DialogsOff();
Delcam.FileSystem.Directory savePath = new
Delcam.FileSystem.Directory(@"C:\Users\asr\Desktop\CSC PowerMILL
Examples\TemplateSession");
Delcam.FileSystem.File pTemplate = new
Delcam.FileSystem.File(@"C:\Users\asr\Desktop\CSC PowerMILL
Examples\Template_Example.ptf");
session.ImportTemplateFile(pTemplate);
session.Initialise();
Delcam.FileSystem.File modelPath = new
Delcam.FileSystem.File(@"C:\Users\asr\Desktop\CSC PowerMILL
Examples\Pocket-Feature.dgk");
PMModel myModel = session.Models.CreateModel(modelPath);
myModel.AddToSelection(true);
powerMILL.Execute("FORM BLOCK");
powerMILL.Execute("EDIT BLOCK RESET");
powerMILL.Execute("BLOCK ACCEPT");
foreach (PMToolpath toolpath in session.Toolpaths)
{
toolpath.IsActive = true;
toolpath.Calculate();
powerMILL.Execute("FORM TOOLZHEIGHTS");
powerMILL.Execute("EDIT TOOLPATH SAFEAREA RESET");
powerMILL.Execute("RESET TOOLPATH RAPID");
powerMILL.Execute("TOOLZHEIGHTS ACCEPT");
toolpath.IsActive = false;
}
Int64 count = 1;
foreach (PMNCProgram sNCProgram in session.NCPrograms)
{
sNCProgram.MachineOptionFileName =
@"C:\Users\asr\Desktop\CSC PowerMILL
Examples\DMU160P_S840D_JM_Rev7.pmoptz";
sNCProgram.OutputWorkplaneName = "OWP";
sNCProgram.Name = "O00" + count.ToString();
sNCProgram.Write();
count = count + 1;
}
powerMILL.DialogsOn();
}
}
}
Imports Delcam.ProductInterface.PowerMILL
Module Module1
Sub Main()
Dim powerMILL As New
PMAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance)
Dim session As PMProject = powerMILL.ActiveProject
powerMILL.DialogsOff()
Dim pTemplate As New Delcam.FileSystem.File("C:\CSC PowerMILL
Examples\Template_Example.ptf")
session.ImportTemplateFile(pTemplate)
Dim modelPath As New Delcam.FileSystem.File("C:\CSC PowerMILL
Examples\Pocket-Feature.dgk")
Dim myModel As PMModel = session.Models.CreateModel(modelPath)
myModel.AddToSelection(True)
powerMILL.Execute("FORM BLOCK")
powerMILL.Execute("EDIT BLOCK RESET")
powerMILL.Execute("BLOCK ACCEPT")
For Each toolpath As PMToolpath In session.Toolpaths
toolpath.IsActive = True
toolpath.Calculate()
powerMILL.Execute("FORM TOOLZHEIGHTS")
powerMILL.Execute("EDIT TOOLPATH SAFEAREA RESET")
powerMILL.Execute("RESET TOOLPATH RAPID")
powerMILL.Execute("TOOLZHEIGHTS ACCEPT")
toolpath.IsActive = False
Next
Dim count As Integer = 1
For Each sNCProgram As PMNCProgram In session.NCPrograms
sNCProgram.MachineOptionFileName = "C:\CSC PowerMILL
Examples\DMU160P_S840D_JM_Rev7.pmoptz"
sNCProgram.OutputWorkplaneName = "OWP"
sNCProgram.Name = "O00" + count.ToString()
sNCProgram.Write()
count = count + 1
Next
End Sub
End Module
learn: www.delcam.tv/lz
watch: www.delcam.tv
visit: www.delcam-services.com
Delcam
Small Heath Business Park, Birmingham B10 0HJ UK
+44 (0)121 766 5544 | delcamconsulting@delcam.com
www.delcam-services.com
Copyright Delcam Ltd 2015. All trademarks are the property of their respective owners.