Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 python dxf中椭圆的实体填充_Python 2.7_Python 3.x_Dxf - Fatal编程技术网

Python 2.7 python dxf中椭圆的实体填充

Python 2.7 python dxf中椭圆的实体填充,python-2.7,python-3.x,dxf,Python 2.7,Python 3.x,Dxf,我想用python绘制填充椭圆。如果我可以使用PIL或其他库,这将很容易。问题是我需要一个.dxf文件格式的椭圆。因此,我使用了dxfwrite包。这允许我画一个椭圆,但我找不到一种方法来填充它的纯色。下面的代码确实绘制了一条椭圆线,但没有填充它 import dxfwrite from dxfwrite import DXFEngine as dxf name = 'ellipse.dxf' dwg = dxf.drawing(name) dwg.add(dxf.ellipse((0,0),

我想用python绘制填充椭圆。如果我可以使用PIL或其他库,这将很容易。问题是我需要一个.dxf文件格式的椭圆。因此,我使用了dxfwrite包。这允许我画一个椭圆,但我找不到一种方法来填充它的纯色。下面的代码确实绘制了一条椭圆线,但没有填充它

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()

你们中有谁知道解决方案吗?

你们可以使用实心图案填充对象填充椭圆:

对于上面的示例,以下是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代码。以下是Autodesk提供的信息:

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)

我希望这对你有用。如果我误解了您的问题,我深表歉意。

您可以使用实心图案填充对象填充椭圆:

对于上面的示例,以下是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代码。以下是Autodesk提供的信息:

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)

我希望这对你有用。如果我误解了您的问题,我深表歉意。

dxfwrite不支持图案填充实体,如果您使用ezdxf,这是解决方案:

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")
导入ezdxf
dwg=ezdxf。新建('AC1015')#图案填充需要DXF R2000(AC1015)格式或更高版本
msp=dwg.modelspace()#将实体添加到模型空间

#重要提示:长轴>=短轴(比率dxfwrite不支持图案填充图元,如果使用ezdxf,这是解决方案:

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")
导入ezdxf
dwg=ezdxf。新建('AC1015')#图案填充需要DXF R2000(AC1015)格式或更高版本
msp=dwg.modelspace()#将实体添加到模型空间

#重要提示:长轴>=短轴(比率使用实体图案填充对象填充椭圆是否可以接受?如果可以,我可以向您展示DXF.dxfwrite仅创建DXF R12文件,DXF R12不支持图案填充实体,但包ezdxf支持图案填充实体。PyPI上的ezdxf:;使用实体图案填充对象填充椭圆是否可以接受?如果可以,我可以向您展示D。)XF.dxfwrite只创建DXF R12文件,DXF R12不支持图案填充实体,但包ezdxf确实支持图案填充实体。PyPI上的ezdxf:;thx供您回答!这就是我的意思。但遗憾的是,我不知道如何在python中实现图案填充。抱歉,我不知道答案的这一部分:(谢谢你的回答!这就是我的想法。但遗憾的是,我不知道如何用python实现图案填充。对不起,我不知道答案的这一部分(