dxflayout.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. # Created: 22.03.2011
  2. # Copyright (c) 2011-2018, Manfred Moitzi
  3. # License: MIT-License
  4. from .dxfobjects import DXFObject, none_subclass, ExtendedTags, DXFAttr, DXFAttributes, DefSubclass, XType
  5. plot_settings_subclass = DefSubclass('AcDbPlotSettings', {
  6. 'page_setup_name': DXFAttr(1),
  7. 'plot_configuration_file': DXFAttr(2),
  8. 'paper_size': DXFAttr(4),
  9. 'plot_view_name': DXFAttr(6),
  10. 'left_margin': DXFAttr(40), # in mm
  11. 'bottom_margin': DXFAttr(41), # in mm
  12. 'right_margin': DXFAttr(42), # in mm
  13. 'top_margin': DXFAttr(43), # in mm
  14. 'paper_width': DXFAttr(44), # in mm
  15. 'paper_height': DXFAttr(45), # in mm
  16. 'plot_origin_x_offset': DXFAttr(46, default=0.), # in mm
  17. 'plot_origin_y_offset': DXFAttr(47, default=0.), # in mm
  18. 'plot_window_x1': DXFAttr(48, default=0.),
  19. 'plot_window_y1': DXFAttr(49, default=0.),
  20. 'plot_window_x2': DXFAttr(140, default=0.),
  21. 'plot_window_y2': DXFAttr(141, default=0.),
  22. 'scale_numerator': DXFAttr(142, default=1.), # Numerator of custom print scale: real world (paper) units
  23. 'scale_denominator': DXFAttr(143, default=1.), # Denominator of custom print scale: drawing units
  24. 'plot_layout_flags': DXFAttr(70),
  25. # 1 = Plot Viewport Borders
  26. # 2 = Show Plot Styles
  27. # 4 = Plot Centered
  28. # 8 = Plot Hidden
  29. # 16 = Use Standard Scale
  30. # 32 = Plot Plot Styles
  31. # 64 = Scale Lineweights
  32. # 128 = Print Lineweights
  33. # 512 = Draw Viewports First
  34. # 1024 = Model Type
  35. # 2048 = Update Paper
  36. # 4096 = Zoom To Paper On Update
  37. # 8192 = Initializing
  38. # 16384 = Prev PlotInit
  39. 'plot_paper_units': DXFAttr(72), # 0 = Plot in inches; 1 = Plot in millimeters; 2 = Plot in pixels
  40. 'plot_rotation': DXFAttr(73),
  41. # 0 = No rotation
  42. # 1 = 90 degrees counterclockwise
  43. # 2 = Upside-down
  44. # 3 = 90 degrees clockwise
  45. 'plot_type': DXFAttr(74),
  46. # 0 = Last screen display
  47. # 1 = Drawing extents
  48. # 2 = Drawing limits
  49. # 3 = View specified by code 6
  50. # 4 = Window specified by codes 48, 49, 140, and 141
  51. # 5 = Layout information
  52. 'current_style_sheet': DXFAttr(7),
  53. 'standard_scale_type': DXFAttr(75),
  54. # 0 = Scaled to Fit
  55. # 1 = 1/128"=1'
  56. # 2 = 1/64"=1'
  57. # 3 = 1/32"=1'
  58. # 4 = 1/16"=1'
  59. # 5 = 3/32"=1'
  60. # 6 = 1/8"=1'
  61. # 7 = 3/16"=1'
  62. # 8 = 1/4"=1'
  63. # 9 = 3/8"=1'
  64. # 10 = 1/2"=1'
  65. # 11 = 3/4"=1'
  66. # 12 = 1"=1'
  67. # 13 = 3"=1'
  68. # 14 = 6"=1'
  69. # 15 = 1'=1'
  70. # 16 = 1:1
  71. # 17 = 1:2
  72. # 18 = 1:4
  73. # 19 = 1:8
  74. # 20 = 1:10
  75. # 21 = 1:16
  76. # 22 = 1:20
  77. # 23 = 1:30
  78. # 24 = 1:40
  79. # 25 = 1:50
  80. # 26 = 1:100
  81. # 27 = 2:1
  82. # 28 = 4:1
  83. # 29 = 8:1
  84. # 30 = 10:1
  85. # 31 = 100:1
  86. # 32 = 1000:1
  87. 'shade_plot_mode': DXFAttr(76), # 0 = As Displayed; 1 = Wireframe; 2 = Hidden; 3 = Rendered
  88. 'shade_plot_resolution_level': DXFAttr(77),
  89. # 0 = Draft
  90. # 1 = Preview
  91. # 2 = Normal
  92. # 3 = Presentation
  93. # 4 = Maximum
  94. # 5 = Custom
  95. 'shade_plot_custom_dpi': DXFAttr(78),
  96. # Valid range: 100 to 32767, Only applied when the shade_plot_resolution level is set to 5 (Custom)
  97. 'unit_factor': DXFAttr(147),
  98. # 147: factor for unit conversion (mm -> inches)
  99. # 147: DXF Reference error 'A floating point scale factor that represents the standard scale value specified in code 75'
  100. 'paper_image_origin_x': DXFAttr(148),
  101. 'paper_image_origin_y': DXFAttr(149),
  102. 'shade_plot_handle': DXFAttr(333),
  103. })
  104. class DXFPlotSettings(DXFObject):
  105. __slots__ = ()
  106. DXFATTRIBS = DXFAttributes(none_subclass, plot_settings_subclass)
  107. # removed reactors 5 .. 102 330 102 .. 330
  108. _LAYOUT_TPL = """0
  109. LAYOUT
  110. 5
  111. 0
  112. 330
  113. 1A
  114. 100
  115. AcDbPlotSettings
  116. 1
  117. 2
  118. Adobe PDF
  119. 4
  120. A4
  121. 6
  122. 40
  123. 3.175
  124. 41
  125. 3.175
  126. 42
  127. 3.175
  128. 43
  129. 3.175
  130. 44
  131. 209.91
  132. 45
  133. 297.03
  134. 46
  135. 0.0
  136. 47
  137. 0.0
  138. 48
  139. 0.0
  140. 49
  141. 0.0
  142. 140
  143. 0.0
  144. 141
  145. 0.0
  146. 142
  147. 1.0
  148. 143
  149. 1.0
  150. 70
  151. 688
  152. 72
  153. 0
  154. 73
  155. 1
  156. 74
  157. 5
  158. 7
  159. 75
  160. 16
  161. 147
  162. 1.0
  163. 76
  164. 0
  165. 77
  166. 2
  167. 78
  168. 300
  169. 148
  170. 0.0
  171. 149
  172. 0.0
  173. 100
  174. AcDbLayout
  175. 1
  176. Layoutname
  177. 70
  178. 1
  179. 71
  180. 1
  181. 10
  182. -3.175
  183. 20
  184. -3.175
  185. 11
  186. 293.857
  187. 21
  188. 206.735
  189. 12
  190. 0.0
  191. 22
  192. 0.0
  193. 32
  194. 0.0
  195. 14
  196. 29.068
  197. 24
  198. 20.356
  199. 34
  200. 0.0
  201. 15
  202. 261.614
  203. 25
  204. 183.204
  205. 35
  206. 0.0
  207. 146
  208. 0.0
  209. 13
  210. 0.0
  211. 23
  212. 0.0
  213. 33
  214. 0.0
  215. 16
  216. 1.0
  217. 26
  218. 0.0
  219. 36
  220. 0.0
  221. 17
  222. 0.0
  223. 27
  224. 1.0
  225. 37
  226. 0.0
  227. 76
  228. 1
  229. 330
  230. 0
  231. """
  232. class DXFLayout(DXFObject):
  233. __slots__ = ()
  234. TEMPLATE = ExtendedTags.from_text(_LAYOUT_TPL)
  235. DXFATTRIBS = DXFAttributes(
  236. none_subclass,
  237. plot_settings_subclass,
  238. DefSubclass('AcDbLayout', {
  239. 'name': DXFAttr(1), # layout name
  240. 'layout_flags': DXFAttr(70),
  241. 'taborder': DXFAttr(71),
  242. 'limmin': DXFAttr(10, xtype=XType.point2d), # minimum limits
  243. 'limmax': DXFAttr(11, xtype=XType.point2d), # maximum limits
  244. 'insert_base': DXFAttr(12, xtype=XType.point3d), # Insertion base point for this layout
  245. 'extmin': DXFAttr(14, xtype=XType.point3d), # Minimum extents for this layout
  246. 'extmax': DXFAttr(15, xtype=XType.point3d), # Maximum extents for this layout
  247. 'elevation': DXFAttr(146, default=0.),
  248. 'ucs_origin': DXFAttr(13, xtype=XType.point3d),
  249. 'ucs_xaxis': DXFAttr(16, xtype=XType.point3d),
  250. 'ucs_yaxis': DXFAttr(17, xtype=XType.point3d),
  251. 'ucs_type': DXFAttr(76),
  252. # Orthographic type of UCS 0 = UCS is not orthographic;
  253. # 1 = Top; 2 = Bottom; 3 = Front; 4 = Back; 5 = Left; 6 = Right
  254. 'block_record': DXFAttr(330),
  255. 'viewport': DXFAttr(331),
  256. # ID/handle to the viewport that was last active in this
  257. # layout when the layout was current
  258. 'ucs': DXFAttr(345),
  259. # ID/handle of AcDbUCSTableRecord if UCS is a named
  260. # UCS. If not present, then UCS is unnamed
  261. 'base_ucs': DXFAttr(346),
  262. # ID/handle of AcDbUCSTableRecord of base UCS if UCS is
  263. # orthographic (76 code is non-zero). If not present and
  264. # 76 code is non-zero, then base UCS is taken to be WORLD
  265. }))