def attdef(tag, insert=(0., 0.), **kwargs): """ Create a new attribute definition, used in block-definitions. :param str text: attribute default text :param insert: insert point (xy- or xyz-tuple), z-axis is 0 by default :param str prompt: prompt text, like "insert a value:" :param str tag: attribute tag string :param int flags: attribute flags, bit-coded, default=0 :param int length: field length ??? see dxf-documentation :param float height: textheight in drawing units (default=1) :param float rotation: text rotation (default=0) (all DXF angles in degrees) :param float oblique: text oblique angle in degree, default=0 :param float xscale: width factor (default=1) :param str style: textstyle (default=STANDARD) :param int mirror: bit coded flags :param int halign: horizontal justification type, LEFT, CENTER, RIGHT, ALIGN, FIT, BASELINE_MIDDLE (default LEFT) :param int valign: vertical justification type, TOP, MIDDLE, BOTTOM, BASELINE (default BASELINE) :param alignpoint: align point (xy- or xyz-tuple), z-axis is 0 by default, if the justification is anything other than BASELINE/LEFT, alignpoint specify the alignment point (or the second alignment point for ALIGN or FIT). """ return Attdef(tag=tag, insert=insert, **kwargs)
def test_find_attdef(self): blocks = Blocks() block = Block(name='TEST') block.add(Attdef(tag='ATT1', text='TEXT1')) blocks.add(block) found = blocks.find_attdef(tag='ATT1', blockname='TEST') self.assertEqual(found['text'], 'TEXT1') self.assertRaises(KeyError, blocks.find_attdef, 'ATT2', 'TEST') self.assertRaises(KeyError, blocks.find_attdef, 'ATT1', 'TEST2')
def test_attdef_all_attribs(self): attdef = Attdef(length=99, rotation=30, xscale=1.5, oblique=75, style='ARIAL', mirror=1, halign=1, valign=2, alignpoint=(5, 5)) expected = " 0\nATTDEF\n 8\n0\n 10\n0.0\n 20\n0.0\n 30\n0.0\n" \ " 40\n1.0\n 1\nAttrib\n 3\nInput:\n 2\nATTRIB\n 70\n0\n" \ " 73\n99\n 50\n30.0\n 41\n1.5\n 51\n75.0\n 7\nARIAL\n" \ " 71\n1\n 72\n1\n 74\n2\n 11\n5.0\n 21\n5.0\n 31\n0.0\n" self.assertEqual(dxfstr(attdef), expected)
def test_create_tag_unchanged(self): attdef = Attdef() attrib = attdef.new_attrib(tag="UNCHANGED") expected = " 0\nATTRIB\n 8\n0\n 10\n0.0\n 20\n0.0\n 30\n0.0\n" \ " 40\n1.0\n 1\nAttrib\n 2\nATTRIB\n 70\n0\n" self.assertEqual(dxfstr(attrib), expected)
def test_create_with_override(self): attdef = Attdef(layer='test') attrib = attdef.new_attrib(layer='xxx', insert=(2, 2)) expected = " 0\nATTRIB\n 8\nxxx\n 10\n2.0\n 20\n2.0\n 30\n0.0\n" \ " 40\n1.0\n 1\nAttrib\n 2\nATTRIB\n 70\n0\n" self.assertEqual(dxfstr(attrib), expected)
def test_create(self): attdef = Attdef(layer='test') attrib = attdef.new_attrib(text='newtext') expected = " 0\nATTRIB\n 8\ntest\n 10\n0.0\n 20\n0.0\n 30\n0.0\n" \ " 40\n1.0\n 1\nnewtext\n 2\nATTRIB\n 70\n0\n" self.assertEqual(dxfstr(attrib), expected)
def test_attdef_simple(self): attdef = Attdef() expected = " 0\nATTDEF\n 8\n0\n 10\n0.0\n 20\n0.0\n 30\n0.0\n" \ " 40\n1.0\n 1\nAttrib\n 3\nInput:\n 2\nATTRIB\n 70\n0\n" self.assertEqual(dxfstr(attdef), expected)