2016-05-11 86 views
0

pythonで塗りつぶした楕円を描きたいと思います。他のいくつかのライブラリをPILなどで使用することができれば簡単です。問題は、.dxfファイル形式で楕円が必要なことです。そのため、私はdxfwriteパッケージを使用しました。これで楕円を描くことができますが、ソリッドカラーで塗りつぶす方法が見つかりませんでした。次のコードは、楕円線を描画しますが、楕円線を塗りつぶすことはありません。python dxfの楕円の塗りつぶし

import dxfwrite 
from dxfwrite import DXFEngine as dxf 

name = 'ellipse.dxf' 
dwg = dxf.drawing(name) 
dwg.add(dxf.ellipse((0,0), 5., 10., segments=200)) 
dwg.save() 

あなたの誰かが解決策を知っていますか?

+0

は楕円を埋めるためにソリッドハッチングオブジェクトを使用することを許容できますか?もしそうなら、私はあなたにDXFを示すことができます。 –

+0

dxfwriteはDXF R12ファイルのみを作成し、DXF R12はHATCHエンティティをサポートしませんが、_ezdxf_パッケージはHATCHエンティティをサポートしています。 PyFのezdxf:https://pypi.python.org/pypi/ezdxf/; [ドキュメントのためのハッチ](https://ezdxf.readthedocs.io/en/latest/entities.html#hatch) – mozman

答えて

1

あなたはソリッドハッチングオブジェクト使用して楕円を埋めることができます:上記の例

Hatch in Autocad

を、ここでは楕円とハッチが含まれているDXFファイルからの抜粋です:

AcDbEntity 
    8 
0 
100 
AcDbEllipse 
10 
2472.192919 
20 
1311.37942 
30 
0.0 
11 
171.0698134145308 
21 
-27.61597470964863 
31 
0.0 
210 
0.0 
220 
0.0 
230 
1.0 
40 
0.2928953354556341 
41 
0.0 
42 
6.283185307179586 
    0 
HATCH 
    5 
5A 
330 
2 
100 
AcDbEntity 
    8 
0 
100 
AcDbHatch 
10 
0.0 
20 
0.0 
30 
0.0 
210 
0.0 
220 
0.0 
230 
1.0 
    2 
SOLID 
70 
    1 
71 
    1 
91 
     1 
92 
     5 
93 
     1 
72 
    3 
10 
2472.192919357234 
20 
1311.379420138197 
11 
171.0698134145308 
21 
-27.61597470964863 
40 
0.2928953354556341 
50 
0.0 
51 
360.0 
73 
    1 
97 
     1 
330 
59 
75 
    1 
76 
    1 
47 
0.794178 
98 
     1 
10 
2428.34191358924 
20 
1317.777876434349 
450 
     0 
451 
     0 
460 
0.0 
461 
0.0 
452 
     0 
462 
1.0 
453 
     2 
463 
0.0 
63 
    5 
421 
     255 
463 
1.0 
63 
    2 
421 
16776960 
470 
LINEAR 
1001 
GradientColor1ACI 
1070 
    5 
1001 
GradientColor2ACI 
1070 
    2 
1001 
ACAD 
1010 
0.0 
1020 
0.0 
1030 
0.0 

多くのDXFコードが含まれています。これは、オートデスクが提供する情報です。

