block.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Created: 25.03.2011
  2. # Copyright (c) 2011-2018, Manfred Moitzi
  3. # License: MIT License
  4. from ezdxf.lldxf.const import LAYOUT_NAMES
  5. from .graphics import GraphicEntity, ExtendedTags, make_attribs, DXFAttr, DXFAttributes, DefSubclass, XType
  6. _BLOCK_TPL = """0
  7. BLOCK
  8. 5
  9. 0
  10. 8
  11. 0
  12. 2
  13. BLOCKNAME
  14. 3
  15. BLOCKNAME
  16. 70
  17. 0
  18. 10
  19. 0.0
  20. 20
  21. 0.0
  22. 30
  23. 0.0
  24. 1
  25. """
  26. class Block(GraphicEntity):
  27. __slots__ = ()
  28. TEMPLATE = ExtendedTags.from_text(_BLOCK_TPL)
  29. DXFATTRIBS = make_attribs({
  30. 'name': DXFAttr(2),
  31. 'name2': DXFAttr(3),
  32. 'flags': DXFAttr(70),
  33. 'base_point': DXFAttr(10, xtype=XType.any_point),
  34. 'xref_path': DXFAttr(1),
  35. })
  36. # block entity flags
  37. # This is an anonymous block generated by hatching, associative dimensioning,
  38. # other internal operations, or an application
  39. ANONYMOUS = 1
  40. # This block has non-constant attribute definitions (this bit is not set if the block has
  41. # any attribute definitions that are constant, or has no attribute definitions at all)
  42. NON_CONSTANT_ATTRIBUTES = 2
  43. XREF = 4 # This block is an external reference (xref)
  44. XREF_OVERLAY = 8 # This block is an xref overlay
  45. EXTERNAL = 16 # This block is externally dependent
  46. RESOLVED = 32 # This is a resolved external reference, or dependent of an external reference (ignored on input)
  47. REFERENCED = 64 # This definition is a referenced external reference (ignored on input)
  48. @property
  49. def is_layout_block(self) -> bool:
  50. """
  51. True if block is a model space or paper space block definition.
  52. """
  53. name = self.dxf.name.lower()
  54. return any(name.startswith(layout_name) for layout_name in LAYOUT_NAMES)
  55. class EndBlk(GraphicEntity):
  56. __slots__ = ()
  57. TEMPLATE = ExtendedTags.from_text(" 0\nENDBLK\n 5\n0\n")
  58. DXFATTRIBS = DXFAttributes(DefSubclass(None, {'handle': DXFAttr(5)}))