# 带有pyautocad的AutoCAD的Python

pyautocad可以识别当前打开的AutoCAD图形，也可以识别当前活动的模型空间。因此，在运行下面的Python代码之前，我将打开一个新的AutoCAD图形。

```# 导入pyautocad
import pyautocad
# 创建AutoCAD实例
acad = pyautocad.Autocad()
```

```# 当前在AutoCAD中被激活的文档的打印名称
print(acad.doc.Name)
```
```Drawing1.dwg
```

```# 指定圆心的x和y坐标
from pyautocad import APoint
point1 = APoint(100.0,100.0) # x and y coordinates of points
# 在图纸上添加圆
circle1 = acad.model.AddCircle(point1,100)
```

pyautocad也可以更改圆圈的颜色。我在下面的代码中这样做：

```# 将圆圈颜色更改为红色
circle1.Color = 10 ＃10是红色
```

```＃检查图层分配
print("current layer: "  + str(circle1.Layer))
# 检查当前线型
print("current linetype: " + str(circle1.Linetype))
# 检查线型比例
print("current linetype scale: " + str(circle1.LinetypeScale))
# 检查当前线宽
print("current line weight: " + str(circle1.Lineweight))
# 检查当前厚度
print("current thickness: " + str(circle1.Thickness))
# 检查当前材料
print("current material:" + str(circle1.Material))
```
```current layer: 0
current linetype: ByLayer
current linetype scale: 1.0
current line weight: -1
current thickness: 0.0
current material:ByLayer
```

```circle1.Layer = "circles"
```

```circle1.Color = 256
```

```＃在绘图中添加两个圆圈
circle2 = acad.model.AddCircle(APoint(200.0,200.0),100)
circle3 = acad.model.AddCircle(APoint(300.0,300.0),100)
＃遍历所有对象
for obj in acad.iter_objects():
print(obj)
```
```<POINTER(IAcadCircle) ptr=0x223f8ed65f8 at 223faa5c848>
<POINTER(IAcadCircle) ptr=0x223f8ed6358 at 223faa5ca48>
<POINTER(IAcadCircle) ptr=0x223f89ede28 at 223faa5c148>
```