model.Assembly
drafting: model.Assembly
Named parts placed together.
model.Assembly holds a product as CAD programs exchange one: a
tree of named parts, each placed in the frame of a geom.UCS, and
of assemblies placed the same way, each part a solid.Shape or a
polymesh.Mesh. A part is defined once and placed as often as it
is used, so the twenty pins of a ring are one part placed twenty
times, as STEP and 3MF keep them. Each part keeps its colours.
pin = solid.cylinder (2, 12);
pin.Colour = [0.8, 0.8, 0.8];
A = model.Assembly ('ring');
A = add (A, 'plate', solid.box (60, 60, 4), ...
geom.UCS ([0, 0, 1], [-30, -30, -4]));
A = add (A, 'pin', pin, geom.UCS ([0, 0, 1], [20, 0, 0]));
A = add (A, 'pin', [], geom.UCS ([0, 0, 1], [-20, 0, 0]));
write (A, 'ring.step');
|
The class is a value class: add returns a new assembly and
leaves its operand unchanged.
See also: model.read, solid.Shape, geom.UCS
Source Code: model.Assembly
The model.Assembly class contains the following properties:
The name STEP gives the product.
A struct array with the fields name and item, the
solid.Shape, polymesh.Mesh or model.Assembly
defined under that name, one element for each part however often it
is placed.
A struct array with the fields name, the name of the placement,
part, the name of the part placed, and placement, the
geom.UCS whose frame the part’s own coordinates are taken in.
The model.Assembly class offers the following public methods:
model.Assembly: A = model.Assembly ()
model.Assembly: A = model.Assembly (NAME)
A = model.Assembly (NAME) returns an assembly named
NAME, 'assembly' by default, with no parts; add
places them.
model.Assembly: A = add (A, NAME, X, U)
model.Assembly: A = add (A, NAME, [], U)
model.Assembly: A = add (…, 'Name', INSTANCE)
A = add (A, NAME, X, U) places
X, a solid.Shape, a polymesh.Mesh or a
model.Assembly, as the part named NAME, its own
coordinates taken in the frame of the geom.UCS U. The
frame is a rigid placement: a part mirrored is another part, made
with solid.Shape.mirror or polymesh.Mesh.mirror.
The first use of a name defines the part. A later use places the same
part again, and gives the same X, or [] for it; another
X under a name already used is an error, and so is an empty one,
a shape, a mesh or an assembly with nothing in it. The same means stored
the same, not only shaped the same: a shape read back from a file is
another shape, so a part is best placed again with [].
Each placement is named after its part, NAME the first time and
then NAME:2, NAME:3 and so on;
'Name' names it INSTANCE instead, which must not be used
already.
See also: model.Assembly.shape
model.Assembly: S = shape (A)
S = shape (A) returns a solid.Shape holding
the solids of every part where the assembly places it, sub-assemblies
included, each with the solid.Shape.Colour and
solid.Shape.Name its part gives it. The solids are kept apart,
not united, so parts that touch stay separate solids. This is the
shape to measure, cut, show or tessellate. The empty assembly gives
the empty shape. An assembly with a mesh among its parts has no exact
shape and is an error; tessellate gives it whole as a mesh.
See also: model.Assembly.tessellate, model.Assembly.write, solid.Shape
model.Assembly: L = solids (A)
L = solids (A) returns an N-by-1 struct
array, an element for each of the N solids of
shape (A), in that order, with the fields:
index | its index in shape (A), from 1 to
N |
name | the solid.Shape.Name its part gives it,
'' where it has none |
colour | the solid.Shape.Colour its part gives
it, a row of NaN where it has none |
path | a cell row of placement names, from the placement in A down through each sub-assembly to the placement of its part |
part | the name of the part it belongs to |
model.Viewer.opacity takes a path, or a name from either field,
to choose which solids to hide or show through. An assembly with a
mesh among its parts has no solids to list and is an error.
pin = solid.cylinder (2, 12);
B = add (model.Assembly ('stage'), 'pin', pin, geom.UCS ());
A = add (model.Assembly ('top'), 'base', solid.box (40, 40, 4), ...
geom.UCS ([0, 0, 1], [-20, -20, -4]));
A = add (A, 'stage', B, geom.UCS ([0, 0, 1], [0, 0, 10]));
L = solids (A);
L(2).path
⇒ {'stage', 'pin'}
|
See also: model.Assembly.shape, solid.Shape.solids, model.Viewer.opacity
model.Assembly: M = tessellate (A)
model.Assembly: M = tessellate (A, TOL)
M = tessellate (A, TOL) returns a
polymesh.Mesh of every part where the assembly places it,
sub-assemblies included: each solid part as
solid.Shape.tessellate makes it within TOL millimetres,
0.01 by default, and each mesh part as it is. The parts keep their
own vertices, so parts that touch are not joined. A triangle keeps
its part’s colour, and is grey where its part has none, when any
part has one. The empty assembly gives the empty mesh.
See also: model.Assembly.shape, solid.Shape.tessellate
model.Assembly: show (A)
model.Assembly: V = show (A)
show (A) shows the assembly in the model.Viewer
kept for the variable, as solid.Shape.show does: drawn as
shape (A), each part in its colour, or as
tessellate (A) when a part is a mesh. The viewer keeps
the assembly, so model.Viewer.opacity can hide its solids or
show them through by the names and paths model.Assembly.solids
lists. V = show (A) also returns the viewer.
See also: model.Viewer, model.Viewer.opacity, solid.Shape.show
model.Assembly: write (A, FILE)
model.Assembly: write (A, FILE, 'Tolerance', TOL)
write (A, FILE) writes the assembly in the format the
extension of FILE names, in either case. A STEP file, .step
or .stp, keeps its structure: each part once, with its name, its
colours and the solid.Shape.Name of its solids, placed by its
placements, which carry their names, and each sub-assembly the same way,
so that a CAD program opens the product as it was built; it cannot hold a
mesh part. A 3MF file, the archive slicers take, keeps the same
structure, each part a mesh written once and placed as a component, in
its colours. 3MF has no place for the name of a placement, so
model.read names the placements of a 3MF file after their
parts. An STL, OBJ or PLY file holds tessellate (A).
write (…, sets, for a
mesh, how far its facets may stray from the parts’ surfaces, as
'Tolerance', TOL)solid.Shape.tessellate takes it, 0.01 by default.
See also: model.read, solid.Shape.write
model.Assembly: TF = isempty (A)