new CAD()
Provides a high-level API for generating complex 2D and 3D forms using the OpenCascade geometry kernel.
This class is also exposed as just CAD within the built-in code editor
panel of each framework application that uses it.
The methods of this class can be used to generate complex geometry by
creating, transforming and combining primitive shapes. Shapes created
using these methods are cached by default for performance reasons and
are automatically added to and removed from the PD.CAD.model as
they are created, transformed and modified. The PD.CAD.model
property is an array that stores the final geometric output that is
converted to a mesh and sent back to the host application for display
or further processing.
The aim of this class is to provide a relatively simple and intuitive set of commands that handle the majority of use cases and abstract away many of the complexities of managing a CAD model and handling geometry. However, these commands do not expose the full range of capabilities of the OpenCascade engine.
Going Deeper
Sitting beneath the higher-level methods in PD.CAD is PD.OCC,
which provides lower-level methods that interface directly with OpenCascade.
In fact, most of the creation, transformation and modification methods in
PD.CAD have corresponding lower-level methods with similar names in
PD.OCC that are called to do the actual work, which you can see if
you look at the process logs.
These lower-level methods are more flexible and expose more capabilities
of the engine, but have more complex input parameters, are not cached, and
require you to manually add and remove the resulting shapes shapes to/from
the CAD model yourself using the PD.CAD.add and PD.CAD.remove
methods. When you need to move beyond the simpler CAD API, you are strongly
encouraged to work directly with OCC as well.
For those who really like a challenge, the raw OpenCascade engine is
also exposed via the oc object, so you can use its methods to access
the full range of capabilities. Again, you can use the PD.CAD.add
and PD.CAD.remove methods to add and remove any generated
oc.TopoDS_Shape to/from the CAD model.
Caching
PD.CAD has the option of caching its primitives and operations so
that previous geometry kernel results can be reused instead of regenerated.
This is on by default and can have significant performance benefits as very often
the individual parts of many models are repetitive. This is particularly effective
when a user is iteratively or interactively editing or refining just one or two
primitives within a more complex boolean solid or model, as it means that only
those steps with modified input parameters need to be regenerated each time.
Classes
Members
-
:object|null
font <static>
-
The font to use for 3D text.
Type
- object | null
-
:boolean
isCancelled <static>
-
A flag indicating that user has cancelled process.
Type
- boolean
-
:number
logLevel <static>
-
The level of logging to display.
Type
- number
-
:Array.<oc.TopoDS_Shape>|Array.<PD.Shape>
model <static>
-
An array storing all the shapes that make up the final model.
Shapes created using
PD.CADmethods are automatically added to and removed from the model as they are created, transformed and modified. However all these creations, transformations and modifications rely on lower-level methods fromPD.OCCto do the actual work. You can use these lower-level methods directly to create interim geometry, but they will not be cached and will not become part of the final model until you specifically use thePD.CAD.addmethod to add them. You can also use thePD.CAD.removeto remove shapes from the model.The
PD.CAD.addmethod is pretty robust in that it will only add shapes if they are valid and do not already exist within the model. You should therefore always use that method rather than pushing shapes directly into the model array.Type
- Array.<oc.TopoDS_Shape> | Array.<PD.Shape>
-
:Array.<LogEntry>
processLog <static>
-
Maintains a log of each operation.
Type
- Array.<LogEntry>
-
:boolean
useCache <static>
-
Whether or not to cache primitives and operations.
Type
- boolean
Methods
-
add(shapes) <static>
-
Add a shape or array of shapes to the generated model.
Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape <repeatable>
One or more shapes to add.
-
addBox(width, depth, height [, centered]) <static>
-
Adds a rectangular prism to the scene.
The box is created with its bottom-left at the origin and its width in the X-axis, depth in the Y-axis and height in Z-axis. For more complex box shapes with different origins, orientations and rounded edges, you can use the
PD.OCC.cuboidmethod directly.(0,d,h) +---------------+ (w,d,h) Z / /| Y |/ / | / (0,0,h) +---------------+ | | | + (w,d,0) | | / | |/ (0,0,0) +---------------+ (w,0,0) - XThis method will cache the generated shape if caching is enabled.
Parameters:
Name Type Argument Description widthnumber The size of the box in the X-axis, defaults to 1000mm (1m).
depthnumber The size of the box in the Y-axis, defaults to 1000mm (1m).
heightnumber The size of the box in the Z-axis, defaults to 1000mm (1m).
centeredboolean <optional>
An optional flag indicating that the box should be centered at the origin rather than at its bottom-left, defaults to false.
Returns:
Returns a rectangular prism shape.
- Type
- oc.TopoDS_Shape
-
addBoxByMinMax(min, min) <static>
-
Adds a new rectangular prism to the scene using points at its minimum and maximum extents.
The box is created at the origin with its width in the X-axis, depth in the Y-axis and height in Z-axis. For more complex box shapes with different origins, orientations and rounded edges, you can use the
PD.OCC.cuboidmethod directly.(max) Z +---------------+ | / /| Y |/ / | / +---------------+ |/ | | + | | / | |/ +---------------+ -- -- X (min)This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Description minArray.<number> An [x,y,z] vector array defining the minimum box extents.
minArray.<number> An [x,y,z] vector array defining the maximum box extents.
Returns:
Returns a rectangular prism shape.
- Type
- oc.TopoDS_Shape
-
addCapsule(radius, height [, endRadius]) <static>
-
Adds a cylindrical shape with rounded ends to the scene.
The capsule is created with its axis running vertically up from the origin. You can use transformation methods to move, scale and rotate it once created. For more complex cylindrical shapes with different positions, orientations and fillet radii, you can use the
PD.OCC.cylindermethod directly.This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Argument Description radiusnumber The distance of the cylinder surface from the centre axis.
heightnumber The distance between the top and bottom planes.
endRadiusnumber <optional>
The radius of the rounded end of the capsule (0 to radius), defaults to the cylinder radius.
Returns:
Returns a cylindrical shape.
- Type
- oc.TopoDS_Shape
-
addChamfer(shape, distance, edges [, makeCopy]) <static>
-
Applies a flat chamfer to one or more edges in a shape.
Parameters:
Name Type Argument Description shapeoc.TopoDS_Shape The shape to chamfer.
distancenumber The size of the chamfer in model units.
edgesArray.<number> An array of edge indices to apply the chamfer to, with an empty array meaning all edges.
makeCopyboolean <optional>
Apply to a copy and keep original shape in the model, defaults to false.
Returns:
Returns the chamfered solid, or the given shape if no matching edges were found.
- Type
- oc.TopoDS_Shape | oc.TopoDS_Solid
-
addCircle(radius [, outline]) <static>
-
Adds a flat circular face/wire at the origin to the scene.
This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Argument Description radiusnumber The radius of the circle.
outlineboolean <optional>
An optional flag for the method to return the outline of the shape as a wire rather than as a shape, defaults to false.
Returns:
Returns a circular shape.
- Type
- oc.TopoDS_Face | oc.TopoDS_Wire
-
addCone(radiusBot, radiusTop, height [, centered]) <static>
-
Construct a conical primitive shape at the origin.
This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Argument Description radiusBotnumber The radius at the bottom of the cone.
radiusTopnumber The radius at the top of the cone, typically 0.
heightnumber The distance between the top and bottom planes.
centerednumber <optional>
An optional flag indicating that the given position represents the center of the cone rather than the bottom-left, defaults to false.
Returns:
Returns a conical shape.
- Type
- oc.TopoDS_Shape
-
addCylinder(radius, height [, centered]) <static>
-
Adds a cylindrical shape with flat ends to the scene.
The cylinder is created with its axis running vertically up from the origin. You can use transformation methods to move, scale and rotate it once created. For more complex cylindrical shapes with different positions, orientations and rounded ends, you can use the
PD.OCC.cylindermethod directly.This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Argument Description radiusnumber The distance of the cylinder surface from the centre axis.
heightnumber The distance between the top and bottom planes.
centerednumber <optional>
An optional flag indicating that the cylinder should be created with its geometric center at the origin rather than the center of its base, otherwise the bottom-left, defaults to false.
Returns:
Returns a cylindrical shape.
- Type
- oc.TopoDS_Shape
-
addDome(radius) <static>
-
Add a new hemispherical shape at the origin.
This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Description radiusnumber The distance of the dome surface from the centre.
Returns:
Returns a hemispherical shape.
- Type
- oc.TopoDS_Shape
-
addFacetedShell(facets [, tolerance]) <static>
-
Construct a shape from the JSON representation of a simple faceted mesh.
There are several variants of point/face meshes, and this is one of the less optimised as it does not separate points and faces. Rather, it uses arrays of vertices to define face boundaries, which means that coincident vertices are repeated. However, in a faceted mesh, coincident vertices are very likely to have different surface normals,
A faceted mesh contains a list of all the
facetsthat make up a shape. Each facet may optionally have a plane equation, but must always have an array of closedboundariesthat define its outline. The first array of boundary points always defines the outer boundary of the facet and any subsequent boundaries defining holes within it. Each boundary is an array containing at least three (3) [x,y,z] vertex arrays points defining each corner.Construct a shell shape sewn together from a series of facets.
This method only deals with faceted data, which means that each face is defined by or contains an array of [x,y,z] vector arrays giving the positions of each corner of its boundaries.
Each entry in the
facetsarray is an object that has an optionalplaneproperty with the [a,b,c,d] plane equation of the face and a non-optionalboundariesproperty containing one or more contours of [x,y,z] vertex positions. If there are multiple contours, the first will be considered the outer boundary and any subsequent contours will be treated as holes within the face.To be valid, each boundary and hole array must contain at least three (3) or more planar vertex indices defining each of its corners.
If you have data in which vertices are given in a separate array and where each face is an ordinal index, you can use the
CAD.AddIndexedShellmethod instead of this one.Parameters:
Name Type Argument Description facetsArray.<object> An array of objects with a
boundariesproperty containing one ot more contours of [x,y,z] vector arrays that make up its outline and any holes it may contain.tolerancenumber <optional>
An optional face sewing tolerance, defaults to 1mm.
Returns:
Returns a shape sewn together from facets.
- Type
- oc.TopoDS_Shape
-
addFillet(shape, radius [, edges] [, makeCopy]) <static>
-
Applies a rounded fillet to one or more edges in a shape.
For simple fillets with the same radius, the
edgesarray should contain a flat list of edge indices and theradiusvalue should give the radius to use on those edges.If you want to fillet different edges with different radii, calling this method more than once is a very inefficient way of doing it and makes keeping track of the edge indexes after each iteration almost impossible. Instead, you can include multiple arrays within the
edgesargument, ensuring that each array starts with the required radius and is followed by one or more edge indices to fillet at that radius, as shown in the third example below.Parameters:
Name Type Argument Description shapeoc.TopoDS_Shape The shape to fillet.
radiusnumber | Array.<number> The radius of the fillet in model units or one or more radius/edge arrays.
edgesArray.<number> <optional>
An array of edge indices to apply the fillet to, with an empty array meaning all edges.
makeCopyboolean <optional>
Apply to a copy and keep original shape in the model, defaults to false.
Returns:
Returns the filleted solid, or the given shape if no matching edges were found.
- Type
- oc.TopoDS_Shape | oc.TopoDS_Solid
Example
const horz_radius = 100; const vert_radius = 200; CAD.addFillet( CAD.addBox(2000, 2000, 100, true), [ [ horz_radius, 1, 5, 9, 11 ], [ vert_radius, 0, 2, 4, 6 ] ] ); -
addHull(shapes [, tolerance] [, makeCopy]) <static>
-
Construct a convex hull shape from points or shape(s).
Parameters:
Name Type Argument Description shapesArray.<Array.<number>> | oc.TopoDS_Shape | Array.<oc.TopoDS_Shape> An array of shape(s) and/or [x,y,z] point clouds.
tolerancenumber <optional>
An optional face sewing tolerance, defaults to 1mm.
makeCopyboolean <optional>
Apply to a copy and keep original shape(s) in the model, defaults to false.
Returns:
Returns a solid hull shape sewn from multiple faces.
- Type
- oc.TopoDS_Shape
-
addHullChain(shapes [, tolerance] [, makeCopy]) <static>
-
Construct a shape from a series of unioned convex hulls.
The order of shapes within the
shapesarray will affect the resulting hull shape as each pair is grouped consecutively.Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> | Array.<Array.<Array.<number>>> A shape or array of shapes/points to create a hull from.
tolerancenumber <optional>
An optional face sewing tolerance, defaults to 1mm.
makeCopyboolean <optional>
Apply to a copy and keep original shape in the model, defaults to false.
Returns:
Returns a hull shape sewn from multiple faces.
- Type
- oc.TopoDS_Shape
-
addIndexedShell(points, faces [, tolerance]) <static>
-
Construct a shell by sewing together a series of facets.
This method takes a collection of indexed planar faces and attempts to construct a connected
TopoDS_Shellout of them. The faces do not have to be in any particular order or have shared edges and/or vertices as this process will do its best work out the interconnection relationships between faces and create shared edges.Note that this method only deals with indexed face data, which means that all the vertices in the shape are stored in one array (vertices) and all the faces in another (faces). The vertices must all be [x,y,z] vector arrays and each face is defined by or contains an array of ordinal indexes of each vertex that make up its boundaries.
Thus, each entry in the
facesarray may be either an array of vertex indices or an object containing aboundariesproperty that is an array. If theboundariesarray contains one or more contours of vertex indices, then the first will be considered as the outer boundary and any subsequent boundaries treated as holes within the face. If the boundary is a flat array of vertex indices, it will be considered as an outer boundary with no holes.To be valid, each boundary and hole array must contain at least three (3) or more planar vertex indices defining each of its corners.
If you have data in which vertices are not given separately, but where each face is a list of [x,y,z] vector arrays, use the
CAD.addFacettedShellmethod instead of this one.Parameters:
Name Type Argument Description pointsArray.<Array.<number>> An array of [x,y,z] vector arrays defining the corners and edges of the shape.
facesArray.<Array.<number>> | Array.<object> An array of boundaries and/or contours, each containing ordinal indexes of the vertices that make up each face.
tolerancenumber <optional>
An optional face sewing tolerance, defaults to 1mm.
Returns:
Returns a shape sewn together from indexed faces.
- Type
- oc.TopoDS_Shape
-
addLogEntry(level, message) <static>
-
Adds a new entry to the process log.
Parameters:
Name Type Description levelnumber The log level of this message.
messagestring The human-readable message to log.
Returns:
Returns a new log entry instance.
- Type
- LogEntry
-
addPolygon(points [, outline]) <static>
-
Adds a flat multi-sided primitive face/wire to the scene.
This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Argument Description pointsArray.<Array.<number>> An array of [x,y,z] vector arrays defining the vertices of the polygon.
outlineboolean <optional>
An optional flag for the method to return the outline of the shape as one or more wires rather than as a face, defaults to false.
Returns:
Returns a polygonal shape or the wires that bound it.
- Type
- oc.TopoDS_Face | Array.<oc.TopoDS_Wire>
-
addPolyhedron(poly [, tolerance]) <static>
-
Construct a shape from a
PD.Polyhedronor a polyhedron notation string.Parameters:
Name Type Argument Description polyPD.Polyhedron | string The polyhedron to add or a Conway polyhedron notation string.
tolerancenumber <optional>
An optional face sewing tolerance, defaults to 1mm.
Returns:
Returns a solid shape sewn together from multiple faces.
- Type
- oc.TopoDS_Shape
-
addPrism(radius, sides, height) <static>
-
Construct a regular prism at the origin.
Parameters:
Name Type Description radiusnumber The radius of the regular prism.
sidesnumber The number of sides of the prism (3 to 256).
heightnumber The distance between the top and bottom planes.
Returns:
Returns a shape sewn together from multiple faces.
- Type
- oc.TopoDS_Shape
-
addPyramid(width, depth, height [, truncate]) <static>
-
Construct a pyramid shape at the origin in the Z-axis.
This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Argument Description widthnumber The size of the wedge in the X-axis.
depthnumber The size of the wedge in the Y-axis.
heightnumber The size of the wedge in the Z-axis.
truncatenumber <optional>
The fractional truncation amount (0 to 1), defaults to 1.0.
Returns:
Returns a wedge shape.
- Type
- oc.TopoDS_Shape
Examples
CAD.addPyramid(4000, 3000, 2000);
CAD.addPyramid(4000, 3000, 4000, 0.5);
-
addShell(shape [, tolerance]) <static>
-
Construct a shape shape from a facetted shape or indexed face shell.
Parameters:
Name Type Argument Description shapePD.Shape | object The shape to add, or an object with
verticesandfaces.tolerancenumber <optional>
An optional face sewing tolerance, defaults to 1mm.
Returns:
Returns a shell shape sewn together from multiple faces.
- Type
- oc.TopoDS_Solid
-
addSolid(shape [, tolerance]) <static>
-
Construct a solid shape from a facetted shape or indexed face shell.
Parameters:
Name Type Argument Description shapePD.Shape | object The shape to add, or an object with
verticesandfaces.tolerancenumber <optional>
An optional face sewing tolerance, defaults to 1mm.
Returns:
Returns a solid shape sewn together from multiple faces.
- Type
- oc.TopoDS_Solid
-
addSphere(radius) <static>
-
Add a new spherical shape at the origin.
This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Description radiusnumber The distance of the spherical surface from the centre.
Returns:
Returns a spherical shape.
- Type
- oc.TopoDS_Shape
-
addText(text [, size] [, height]) <static>
-
Construct a set of primitive shapes representing 3D text.
This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Argument Description textstring The characters to be generated.
sizenumber <optional>
The size of the text in model units, defaults to 36.
heightnumber <optional>
The extrusion height of the text faces, defaults to 0.15.
Returns:
Returns a complex shape representing the text.
- Type
- oc.TopoDS_Shape | oc.TopoDS_Solid
-
addTorus(radiusRing, radiusPipe) <static>
-
Construct a toroidal primitive shape at the origin.
This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Description radiusRingnumber The distance of the pipe center from main centre.
radiusPipenumber The distance of the pipe surface from the pipe centre.
Returns:
Returns a toroidal shape.
- Type
- oc.TopoDS_Shape
-
addWedge(width, depth, height [, taperHeight] [, taperWidth]) <static>
-
Adds a wedge shape at the origin along the Y-axis to the scene.
The construction of the wedge can be controlled by the number of arguments you provide to this method. The first three size values are absolutely required, but you can provide either a an additional height value, a height and width, or the minimum and maximum X and Z coordinates.
Z | (0,0,h) (w,d,h) Y 4-------------------5__ / |'' 3---------------|---2 | /(0,d,0) (w,d,0)/ | / | / |/ |/ +-------------------+ -- X (0,0,0) (w,0,0)This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Argument Description widthnumber The size of the wedge in the X-axis.
depthnumber The size of the wedge in the Y-axis.
heightnumber The size of the wedge in the Z-axis.
taperHeightnumber | Array.<number> <optional>
The height of the tapered end as a number or [min,max] array, defaults to [0,0].
taperWidthnumber | Array.<number> <optional>
The width of the tapered end as a number or [min,max] array, defaults to [0,width].
Returns:
Returns a wedge shape.
- Type
- oc.TopoDS_Shape
Examples
/// Define just the size. PD.CAD.addWedge(2000, 4000, 1500);
/// Define the height and width at end. const width = 2000; const depth = 4000; const height = 1500; const end_width = 0.5 * width; const end_height = 0.25 * height; PD.CAD.addWedge(width, depth, height, end_height, end_width);
/// Define X and Z positions at each end. const width = 2000; const depth = 4000; const height = 1500; const x_min = 0.40 * width; const x_max = 0.75 * width; const z_min = -0.25 * height; const z_max = 0.25 * height; PD.CAD.addWedge(width, depth, height, [ x_min, x_max ], [ z_min, z_max ]);
-
addWire(points [, closed]) <static>
-
Adds an infinitely thin wire with one or more segments to the scene.
This method will cache the generated shape if caching is enabled.
Parameters:
Name Type Argument Description pointsArray.<Array.<number>> An array of [x,y,z] vector arrays defining the vertices of the wire.
closedboolean <optional>
An optional flag indicating that the wire is a closed loop, defaults to false.
Returns:
Returns a wire.
- Type
- oc.TopoDS_Wire
-
addWires(contours) <static>
-
Adds an array of infinitely thin wires with one or more point contours to the scene.
This method will cache the generated wires if caching is enabled.
Parameters:
Name Type Description contoursArray.<Array.<Array.<number>>> An array of lines, each containing at least two [x,y,z] vector arrays defining the vertices of the wire.
Returns:
Returns an array of one or more wires.
- Type
- Array.<oc.TopoDS_Wire>
Example
const text_lines = PD.VectorFont.generateText('This is a test.', PD.ALIGN.CENTER); CAD.addWires(text_lines); -
cancelOperation(state) <static>
-
Sets or clears the cancel operations flags.
Parameters:
Name Type Description stateboolean The name of the operation.
-
checkCache(caller, args, generatorFn) <static>
-
Hashes input arguments and checks the cache for that hash.
This method first checks if a cached result exists and, if so, returns it. If not, it executes the callback and caches the result.
Parameters:
Name Type Description callerstring The name of the calling method.
argsArray.<any> An array of arguments defining the operation.
generatorFnfunction A callback function to execute the operation.
Returns:
Returns the results of the cached function.
- Type
- oc.TopoDS_Shape | Array.<oc.TopoDS_Shape>
-
checkCancelToken() <static>
-
If the URL token is valid and has been revoked, the host application must have cancelled the operation. Thus, this method throws an error in order to abort the process.
Throws:
-
Throws an error if URL token has been revoked.
- Type
- Error
-
-
clearCache() <static>
-
Removes all items from the cache to clear memory.
-
combine(shapes [, makeCopy]) <static>
-
Combines the given shape(s) into a single compound shape.
Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> An array of shapes to combine.
makeCopyboolean <optional>
Apply to copies and keep original shapes in the model, defaults to false.
Returns:
Returns the compound shape.
- Type
- oc.TopoDS_Shape
-
distribute(shapes, spacing [, columns]) <static>
-
Distribute shapes over an XY grid.
This method takes an array of shapes and distributes them over grid with the given spacing. If you want to group items and keep them together, simply include them in a sub-array.
Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> A shape or array of shapes to duplicate.
spacingnumber | Array.<number> A number or [x,y,z] vector array defining the grid cell size in each axis.
columnsnumber <optional>
The number of columns in the X-axis, defaults to 8.
Returns:
Returns the distributed shape(s).
- Type
- oc.TopoDS_Shape | Array.<oc.TopoDS_Shape>
-
duplicate(shapes, offset [, copies]) <static>
-
Adds one or more translated copies of the given shape(s).
If the
copiesargument is a number greater than zero, it specifies the number of duplicate copies to create with the given offset. If thecopiesargument is given as a [copiesX,copiesY,copiesZ] array, that number of shape(s) will be duplicated in each axisParameters:
Name Type Argument Description shapesoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> A shape or array of shapes to duplicate.
offsetArray.<number> An [x,y,z] vector array defining the translation offset in each axis.
copiesnumber | Array.<number> <optional>
The number of copies to create, or [copiesX,copiesY,copiesZ] to array copy, defaults to 1.
Returns:
Returns the duplicated shape(s).
- Type
- oc.TopoDS_Shape | Array.<oc.TopoDS_Shape>
-
error(message) <static>
-
Outputs an error message to the host application and console.
Parameters:
Name Type Description messagestring The error message to log.
-
evaluateCode(payload) <static>
-
Executes/evaluates some JavaScript code sent from the host application.
Parameters:
Name Type Description payloadobject A container object typically sent from the host application.
Properties of
payload:Name Type Description codestring The JavaScript code block to evaluate.
jsonstring The JSON data block to evaluate.
Returns:
Returns an array of faces and edges, of
nullif there was invalid input.- Type
- Array | null
-
extrude(face, vector [, makeCopy]) <static>
-
Extrudes a flat polygonal face into a shape.
Parameters:
Name Type Argument Description faceoc.TopoDS_Shape A flat face shape to extrude.
vectorArray.<number> An [x,y,z] vector array defining the distances to extrude in each axis.
makeCopyboolean <optional>
Apply to a copy and keep original face in the model, defaults to false.
Returns:
Returns the extruded shape.
- Type
- oc.TopoDS_Shape
-
extrudeAndRotate(wire, height, degrees [, makeCopy]) <static>
-
Extrude and rotate a wire into a 3D shape.
Parameters:
Name Type Argument Description wireoc.TopoDS_Shape The wire to extrude.
heightnumber The height of the extrusion in model units.
degreesnumber The angle of rotation in degrees.
makeCopyboolean <optional>
Apply to a copy and keep original wire in the model, defaults to false.
Returns:
Returns the extruded shape.
- Type
- oc.TopoDS_Shape
-
getFace(shape [, index] [, makeCopy]) <static>
-
Extracts a particular face from within a shape.
Parameters:
Name Type Argument Description shapeoc.TopoDS_Shape The shape to extract the face from.
indexnumber <optional>
The ordinal index of the face within the shape, defaults to 0.
makeCopyboolean <optional>
Keep the original shape in the model, defaults to false.
Returns:
Returns the solid at the given index, or the given shape if no matching solid was found.
- Type
- oc.TopoDS_Shape | oc.TopoDS_Face
-
getShapeGeometry(payload) <static>
-
This function accumulates all the shapes in
PD.CAD.modelinto a singleTopoDS_Compoundand converts it to a mesh (and a set of edges) withPD.OCC.shapeToMesh(), and sends it back to the host application.Parameters:
Name Type Description payloadobject A container object typically sent from the host application.
Properties of
payload:Name Type Description maxDeviationnumber The welding tolerance and mesh resolution of the resulting geometry.
Returns:
Returns a [faces,edges] array if successful, otherwise null.
- Type
- Array | null
-
getSolid(shape [, index] [, makeCopy]) <static>
-
Extracts a particular solid from within a compound shape.
Parameters:
Name Type Argument Description shapeoc.TopoDS_Shape The shape to extract the solid from.
indexnumber <optional>
The ordinal index of the solid within the shape, defaults to 0.
makeCopyboolean <optional>
Keep the original solid compound in the model, defaults to false.
Returns:
Returns the solid at the given index, or the given shape if no matching solid was found.
- Type
- oc.TopoDS_Shape | oc.TopoDS_Solid
-
getWire(shape [, index] [, makeCopy]) <static>
-
Extracts a particular wire from within a shape.
Parameters:
Name Type Argument Description shapeoc.TopoDS_Shape The shape to extract the wire from.
indexnumber <optional>
The ordinal index of the wire within the shape, defaults to 0.
makeCopyboolean <optional>
Keep the original shape in the model, defaults to false.
Returns:
Returns the wire at the given index, or the given shape if no matching wire was found.
- Type
- oc.TopoDS_Shape | oc.TopoDS_Wire
-
hollow(shape, faces, thickness [, tolerance] [, makeCopy]) <static>
-
Creates a hollowed out solid from a closed shell.
Parameters:
Name Type Argument Description shapeoc.TopoDS_Shape The shape to hollow out.
facesArray.<oc.TopoDS_Face> An array of one or more faces to remove.
thicknessnumber The thickness of the walls.
tolerancenumber <optional>
The tolerance to use when unioning, defaults to 0.1.
makeCopyboolean <optional>
Apply to a copy and keep original shape in the model, defaults to false.
Returns:
Returns the hollowed out shape.
- Type
- oc.TopoDS_Shape
-
importSTEPorIGES(filename, content) <static>
-
This function parses the ASCII contents of a
.STEPor.IGESfile. and adds the resulting shapes to scene.Parameters:
Name Type Description filenamestring The name of the file.
contentstring The contents of the file.
Returns:
Returns a shape if successfully loaded, otherwise null.
- Type
- oc.TopoDS_Shape | null
-
importSTL(filename, content) <static>
-
This function parses the contents of an ASCII .STL File as a Shape into the
externalShapesdictionary.Parameters:
Name Type Description filenamestring The name of the file.
contentstring The contents of the file.
Returns:
Returns a shape if successfully loaded, otherwise
null.- Type
- oc.TopoDS_Shape | null
-
intersect(shapes [, makeCopy] [, tolerance] [, keepEdges]) <static>
-
Computes the intersection of a set of shapes.
Parameters:
Name Type Argument Description shapesArray.<oc.TopoDS_Shape> An array of shapes to intersect.
makeCopyboolean <optional>
Apply to copies and keep original shapes in the model, defaults to false.
tolerancenumber <optional>
The tolerance to use when intersecting, defaults to 0.1.
keepEdgesboolean <optional>
Whether or not to keep the original edge(s) in the shape, defaults to false.
Returns:
Returns the intersection shape.
- Type
- oc.TopoDS_Shape
-
loft(wires [, makeCopy]) <static>
-
Lofts between a set or wires.
Parameters:
Name Type Argument Description wiresArray.<oc.TopoDS_Shape> The set of wires to loft between.
makeCopyboolean <optional>
Apply to copies and keep original wires in the model, defaults to false.
Returns:
Returns the lofted shape.
- Type
- oc.TopoDS_Shape
-
log(message) <static>
-
Logs a message to the host application and console.
Parameters:
Name Type Description messagestring The message to log.
-
mirror(shapes, axis [, makeCopy]) <static>
-
Mirrors the given shape(s) around a given axis.
Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> A shape or array of shapes to mirror.
axisArray.<number> An [x,y,z] vector array defining the normal to the mirror plane.
makeCopyboolean <optional>
Apply to copies and keep original shapes in the model, defaults to false.
Returns:
Returns the mirrored shape(s).
- Type
- oc.TopoDS_Shape | Array.<oc.TopoDS_Shape>
-
move(shapes, offset [, makeCopy]) <static>
-
Translates the given shape(s) by a relative vector.
This method is simply an alias for
PD.CAD.translate.Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> A shape or array of shapes to translate.
offsetArray.<number> An [x,y,z] vector array defining the translation offset in each axis.
makeCopyboolean <optional>
Apply to copies and keep original shapes in the model, defaults to false.
Returns:
Returns the translated shape(s).
- Type
- oc.TopoDS_Shape | Array.<oc.TopoDS_Shape>
-
offset(shape, distance [, tolerance] [, makeCopy]) <static>
-
Offsets the edges and faces of a shape by the given distance.
Parameters:
Name Type Argument Description shapeoc.TopoDS_Shape The shape to offset.
distancenumber The distance to offset surfaces in the shape.
tolerancenumber <optional>
The tolerance to use when welding offset vertices together, defaults to 0.1.
makeCopyboolean <optional>
Apply to a copy and keep original shape in the model, defaults to false.
Returns:
Returns the offset shape.
- Type
- oc.TopoDS_Shape
-
progress( [operation]) <static>
-
Sends a progress message to the host application.
This is an important message as it informs the host application that the worker is busy and allows it to display the operation name and keep the user informed on what is happening.
The
messageargument should be included only at the very beginning of each operation. For ongoing progress updates, don't include the message argument. When the process is complete, you can call this method with 'Done' as the message, but this is not necessary as the results will automatically be sent to the host application in a message that does not include thebusyindicator, so the host will know that it is complete.Parameters:
Name Type Argument Description operationstring <optional>
The operation name or message.
-
progressMessage(level [, message]) <static>
-
First checks if the process has been cancelled and, if not, adds the given message to the progress log.
The movement of the progress bar should not be affected by the current log level so, if the log level is less than the level of this message, we still need to send
undefinedto the host application to increment it.Parameters:
Name Type Argument Description levellevel The log level of this message.
messagestring <optional>
The message to add to the log.
Throws:
-
Throws and error if process cancelled.
- Type
- Error
-
-
progressOperation(level [, operation]) <static>
-
Check first if the process has been cancelled and, if not, format the operation and add it to the progress log.
The movement of the progress bar should not be affected by the current log level so, if the log level is less than the level of this operation, we still need to send
undefinedto the host application to increment it.Parameters:
Name Type Argument Description levellevel The log level of the operation.
operationstring <optional>
The name of the operation to log.
Throws:
-
Throws and error if process cancelled.
- Type
- Error
-
-
remove(shapes) <static>
-
Removes a shape or array of shapes from the generated model.
Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape <repeatable>
One or more shapes to remove.
-
removeInternalEdges(shape [, makeCopy]) <static>
-
Unifies a shape by cleaning up internal edges.
Parameters:
Name Type Argument Description shapeoc.TopoDS_Shape The shape to clean up.
makeCopyboolean <optional>
Apply to a copy and keep original shape in the model, defaults to false.
Returns:
Returns the unified shape.
- Type
- oc.TopoDS_Shape
-
revolve(shape, degrees [, axis] [, about] [, makeCopy]) <static>
-
Revolves a shape by the given angle and axis.
Parameters:
Name Type Argument Description shapeoc.TopoDS_Shape The shape to revolve.
degreesnumber The angle of revolution in degrees.
axisArray.<number> <optional>
An [x,y,z] vector array defining the axis of revolution, defaults to [ 0, 0, 1 ].
aboutArray.<number> <optional>
An [x,y,z] vector array defining the revolution origin, defaults to the origin.
makeCopyboolean <optional>
Apply to a copy and keep original shape in the model, defaults to false.
Returns:
Returns the revolved shape.
- Type
- oc.TopoDS_Shape
-
rotate(shapes, axis, degrees [, makeCopy]) <static>
-
Rotates the given shape(s) around a given axis.
Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> A shape or array of shapes to rotate.
axisArray.<number> An [x,y,z] vector array defining the axis of rotation.
degreesnumber The angle of rotation in decimal degrees.
makeCopyboolean <optional>
Apply to copies and keep original shapes in the model, defaults to false.
Returns:
Returns the rotated shape(s).
- Type
- oc.TopoDS_Shape | Array.<oc.TopoDS_Shape>
-
rotateX(shapes, degrees [, makeCopy]) <static>
-
Rotates the given shape(s) around the X axis axis.
Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> A shape or array of shapes to rotate.
degreesnumber The angle of rotation in decimal degrees.
makeCopyboolean <optional>
Apply to copies and keep original shapes in the model, defaults to false.
Returns:
Returns the rotated shape(s).
- Type
- oc.TopoDS_Shape | Array.<oc.TopoDS_Shape>
-
rotateY(shapes, degrees [, makeCopy]) <static>
-
Rotates the given shape(s) around the Y axis.
Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> A shape or array of shapes to rotate.
degreesnumber The angle of rotation in decimal degrees.
makeCopyboolean <optional>
Apply to copies and keep original shapes in the model, defaults to false.
Returns:
Returns the rotated shape(s).
- Type
- oc.TopoDS_Shape | Array.<oc.TopoDS_Shape>
-
rotateZ(shapes, degrees [, makeCopy]) <static>
-
Rotates the given shape(s) around the Z axis.
Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> A shape or array of shapes to rotate.
degreesnumber The angle of rotation in decimal degrees.
makeCopyboolean <optional>
Apply to copies and keep original shapes in the model, defaults to false.
Returns:
Returns the rotated shape(s).
- Type
- oc.TopoDS_Shape | Array.<oc.TopoDS_Shape>
-
saveShapeSTEP( [filename]) <static>
-
Generates a STEP file containing the current shape(s).
Parameters:
Name Type Argument Description filenamestring <optional>
The name of the temporary file, defaults to 'ShapeEditorPart.step'.
Returns:
Returns the STEP file content, or
nullif the conversion failed.- Type
- object | null
-
scale(shapes, scale [, makeCopy]) <static>
-
Scales the given shape(s) from the origin.
Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> A shape or array of shapes to scale.
scalenumber A relative scale factor to apply equally in each axis.
makeCopyboolean <optional>
Apply to copies and keep original shapes in the model, defaults to false.
Returns:
Returns the scaled shape(s).
- Type
- oc.TopoDS_Shape | Array.<oc.TopoDS_Shape>
-
setCancelToken( [token]) <static>
-
Sets the URL token used for cancelling operations.
Parameters:
Name Type Argument Description tokenstring <optional>
A revokable URL token.
-
setLogLevel(level) <static>
-
Sets or clears the cancel operations flags.
Parameters:
Name Type Description levelnumber The level to log at (0 to 3).
-
subtract(mainBody, shapesToSubtract [, makeCopy] [, tolerance] [, keepEdges]) <static>
-
Subtracts a set of shapes from a main body shape.
Parameters:
Name Type Argument Description mainBodyoc.TopoDS_Shape The shape to subtract from.
shapesToSubtractoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> An array of shapes to subtract.
makeCopyboolean <optional>
Apply to copies and keep original shapes in the model, defaults to false.
tolerancenumber <optional>
The tolerance to use when subtracting, defaults to 0.1.
keepEdgesboolean <optional>
Whether or not to keep the original edge(s) in the shape, defaults to false.
Returns:
Returns the resulting shape.
- Type
- oc.TopoDS_Shape
-
sweep(shape, path [, makeCopy]) <static>
-
Creates a pipe by sweeping a shape along a wire path.
Parameters:
Name Type Argument Description shapeoc.TopoDS_Shape The shape to sweep along the path.
pathoc.TopoDS_Wire A wire defining the path to sweep the shape along.
makeCopyboolean <optional>
Apply to a copy and keep original shape in the model, defaults to false.
Returns:
Returns the swept shape.
- Type
- oc.TopoDS_Shape
-
translate(shapes, offset [, makeCopy]) <static>
-
Translates the given shape(s) by a relative vector.
Parameters:
Name Type Argument Description shapesoc.TopoDS_Shape | Array.<oc.TopoDS_Shape> A shape or array of shapes to translate.
offsetArray.<number> An [x,y,z] vector array defining the translation offset in each axis.
makeCopyboolean <optional>
Apply to copies and keep original shapes in the model, defaults to false.
Returns:
Returns the translated shape(s).
- Type
- oc.TopoDS_Shape | Array.<oc.TopoDS_Shape>
-
union(shapes [, makeCopy] [, tolerance] [, keepEdges]) <static>
-
Combines a set of shapes into a single unioned shape.
Parameters:
Name Type Argument Description shapesArray.<oc.TopoDS_Shape> An array of shapes to combine.
makeCopyboolean <optional>
Apply to copies and keep original shapes in the model, defaults to false.
tolerancenumber <optional>
The tolerance to use when unioning, defaults to 0.1.
keepEdgesboolean <optional>
Whether or not to keep the original edge(s) in the shape, defaults to false.
Returns:
Returns the unioned shape.
- Type
- oc.TopoDS_Shape