Blocks and attributes

An INSERT places a block, and its attributes are the texts it carries. This page has INSERTs, attributes, MINSERTs and making an INSERT static; dynamic blocks have pages of their own.

INSERTs

An INSERT is a DxfBlockReference. The INSERT of BOLT at (50, 60, 0) turned by 45 degrees and scaled by (1.5, -1.5, 2) has Position (50, 60, 0), Rotation 0.785 and a BlockTransform that takes BOLT's origin (1, 2, 0) to the insertion point; the block's point (0, 0, 0) lands at (46.82, 61.06, 0). Setting Position to (60, 55, 1) moves its ATTRIB MARK from (50, 59, 0) to (60, 54, 1): an INSERT moved, turned, scaled or given a new normal carries its attributes with it. Name is the block it places, BlockTableRecord that block; BlockName is the block it is in. new DxfBlockReference(position, block) places a block of the drawing.

Attributes

Its attributes are DxfAttributeReference objects (Tag, TextString, owned by the INSERT) in its AttributeCollection: AppendAttribute adds one, SetAttributeFromBlock fills one from its ATTDEF, and erasing one keeps the others' handles. An ATTDEF is a DxfAttributeDefinition with its Prompt. An attribute of several lines embeds an MTEXT from R2018: IsMTextAttribute makes one of its value where its text stands, or takes it out, MTextAttribute gives and takes the MTEXT, its text made to agree as ezdxf's set_mtext makes it but for its value, the words of every line joined by spaces as AutoCAD 2021 reads it (LINE ONE LINE TWO LINE THREE for three lines, where ezdxf writes the first). AutoCAD writes an empty group 1 in an ATTRIB of several lines it makes, but reads the library's as its own, and a reader that does not read the MTEXT needs the words there, so the ATTRIB keeps them. An ATTDEF of several lines writes the MTEXT's contents in its group 1, its lines apart by \P (LINE ONE\PLINE TWO\PLINE THREE), as AutoCAD 2021 writes its own; made one of one line it keeps its first line. The TextString of an ATTRIB or ATTDEF of several lines is the words of the lines of its MTEXT joined by spaces, whatever its group 1 holds, as AutoCAD 2021 reads both: LINE ONE LINE TWO LINE THREE of the definition above, and of an ATTRIB AutoCAD wrote with an empty group 1. Setting it sets the words of the MTEXT, which keeps its place and look, its backslashes and braces written as codes, and its group 1 made to agree: the ATTRIB of three lines set to M24 GALV is an MTEXT of one line M24 GALV, still an attribute of several lines. UpdateMTextAttribute() places the MTEXT again where the text stands, after the attribute is moved or set from its definition. A MINSERT is a DxfMInsertBlock with its Columns, Rows, ColumnSpacing and RowSpacing: a cell stands one spacing on along the axes of the INSERT's own plane, turned by its angle, so that in the plan an array of a plane tilted 45 degrees about X (its normal (0, -0.7071, 0.7071)), its rows 40 apart, shows them 28.28 apart, each 28.28 higher, as AutoCAD 2021 draws them.

Clipping an INSERT