Hatch group codes 
Group code 
Description 
100 
Subclass marker (AcDbHatch) 
10 
Elevation point (in OCS) 
DXF: X value = 0; APP: 3D point (X and Y always equal 0, Z represents the elevation) 
20, 30 
DXF: Y and Z values of elevation point (in OCS) 
Y value = 0, Z represents the elevation 
210 
Extrusion direction (optional; default = 0, 0, 1) 
DXF: X value; APP: 3D vector 
220, 230 
DXF: Y and Z values of extrusion direction 
2 
Hatch pattern name 
70 
Solid fill flag (solid fill = 1; pattern fill = 0); for MPolygon, the version of MPolygon 
63 
For MPolygon, pattern fill color as the ACI 
71 
Associativity flag (associative = 1; non-associative = 0); for MPolygon, solid-fill flag (has solid fill = 1; lacks solid fill = 0) 
91 
Number of boundary paths (loops) 
varies 
Boundary path data. Repeats number of times specified by code 91. See Boundary Path Data 
75 
Hatch style: 
0 = Hatch “odd parity” area (Normal style) 
1 = Hatch outermost area only (Outer style) 
2 = Hatch through entire area (Ignore style) 
76 
Hatch pattern type: 
0 = User-defined; 1 = Predefined; 2 = Custom 
52 
Hatch pattern angle (pattern fill only) 
41 
Hatch pattern scale or spacing (pattern fill only) 
73 
For MPolygon, boundary annotation flag (boundary is an annotated boundary = 1; boundary is not an annotated boundary = 0) 
77 
Hatch pattern double flag (pattern fill only): 
0 = not double; 1 = double 
78 
Number of pattern definition lines 
varies 
Pattern line data. Repeats number of times specified by code 78. See Pattern Data 
47 
Pixel size used to determine the density to perform various intersection and ray casting operations in hatch pattern computation for associative hatches and hatches created with the Flood method of hatching 
98 
Number of seed points 
11 
For MPolygon, offset vector 
99 
For MPolygon, number of degenerate boundary paths (loops), where a degenerate boundary path is a border that is ignored by the hatch 
10 
Seed point (in OCS) 
DXF: X value; APP: 2D point (multiple entries) 
20 
DXF: Y value of seed point (in OCS); (multiple entries) 
450 
Indicates solid hatch or gradient; if solid hatch, the values for the remaining codes are ignored but must be present. Optional; if code 450 is in the file, then the following codes must be in the file: 451, 452, 453, 460, 461, 462, and 470. If code 450 is not in the file, then the following codes must not be in the file: 451, 452, 453, 460, 461, 462, and 470 
0 = Solid hatch 
1 = Gradient 
451 
Zero is reserved for future use 
452 
Records how colors were defined and is used only by dialog code: 
0 = Two-color gradient 
1 = Single-color gradient 
453 
Number of colors: 
0 = Solid hatch 
2 = Gradient 
460 
Rotation angle in radians for gradients (default = 0, 0) 
461 
Gradient definition; corresponds to the Centered option on the Gradient Tab of the Boundary Hatch and Fill dialog box. Each gradient has two definitions, shifted and unshifted. A Shift value describes the blend of the two definitions that should be used. A value of 0.0 means only the unshifted version should be used, and a value of 1.0 means that only the shifted version should be used. 
462 
Color tint value used by dialog code (default = 0, 0; range is 0.0 to 1.0). The color tint value is a gradient color and controls the degree of tint in the dialog when the Hatch group code 452 is set to 1. 
463 
Reserved for future use: 
0 = First value 
1 = Second value 
470 
String (default = LINEAR) 

これはあなたの役に立つかもしれません。私はあなたの問題を逃した場合は謝罪します。

+0

あなたの答えのためのthx!私は何を言います。しかし、悲しいことに私はどのようにPythonでハッチを実装するのか分かりません。 – ChrisG

+0

申し訳ありませんが、私はその答えの一部を知らない。 :( –

2

あなたはこのezdxf使用する場合HATCHエンティティは、dxfwriteによってサポートされていないがソリューションです:

import ezdxf 

dwg = ezdxf.new('AC1015') # hatch requires the DXF R2000 (AC1015) format or later 
msp = dwg.modelspace() # adding entities to the model space 

# important: major axis >= minor axis (ratio <= 1.) else AutoCAD crashes 
msp.add_ellipse((0, 0), major_axis=(0, 10), ratio=0.5) 

hatch = msp.add_hatch(color=2) 
with hatch.edit_boundary() as boundary: # edit boundary path (context manager) 
    edge_path = boundary.add_edge_path() 
    # an edge path can contain line, arc, ellipse or spline elements 
    edge_path.add_ellipse((0, 0), major_axis_vector=(0, 10), minor_axis_length=0.5) 
    # upcoming ezdxf 0.7.7: 
    # renamed major_axis_vector to major_axis 
    # renamed minor_axis_length to ratio 

dwg.saveas("solid_hatch_ellipse.dxf") 
関連する問題