Function Reference: geom.read

drafting: C = geom.read (FILE)

drafting: C = geom.read (FILE, 'Layer', LAYER)

drafting: G = geom.read (FILE, 'Type', TYPE)

drafting: G = geom.read (FILE, 'Type', TYPE, 'Layer', LAYER)

Read geom objects from an ASCII DXF file.

C = geom.read (FILE) returns what is in FILE: a row cell array with one geom object per entity, in the order of the file, nothing joined and nothing reclassified. LINE, ARC, CIRCLE, LWPOLYLINE and a flat POLYLINE are geom.Polyline objects; SPLINE and ELLIPSE are geom.Spline objects, an ellipse as its exact rational spline; a HATCH gives the geom.Region objects it fills. A LINE slanting in three dimensions and a 3-D POLYLINE are geom.Path objects, since no single plane holds them. Text, dimensions, inserts, points, meshes and solids are skipped. An empty file gives cell (1, 0).

A group the package wrote, through the write method of a geom.Path or geom.Region or through geom.write, is one element, the class its extended data names, so what was written is what is read: a closed path stays a path, the route solid.sweep turns into a ring, and a region keeps its holes.

Frames. Every geom object carries a geom.UCS, which the package writes as extended data and reads back, for a flat object only where the stored axes still lie in the entity’s plane. A file without that data is read in any plane: an entity whose normal is the z axis in the world frame moved to its height, one whose normal points down the z axis mirrored into the plane facing up first, as 2-D CAD programs treat it, and any other in DXF’s own frame for its plane. Paths and splines are read in world coordinates.

C = geom.read (FILE, 'Layer', LAYER) returns only what lies on the layer LAYER, its name compared without regard to case, as CAD programs compare them.

G = geom.read (FILE, 'Type', TYPE) builds the class TYPE names and returns one object of it:

'polyline'
A geom.Polyline, from one entity.
'spline'
A geom.Spline, from one entity.
'path'
A geom.Path, the entities chained end to end by geom.Path.chain.
'region'
A geom.Region, the entities chained into closed loops and the loops that share a plane nested by geom.Region.nest, an outline and its holes.

The package’s own groups count as built. Exactly one object must result. More than one is an error naming the layer, as is finding objects on several layers with no 'Layer' given, and finding none: separate parts belong on separate layers, and 'Layer' picks one.

The width of a polyline is dropped, since a geom object has none. Whatever is skipped, the widths dropped, and with 'Type' whatever is left over, are reported in one warning, counted by entity type.

Coordinates are converted to millimetres from the units the file declares in $INSUNITS; a file declaring none is read as millimetres. The reader takes ASCII DXF from R12 (AC1009) to R2018 (AC1032). Text before R2007 is decoded from the code page the header names, and from R2007 on as UTF-8. A binary DXF is an error.

 
 R = geom.Region (geom.Polyline ([0, 0; 60, 0; 60, 40; 0, 40], ...
                                 'Closed', true));
 f = [tempname(), '.dxf'];
 write (R, f);
 B = geom.read (f, 'Type', 'region');
 S = solid.extrude (B, 10);

See also: geom.write, geom.Polyline.write, geom.Spline.write, geom.Path.write, geom.Region.write, draw.read

Source Code: geom.read