powershape user guide
Post on 28-Feb-2018
299 Views
Preview:
TRANSCRIPT
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 1/29
Delcam Custom Software Core
www.delcam-services.com
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 2/29
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 3/29User Guide - PowerSHAPE • 1
Custom Software Core
User Guide - PowerSHAPE
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 4/29User Guide - PowerSHAPE • 2
Delcam Custom Software Core
Copyright © 2011 - 2015 All rights reserved.
Delcam Ltd has no control over the use made of the software described in this
manual and cannot accept responsibility for any loss or damage howsoever caused
as a result of using the software. Users are advised that all the results from the
software should be checked by a competent person, in accordance with good quality
control procedures.
The functionality and user interface in this manual is subject to change without
notice in future revisions of the software.
The software described in this manual is furnished under licence agreement and
may be used or copied solely in accordance with the terms of such licence.
Delcam Ltd grants permission for licensed users to print copies of this manual or
portions of this manual for personal use only. Schools, colleges and universities that
are licensed to use the software may make copies of this manual or portions of thismanual for students currently registered for classes where the software is used.
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.
It is the responsibility of the licensee of Delcam's software to ensure that the
storage and processing of any personal data complies with the appropriate legalregulations.
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 5/29User Guide - PowerSHAPE • 3
Contents
Custom Software Core ........................................................................................... 1
User Guide - PowerSHAPE 1
Introduction ............................................................................................................. 4
What is Custom Software Core? ................................................................... 4
Installing CSC ................................................................................................ 5
Learning to code with Custom Software Core .............................................. 6
Examples .............................................................................................................. 19
Example 1 - Creating a Cylinder ................................................................. 19
Example 2 - Cleaning a Mesh ..................................................................... 22
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 6/29User Guide - PowerSHAPE • 4
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:
Changes made to the macro language by PowerSHAPE and PowerMILL development
teams are hidden from the developer, with version discrepancies being handled
seamlessly by CSC.
The developer is able to leverage all of the power provided by the VB.net and C#
programming languages.
Significantly fewer lines of code are required to perform like-for-like operations
using CSC over direct macro language scripting, resulting in reduced complexity and
shorter development times.
Throughout this document:
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
For versions of PowerSHAPE below 15.1.46, returned values will be in the
language of the PC’s current culture; this can cause problems for Custom
Software Core. To resolve this issue, add to the windows environment the
variable ‘LC_ALL = English’ , which will force PowerSHAPE to run in English. The
downside to this is that the UI will also be displayed in English. If, afterwards,
you wish to revert the change, it is only necessary to delete the new
environment variable.
We recommend that, if running a 32Bit version of PowerSHAPE, you compile your
applications as 32Bit; likewise, if you are running a 64Bit version of PowerSHAPE,
compile in 64Bit.
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 7/29User Guide - PowerSHAPE • 5
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.
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 8/29User Guide - PowerSHAPE • 6
Learning to code with Custom Software Core To begin with, we will look at some of the more common tasks performed with CSC
such as starting a new project, connecting to PowerSHAPE, creating simple models and
so forth. After this we will look at some examples where macro code can be replaced
with CSC.
Creating a Project
1 Open up Microsoft Visual Studio and start a new project.
2 Select ‘Visual C#’ or ‘Visual Basic’ (based on your preference) from the options on
the left, then select ‘Console Application’ (Figure 1).
3 Give the project a name and a save location (Figure 1).
4 Your main project source file will contain the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Example1
{
class Program
{
static void Main(string[] args)
{}
}
}
Figure 1 – New Project
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 9/29User Guide - PowerSHAPE • 7
Module Module1
Sub Main()
End Sub
End Module
5 The next step is to set references to custom software core. Figure 2 shows a
reference diagram detailing the dependencies for each reference.
Figure 2 – Reference Diagram
6 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).
Figure 3 – Add Reference
Delcam.Utilities
Delcam.Geometry
Delcam.ProductInterface
Delcam.ProductInterface.PowerSHAPE
Delcam.ProductInterface.PowerMILL
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 10/29User Guide - PowerSHAPE • 8
7 From within the window that now appears, select ‘Assemblies’ and then ‘Extensions’
from the list.
8 Navigate the list of references and select the following:
Delcam.Geometry
Delcam.ProductInterface
Delcam.ProductInterface.PowerSHAPE
Delcam.Utilities
9 With the references added, insert the following using directive at the top of your
source file:
using Delcam.ProductInterface.PowerSHAPE;
Imports Delcam.ProductInterface.PowerSHAPE
This will save repeatedly typing in Delcam.ProductInterface.PowerSHAPE
when accessing items within this class
Connecting to PowerSHAPE
The following section demonstrates how CSC can be used to communicate with a
running instance of PowerSHAPE; required is a running instance of PowerSHAPE
with an active model.
1 Start an instance of PowerSHAPE.
2 To access the PowerSHAPE instance, add the following line to the main method of
your source file:
PSAutomation powerSHAPE = new PSAutomation
(Delcam.ProductInterface.InstanceReuse.UseExistingInstance);
Dim powerSHAPE As New PSAutomation(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 PowerSHAPE); Create a single instance (close any
PowerSHAPE instances already open and create a new one) or
UseExistingInstance (attach to a running instance of PowerSHAPE).
If you continue the line by typing a ‘.’ after your selection of InstanceReuse,
you are presented with a number of additional options including the mode in
which to open PowerSHAPE (drafting, pro, toolmaker, for example) and the
version and/or maximum version of the PowerSHAPE installation to run.
3 After attaching to PowerSHAPE it is often desirable to reset the list of available
models, thereby closing them, and open a new one. This can be achieved as
follows:
powerSHAPE.Reset();
powerSHAPE.Reset()
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 11/29
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 12/29User Guide - PowerSHAPE • 10
Creating Geometry
Figure 4 below details a CSC PowerSHAPE class hierarchy. PSAutomation contains a
PSModel, which contains collections of arcs, curves, lines and so forth, each
containing one or more objects of its type. Objects can be added to and removed
from collections and the objects themselves manipulated with the various operations
available on them: in short, a typical object oriented strategy.
Figure 4 – Class Diagram
As a simple introduction we will create a line between two points.
1 Two Delcam.Geometry.Point objects are used to define the start and end points of
the line and are created with the following code, which should be added to the mainmethod of the application source file.
Delcam.Geometry.Point startPoint = new Delcam.Geometry.Point(0,0,0);
Delcam.Geometry.Point endPoint = new Delcam.Geometry.Point(10, 5, 0);
Dim startPoint As Delcam.Geometry.Point = New Delcam.Geometry.Point(0, 0, 0)
Dim endPoint As Delcam.Geometry.Point = New Delcam.Geometry.Point(10, 5, 0)
startPoint is initialised with coordinates (0, 0, 0), which is the origin of the model,
and endpoint is given the coordinates (10, 5, 0), which represents displacement in
both X and Y.
PSAutomation
PSModel
PSArcsCollection
PSCurvesCollection
PSSolidsCollection
PSLinesCollection
Active
PSArc
PSCurve
PSLine
PSSolid
*
*
*
*
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 13/29User Guide - PowerSHAPE • 11
2 The two points can now be passed to PowerSHAPE and a line drawn between them:
PSLine myLine = psModel.Lines.CreateLine(startPoint, endPoint);
Dim myLine As PSLine = psModel.Lines.CreateLine(startPoint, endPoint)
PSLine myLine holds a reference to the newly created PowerSHAPE object and
is defined in the Delcam.ProductInterface.PowerSHAPE namespace.
3 The code can now be tested. Ensure there is an open session of PowerSHAPE to
connect to, click the ‘Start’ icon in Microsoft Visual Studio and observe the
PowerSHAPE active window where a line will be created. If any problems are
encountered, review all previous steps to this point and ensure they have been
completed in accordance with the document.
4 The line can now be manipulated in code via the PSLine object it is mapped to
(myLine). As an example, let us return the length of the line and store it as a
delcam.geometry.MM length object. Add the following code to the main method:
Delcam.Geometry.MM lineLength = myLine.Length;
Dim lineLength As Delcam.Geometry.MM = myLine.Length
Lengths are stored in a Delcam.Geometry.MM as it facilitates length-specific
operations such as converting to inches:
Inch inchLength = (Inch)lineLength;
Dim inchLength As Inch = CType(lineLength, Inch)
Custom Software Core always assumes the PowerSHAPE session to be
running in mm; thus the return value will always be treated as mm. If youattempted the following: Delcam.Geometry.Inch sizeX =
myModel.BoundingBox.MaxX with a session running in inches, the result
would be read in Inches but then multiplied by 25.4 as CSC assumes it to be
in mm.
5 Create a message box to display the line length. Firstly add a reference to
Window.Systems.Forms by right clicking on your project in the Solution Explorer
and selecting ‘Add’ then ‘Add Reference’ from the list. Select ‘Assemblies’ from the
left then ‘Framework’ from the resulting drop down. Select System.Windows.Forms
from the list and click ‘OK’ .
6 Add a using directive to the top of the main source file:
using System.Windows.Forms;
Imports System.Windows.Forms;
7 Instantiate a message box in which to display the line length. Add the following
code to the main method:
MessageBox.Show("The line is " + lineLength.ToString() + "mm");
MessageBox.Show("This line is" & lineLength.ToString & " mm")
8 Run the code once more and a message box will appear (Figure 5).
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 14/29User Guide - PowerSHAPE • 12
Creating Solids, Surfaces and Meshes
We shall now see how CSC can be used to create other objects in PowerSHAPE by
defining a simple solid block.
1 Delete from your main method all lines of code added in the previous sectionincluding points, lines and message box.
2 To create a simple block enter the following code:
PSSolid mySolid = psModel.Solids.CreateBlock(startPoint, 25, 50, 10, 0);
Dim mySolid As PSSolid = psModel.Solids.CreateBlock(startPoint,25,50,10,0)
3 This creates a block at the origin (0, 0, 0) of 25mm length, 50mm width, 10mm
height and with a draft angle of 0⁰.
4 Many operations can now be performed from within code on the newly created solid
through its PSSolid reference object. If, for example, it is desired to delete the solidfrom PowerSHAPE, enter the following:
mySolid.Delete();
mySolid.Delete()
5 With the addition of a single line of code a mesh can be created from the solid:
PSMesh myMesh = psModel.Meshes.CreateMeshFromSolid(mySolid);
Dim myMesh As PSMesh = psModel.Meshes.CreateMeshFromSolid(mySolid)
6 Alternatively, the solid can be turned into surfaces thus:
List<PSSurface> newSurface =
psModel.Surfaces.CreateSurfacesFromSolid(mySolid);
Dim newSurface As List(Of PSSurface) =
psModel.Surfaces.CreateSurfacesFromSolid(mySolid)
Surfaces must be stored in a list as such transforms may return many; six in
the case of a cube.
7 Delete all code entered in this section before moving to the next.
Figure 5 – Line Length Message Box
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 15/29User Guide - PowerSHAPE • 13
Importing and Exporting a Model
It is common practice to import and export solids, surfaces and so forth in
PowerSHAPE. This section will focus on how to achieve this using CSC.
1 Create an instance of Delcam.FileSystem.File with which to encapsulate an import
file location:
Delcam.FileSystem.File importFile = new Delcam.FileSystem.File(@"C:\CSC
PowerSHAPE Examples\Example.dgk");
Dim importFile As Delcam.FileSystem.File = New
Delcam.FileSystem.File("C:\CSC PowerSHAPE Examples\Example.dgk")
Example.dgk will be located in the path to which you extracted your example
files earlier and may be different to that specified above.
2 Import the DGK file into the model:
psModel.Import(importFile);
psModel.Import(importFile)
3 The solid has now been imported into the open model. To obtain an instance of it
from the solids collection enter the following line of code:
PSSolid mySolid = psModel.Solids.LastItem();
Dim mySolid As PSSolid = psModel.Solids.LastItem
4 The solid can now be manipulated as before. The same principle can be applied to
surfaces, meshes, curves and so forth.
5 To export the solid, it is first necessary to ensure it is the only selected object. The
following two lines of code clear all selected items and then reselect the object that
is to be exported.
psModel.ClearSelectedItems();
mySolid.AddToSelection();
psModel.ClearSelectedItems()
mySolid.AddToSelection()
6 The solid will now be exported back to its original file and location:
psModel.Export(importFile, ExportItemsOptions.Selected);
psModel.Export(importFile, ExportItemsOptions.Selected)
Executing Macro Commands
It is also possible to execute macro commands from within our code, the
mechanism for doing which is outlined in the following.
1 Create a simple block using macro commands. Note this is purely for demonstration
purposes since a similar result was achieved earlier using CSC functions.
powerSHAPE.Execute("CREATE SOLID BLOCK");
powerSHAPE.Execute("BLOCK");powerSHAPE.Execute("0,0,0");
powerSHAPE.Execute("CREATE SOLID BLOCK")
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 16/29User Guide - PowerSHAPE • 14
powerSHAPE.Execute("BLOCK")
powerSHAPE.Execute("0,0,0")
2 Alternatively you may wish to acquire information from PowerSHAPE to use within
your program. If, for example, you want to find the length of a line, enter the
following:
Double lineLength2 =(Double)powerSHAPE.ExecuteEx("line[TempLine].length");
Dim lineLength2 As Double = powerSHAPE.ExecuteEx("line[TempLine].length")
You will need to know the name of the line to perform this operation.
3 It is important to note that entities created within PowerSHAPE using macro
commands will not appear within the CSC cache until it is updated. To update the
cache, issue the following command:
psModel.Refresh();
psModel.Refresh()
4 It is now possible to create in code an instance of the PowerSHAPE object that was
created with the macro command. If, for example, you create a line in macro code,
create a PSLine instance as follows:
powerSHAPE.Execute("CREATE LINE SINGLE");
powerSHAPE.Execute("0 0 0");
powerSHAPE.Execute("10 0 0");
psModel.Refresh();
PSLine myLine = psModel.Lines[0];
powerSHAPE.Execute("CREATE LINE SINGLE")
powerSHAPE.Execute("0 0 0")
powerSHAPE.Execute("10 0 0")
psModel.Refresh()
Dim myLine As PSLine = psModel.Lines(0)
It is strongly recommended that you always use available CSC functionality in
preference to issuing raw macro commands. If you feel that CSC is lacking the
functionality you require, please contact the forum at:
http://forum.delcam.com/viewforum.php?f=53
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 resultingwindow and install it.
2 Next, right click on your solution and select ‘Add’ then ‘New Project’ (Figure 6).
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 17/29User Guide - PowerSHAPE • 15
3 Select ‘Other Project Types’ followed by ‘Visual Studio Installer’ from the left-hand-
side of the new window; then select ‘Setup Project’.
4 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.
Figure 6 – Adding a new project
Figure 7 – Setting Manufacturer, ProductName
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 18/29User Guide - PowerSHAPE • 16
5 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).
6 From the dialog box, select ‘Primary Output’ and click ‘Ok’.
7 You will notice references appear in the right hand box (Figure 10).
8 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.
9 If it is desired to add a shortcut to the start menu then right click ‘User’s Program’sMenu’ and select ‘Add’ followed by ‘Folder’; name the folder appropriately ( Figure
11).
Figure 8 – Adding a project output
Figure 9 – File System Editor
Figure 10 – Adding References
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 19/29User Guide - PowerSHAPE • 17
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.
Figure 11 – Set an install folder
Figure 12 – Adding shortcut to program menu
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 20/29User Guide - PowerSHAPE • 18
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 21/29User Guide - PowerSHAPE • 19
Examples
Example 1 - Creating a Cylinder Example 1 demonstrates how to use CSC to create a circle in PowerSHAPE, extrude it to
form a solid and then export the result to file.
For comparison, macro code to accomplish the same task is presented below.
CREATE ARC
FULL
0,0,0
MODIFY
DIMENSION 20
ACCEPT
CREATE SOLID EXTRUSION
MODIFY
LENGTH 50
ACCEPT
FILE EXPORT WIZARDNEXT
C:\CSC PowerSHAPE Examples\Cylinder.dgk
WIZEXPORT
The CSC steps are as follows:
1 Start a new console application in Microsoft Visual Studio as detailed previously.
2 Add the following references to your solution (if you have forgotten how to do this refer
back).
Delcam.Geometry
Delcam.ProductInterface
Delcam.ProductInterface.PowerSHAPE
Delcam.Utilities
3 Add the following using directive to the top of the main source file.
using Delcam.ProductInterface.PowerSHAPE;
Imports Delcam.ProductInterface.PowerSHAPE
4 Connect to PowerSHAPE and turn off all dialogs as before.
PSAutomation powerSHAPE = new PSAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance);
PSModel psModel = powerSHAPE.ActiveModel;
powerSHAPE.FormUpdateOff();
powerSHAPE.RefreshOff();
powerSHAPE.DialogsOff();
Dim powerSHAPE As PSAutomation = New
PSAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance)
Dim psModel As PSModel = powerSHAPE.ActiveModel
powerSHAPE.FormUpdateOff()
powerSHAPE.RefreshOff()
powerSHAPE.DialogsOff()
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 22/29User Guide - PowerSHAPE • 20
5 It is usually desirable to re-enable forms and dialogs before the program exits. Add this
code now and all subsequent lines between this and the previous block.
powerSHAPE.FormUpdateOn();
powerSHAPE.RefreshOn();
powerSHAPE.DialogsOn();
powerSHAPE.FormUpdateOn()
powerSHAPE.RefreshOn()powerSHAPE.DialogsOn()
6 Two points are required to create a circle; the first is the origin of the circle and the
second the position at which the circle starts (typically this is of no concern, but is
required by CSC). The following code creates a circle centred at (0, 0, 0) and starting
from the x-axis (the co-ordinate position of this point is not important so long as it lies
on the axis).
Delcam.Geometry.Point originPoint = new Delcam.Geometry.Point(0,0,0);
Delcam.Geometry.Point startPoint = new Delcam.Geometry.Point(10, 0, 0);
PSArc myCircle = psModel.Arcs.CreateArcCircle(originPoint,
startPoint, 20.0);
Dim originPoint As Delcam.Geometry.Point = New Delcam.Geometry.Point(0, 0, 0)
Dim startPoint As Delcam.Geometry.Point = New Delcam.Geometry.Point(10, 0, 0)
Dim myCircle As PSArc = psModel.Arcs.CreateArcCircle(originPoint,
startPoint, 20)
7 The circle will now be extruded by 50.0 mm in the positive to form a solid.
PSSolid myCylinder =
psModel.Solids.CreateSolidExtrusionFromWireframe(myCircle, 50.0, 0.0);
Dim myCylinder As PSSolid =
psModel.Solids.CreateSolidExtrusionFromWireframe(myCircle, 50, 0)
8 The cylinder thus formed can now be exported by firstly creating a
Delcam.FileSystem.File object initialised with an appropriate export path and then
writing the data to it.
Delcam.FileSystem.File exportLocation = new
Delcam.FileSystem.File(@"C:\CSC PowerSHAPE Examples\Cylinder.dgk");
psModel.Export(exportLocation, ExportItemsOptions.Selected);
Dim exportLocation As New Delcam.FileSystem.File("C:\CSC PowerSHAPE
Examples\Cylinder.dgk")
psModel.Export(exportLocation, ExportItemsOptions.Selected)
9 The code can now be run. If the result is not as expected, ensure you have followed
verbatim all he steps in this example.
It is worthy of note that, should the code required to disable and re-enable forms and
dialogs be excluded from the count, the number of lines required to accomplish our
objective here is six, eight fewer than the macro code solution.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Delcam.ProductInterface.PowerSHAPE;
namespace CylinderExample
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 23/29User Guide - PowerSHAPE • 21
{
class Program
{
static void Main(string[] args)
{
PSAutomation powerSHAPE = new
PSAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance);
PSModel psModel = powerSHAPE.ActiveModel;
powerSHAPE.FormUpdateOff();
powerSHAPE.RefreshOff();
powerSHAPE.DialogsOff();
Delcam.Geometry.Point originPoint = new
Delcam.Geometry.Point(0,0,0);
Delcam.Geometry.Point startPoint = new
Delcam.Geometry.Point(10, 0, 0);
PSArc myCircle = psModel.Arcs.CreateArcCircle(originPoint,
startPoint, 20.0);
PSSolid myCylinder =
psModel.Solids.CreateSolidExtrusionFromWireframe(myCircle, 10.0, 0.0);
Delcam.FileSystem.File exportLocation = new
Delcam.FileSystem.File(@"C:\CSC PowerSHAPE Examples\Cylinder.dgk");
psModel.Export(exportLocation, ExportItemsOptions.Selected);
powerSHAPE.FormUpdateOn();
powerSHAPE.RefreshOn();
powerSHAPE.DialogsOn();
}
}
}
Imports Delcam.ProductInterface.PowerSHAPE
Module Module1
Sub Main()
Dim powerSHAPE As PSAutomation = New
PSAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance)
Dim psModel As PSModel = powerSHAPE.ActiveModel
powerSHAPE.FormUpdateOff()
powerSHAPE.RefreshOff()
powerSHAPE.DialogsOff()
Dim originPoint As Delcam.Geometry.Point = New
Delcam.Geometry.Point(0, 0, 0)
Dim startPoint As Delcam.Geometry.Point = New
Delcam.Geometry.Point(10, 0, 0)
Dim myCircle As PSArc =
psModel.Arcs.CreateArcCircle(originPoint, startPoint, 20)
Dim myCylinder As PSSolid =
psModel.Solids.CreateSolidExtrusionFromWireframe(myCircle, 50, 0)
Dim exportLocation As New Delcam.FileSystem.File("C:\CSC
PowerSHAPE Examples\Cylinder.dgk")
psModel.Export(exportLocation, ExportItemsOptions.Selected)
powerSHAPE.FormUpdateOn()
powerSHAPE.RefreshOn()
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 24/29User Guide - PowerSHAPE • 22
powerSHAPE.DialogsOn()
End Sub
End Module
Example 2 - Cleaning a Mesh Consider the case of importing a .STL scan file, the mesh of which contains a number of
undesired detached pieces that are to be removed, thereby leaving only the largest
piece of the mesh.
To achieve this it is necessary to split the mesh into its individual pieces, consider each
one in turn, retain the largest and export this back to file. A macro code solution
requires IF statements, which can be confusing and difficult; the following steps
demonstrate how the problem can be solved using CSC.
1 Start by adding the required references along with the following standard code with
which you should now be familiar.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Delcam.ProductInterface.PowerSHAPE;
namespace CleanUpMesh
{
class Program
{
static void Main(string[] args)
{
PSAutomation powerSHAPE = new PSAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance);
PSModel psModel = powerSHAPE.ActiveModel;
powerSHAPE.FormUpdateOff();
powerSHAPE.RefreshOff();
powerSHAPE.DialogsOff();
powerSHAPE.FormUpdateOn();
powerSHAPE.RefreshOn();
powerSHAPE.DialogsOn();
}
}}
Imports Delcam.ProductInterface.PowerSHAPE
Module Module1
Sub Main()
Dim powerSHAPE As New
PSAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance)
Dim psModel As PSModel = powerSHAPE.ActiveModel
powerSHAPE.FormUpdateOff()
powerSHAPE.RefreshOff()
powerSHAPE.DialogsOff()
powerSHAPE.FormUpdateOn()
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 25/29User Guide - PowerSHAPE • 23
powerSHAPE.RefreshOn()
powerSHAPE.DialogsOn()
End Sub
End Module
2 Create a Delcam.FileSystem.File object with which to import the .STL file and create
a second file object to which the final result will be exported.
Delcam.FileSystem.File importFile = new Delcam.FileSystem.File(@"C:\CSC
PowerSHAPE Examples\SampleMesh.stl");
Delcam.FileSystem.File exportFile = new Delcam.FileSystem.File(@"C:\CSC
PowerSHAPE Examples\SplitMesh.dmt");
psModel.Import(importFile);
PSMesh myMesh = psModel.Meshes.LastItem();
Dim importFile As New Delcam.FileSystem.File("C:\CSC PowerSHAPE
Examples\SampleMesh.stl")
Dim exportFile As New Delcam.FileSystem.File("C:\CSC PowerSHAPE
Examples\SplitMesh.dmt")
psModel.Import(importFile)Dim myMesh As PSMesh = psModel.Meshes.LastItem
3 Split the mesh and store in a list the pieces returned by PowerSHAPE.
List<PSMesh> meshList = myMesh.Split();
Dim meshList As List(Of PSMesh) = myMesh.Split
4 Cycle through each entity to determine the largest bounding box. This can be
achieved with a single line of code:
meshList.OrderBy(m => m.BoundingBox.Volume).Last().AddToSelection(true);
meshList.OrderBy(Function(m) m.BoundingBox.Volume).Last.AddToSelection(true)
5 Now only the largest piece of the mesh is selected PowerSHAPE, it can be exported
to file in the manner described earlier in the document.
psModel.Export(exportFile, ExportItemsOptions.Selected);
psModel.Export(exportFile, ExportItemsOptions.Selected)
It should be noted that a complex operation has been reduced to a small number of
concisely written and easy to comprehend lines of code, the full listing of which is given
below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Delcam.ProductInterface.PowerSHAPE;
namespace CleanUpMesh
{
class Program
{
static void Main(string[] args)
{PSAutomation powerSHAPE = new
PSAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance);
powerSHAPE.Reset();
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 26/29User Guide - PowerSHAPE • 24
PSModel psModel = powerSHAPE.ActiveModel;
powerSHAPE.FormUpdateOff();
powerSHAPE.RefreshOff();
powerSHAPE.DialogsOff();
Delcam.FileSystem.File importFile = new Delcam.FileSystem.File(@"C:\CSC PowerSHAPE Examples\SampleMesh.stl");
Delcam.FileSystem.File exportFile = new
Delcam.FileSystem.File(@"C:\ CSC PowerSHAPE Examples \SplitMesh.dmt");
psModel.Import(importFile);
PSMesh myMesh = psModel.Meshes.LastItem();
List<PSMesh> meshList = myMesh.Split();
meshList.OrderBy(m =>
m.BoundingBox.Volume).Last().AddToSelection(true);
psModel.Export(exportFile, ExportItemsOptions.Selected);
powerSHAPE.FormUpdateOn();powerSHAPE.RefreshOn();
powerSHAPE.DialogsOn();
}
}
}
Imports Delcam.ProductInterface.PowerSHAPE
Module Module1
Sub Main()
Dim powerSHAPE As New
PSAutomation(Delcam.ProductInterface.InstanceReuse.UseExistingInstance)
Dim psModel As PSModel = powerSHAPE.ActiveModel
powerSHAPE.FormUpdateOff()
powerSHAPE.RefreshOff()
powerSHAPE.DialogsOff()
Dim importFile As New Delcam.FileSystem.File("C:\CSC PowerSHAPE
Examples\SampleMesh.stl")
Dim exportFile As New Delcam.FileSystem.File("C:\CSC PowerSHAPE
Examples\SplitMesh.dmt")
psModel.Import(importFile)
Dim myMesh As PSMesh = psModel.Meshes.LastItem
Dim meshList As List(Of PSMesh) = myMesh.Split
meshList.OrderBy(Function(m)
m.BoundingBox.Volume).Last.AddToSelection(True)
psModel.Export(exportFile, ExportItemsOptions.Selected)
powerSHAPE.FormUpdateOn()
powerSHAPE.RefreshOn()
powerSHAPE.DialogsOn()
End Sub
End Module
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 27/29User Guide - PowerSHAPE • 25
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 28/29
7/25/2019 PowerSHAPE User Guide
http://slidepdf.com/reader/full/powershape-user-guide 29/29
© Copyright Delcam Ltd 2015. All trademarks are the property of their respective owners.
DelcamSmall Heath Business Park, Birmingham B10 0HJ UK
+44 (0)121 766 5544 | delcamconsulting@delcam.com
www.delcam-services.com
visit: www.delcam-services.com
watch:www.delcam.tvlearn:www.delcam.tv/lz
top related