Class Definition: 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.

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 in its part’s colour. 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: 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 shape (A) in the model.Viewer kept for the variable, as solid.Shape.show does, each part in its colour, or tessellate (A) when a part is a mesh. V = show (A) also returns the viewer.

See also: model.Viewer, 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, keeps its structure: each part once, with its name and colours, 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 (…, 'Tolerance', TOL) sets, for a mesh, how far its facets may stray from the parts’ surfaces, as solid.Shape.tessellate takes it, 0.01 by default.

See also: model.read, solid.Shape.write

model.Assembly: N = numparts (A)

See also: model.Assembly.numinstances

model.Assembly: N = numinstances (A)

See also: model.Assembly.numparts

model.Assembly: TF = isempty (A)