def test_from_points(self): box = ConstructionBox.from_points((2, 1), (4, 5)) assert box.center == (3, 3) assert box.width == 2 assert box.height == 4 assert box.angle == 0 # reverse order, same result box = ConstructionBox.from_points((4, 5), (2, 1)) assert box.center == (3, 3) assert box.width == 2 assert box.height == 4 assert box.angle == 0
def block_content_horizontal( name: str, align: mleader.BlockAlignment, base_point=Vec2(0, 0), block_scale=1.0, block_rotation=0.0, overall_scale=1.0, ): x1, y1, x2, y2 = -40, -40, 60, 40 construction_box = ConstructionBox.from_points((x1, y1), (x2, y2)) doc = ezdxf.new(DXFVERSION, setup=True) block = create_block(doc, size=8.0, margin=0.25, base_point=base_point) msp = doc.modelspace() ml_builder = msp.add_multileader_block(style="Standard") ml_builder.set_content(name=block.name, alignment=align, scale=block_scale) ml_builder.set_overall_scaling(overall_scale) ml_builder.set_attribute("ONE", "Data1") ml_builder.set_attribute("TWO", "Data2") # Construction plane of the entity is defined by an render UCS. # The default render UCS is the WCS. # The leader lines vertices are expected in render UCS coordinates, which # means relative to the UCS origin! # This example shows the simplest way UCS==WCS! ml_builder.add_leader_line(mleader.ConnectionSide.right, [Vec2(x2, y1)]) ml_builder.add_leader_line(mleader.ConnectionSide.right, [Vec2(x2, y2)]) ml_builder.add_leader_line(mleader.ConnectionSide.left, [Vec2(x1, y1)]) ml_builder.add_leader_line(mleader.ConnectionSide.left, [Vec2(x1, y2)]) # The insert point (in UCS coordinates is the insert location for BLOCK # content: insert = Vec2(5, 2) ml_builder.build(insert=insert, rotation=block_rotation) # visual additions: msp.add_circle(insert, radius=0.25) # show the insertion point msp.add_lwpolyline(construction_box.corners, close=True) # draw target box doc.set_modelspace_vport( construction_box.width, center=construction_box.center ) doc.saveas(OUTDIR / f"{name}_{DXFVERSION}.dxf")
def block_content_vertical( name: str, align: mleader.BlockAlignment, base_point=Vec2(0, 0), block_scale=1.0, block_rotation=0.0, overall_scale=1.0, ): x1, y1, x2, y2 = -30, -30, 30, 30 construction_box = ConstructionBox.from_points((x1, y1), (x2, y2)) doc = ezdxf.new(DXFVERSION, setup=True) block = create_block(doc, size=8.0, margin=0.25, base_point=base_point) msp = doc.modelspace() ml_builder = msp.add_multileader_block(style="Standard") ml_builder.set_content( name=block.name, alignment=align, scale=block_scale ) # block scale ml_builder.set_overall_scaling(overall_scale) ml_builder.set_attribute("ONE", "Data1") ml_builder.set_attribute("TWO", "Data2") ml_builder.add_leader_line(mleader.ConnectionSide.top, [Vec2(x1, y2)]) ml_builder.add_leader_line(mleader.ConnectionSide.top, [Vec2(x2, y2)]) ml_builder.add_leader_line(mleader.ConnectionSide.bottom, [Vec2(x1, y1)]) ml_builder.add_leader_line(mleader.ConnectionSide.bottom, [Vec2(x2, y1)]) # The insert point (in UCS coordinates= is the insert location for BLOCK # content: insert = Vec2(5, 2) ml_builder.build(insert=insert, rotation=block_rotation) # visual additions: msp.add_circle(insert, radius=0.25) # show the insertion point msp.add_lwpolyline(construction_box.corners, close=True) # draw target box doc.set_modelspace_vport( construction_box.width, center=construction_box.center ) doc.saveas(OUTDIR / f"{name}_{DXFVERSION}.dxf")