An INSERT, a MINSERT and an INSERT of an external reference are clipped as AutoCAD 2021's XCLIP clips them. insert.ClipTo(points, worldToClip) writes a DxfSpatialFilter, a SPATIAL_FILTER named SPATIAL in the dictionary ACAD_FILTER of the INSERT's extension dictionary, both made as AutoCAD makes them (owned hard, the filter owned by its dictionary, its class listed and counted in CLASSES). points is the boundary in the clip coordinate system, the UCS that is current: two points are a rectangle's opposite corners, three or more a polygon, and worldToClip carries a point of the world into it (GeoTransform3.Identity for the world's). The filter keeps, as AutoCAD does, the boundary as picked, the matrix from the world into the clip system, the inverse of the INSERT's placing as it stood (a block 100 by 100 inserted at (1000, 0) clipped to (1010, 10) and (1090, 90) keeps the shift by -1000) and the clip system's origin and normal; a clip is kept against the block, so that the INSERT moved, turned, scaled or copied shows the same part of it. insert.ClipOutline gives the boundary as a ring in the block's own coordinates, a rectangle as its four corners: a block whose origin is (10, 20) clipped to the rectangle that covers its lower left corner 40 by 30 is (10, 20), (50, 20), (50, 50), (10, 50), whatever the INSERT is moved to. insert.SpatialFilter reads the filter, null for an INSERT not clipped: its Points, Normal and Origin, the matrices InverseBlockTransform and WorldToClip (twelve numbers each, row by row), and IsEnabled, FrontClip and BackClip, which are set (the clip off, the planes at a distance from the boundary or none). insert.RemoveClip() takes the filter off, and the dictionary ACAD_FILTER with it where that holds nothing else, leaving the extension dictionary as AutoCAD leaves it. A clip turned inside out is kept as a polygon with a slit round the block's extents, as AutoCAD keeps it: CadXClips.Inverted of the presenter makes it. A filter is read from and written to a DWG of R2000 and later with the rest of the objects, and AutoCAD 2021 reads both, its AUDIT finding nothing. A boundary in a plane tilted to the drawing's is kept whole; the presenter draws its frame as its projection on the plan and the block where the boundary's prism cuts the block's plane, as AutoCAD 2021 does (a line or a curve that does not lie flat where its path leaves the prism), and its front and back planes cut the block in height: a line, circle, arc, ellipse, spline or polyline, 2D and 3D included, that crosses one is cut at it, a dashed one carrying on the pattern of the whole; a text, an MTEXT, a hatch, a solid or a 3D face in a plane that is tilted out of the plan is cut where the planes meet its plane, as the strip of the plan between them.

The clip of an INSERT of an external reference is kept in the drawing's own coordinates, base point and all, as AutoCAD 2021 keeps it (entget of the filter of a drawing whose base point is (70, 0, 0), attached at (100, 0, 0) and clipped to the rectangle (130, 10) to (190, 40) of the world: the inverse of the placing is the shift by -30, and the boundary the drawing's x 100 to 160): ClipTo writes it so and ClipOutline gives the ring so, where an ordinary block's is measured from its origin (the shift by -100 there). The boundary and the content of the drawing move together when the drawing's base point changes (a clip of 20 to 80 on a drawing reloaded with its base point at 70 stands from -50 to 10, AutoCAD 2021's PNGOUT of it). The presenter places the ring by the base point the drawing has now and makes a boundary picked at x 130 to 190 stand there; the library, which has only the origin the block records, takes that origin for the base point. A clip of an external reference made by an earlier version, which kept the boundary from the insertion point, is read as the drawing's own coordinates, and stands a base point away where that is not the origin.

Units and extents

UnitFactor takes the block's units to the drawing's ($INSUNITS): 25.4 for a block in inches inserted in millimetres, 1 where either gives none. GeometryExtentsBestFit() is the box of the shapes placed, and GeometryExtentsBestFit(parentTransform) the same after an outer INSERT's BlockTransform; a MINSERT has none (InvalidOperationException, as AutoCAD 2021 threw eInvalidExtents), its GeometricExtents its first cell's, and its TreatAsBlockRefForExplode false. A MINSERT is one by its subclass AcDbMInsertBlock, of one cell too, or by its counts in R12.

Making an INSERT static

insert.ConvertToStaticBlock("BOLT_500") makes the INSERT place a new block BOLT_500 holding copies of what it draws, the anonymous block's entities (or the dynamic block's, where it places that), its tie to the dynamic block (the entry AcDbBlockRepresentation of its extension dictionary) taken out; ConvertToStaticBlock() names the copy as AutoCAD names an anonymous block, *U1 the first the drawing has not, and no INSERT of it names: a drawing whose PPP holds an INSERT of *U1, a block it has not, gets *U2. A name given that an INSERT of the drawing names, which would then place the new block, is refused where that block would come to insert itself through it, PPP holding an INSERT of MM and the block made static an INSERT of PPP; nothing is written then. Exploding an INSERT is set out under Editing rules.

See also