我在做一个帮助工程师自动化绘图任务的项目。由于我的公司使用ZWcad而不是Autocad,我发现自己不得不使用pyzwcad,但是我在一个地方找不到足够的信息,或者我没有在正确的地方搜索,因为我是一个初学者,我需要在一个地方收集我收集的所有数据。
发布于 2021-10-21 18:16:44
首先,您需要导入pyzwacad。
from pyzwcad import *或者直接导入使用过的方法
from pyzwcad import ZwCAD, ZCAD, APoint, aDouble使用API实现任务自动化的首选方法是让用户在使用该工具之前启动程序。
因此,我们现在需要定义cad对象。
acad = ZwCAD()在接下来的段落中,我将总结一下在我的项目中使用的一些pyzwacad方法。

发布于 2021-10-22 12:44:21
3-加圈:
# add insertion point
x_coo = 50
y_coo = 50
c1 = APoint(x_coo, y_co)
radius = 500
circle= acad.model.AddCircle(c1, radius)4-旋转物体:
# add base point
x_coo = 50
y_coo = 50
base_point= APoint(x_coo, y_co)
r_ang = (45 * np.pi) / 180
object.Rotate(base_point, r_ang)
# object is refering to the object name it could be difrent based on your code5-增加案文:
# add insertion point
x_coo = 50
y_coo = 50
pttxt = APoint(x_coo, y_coo)
txt_height = 200 # text height
text = acad.model.AddText("text string", pttxt, txt_height)6-更改文本对齐方式:
# first we need to sort the current insertion point for the exist text object as it will be reset after changing the alignment.
old_insertion_point = APoint(text.InsertionPoint)
# text is refering to text object name it could be difrent based on your code
text.Alignment = ZCAD.zcAlignmentBottomCenter
# modify the text insertion point as the above step automaticaly reset it to (0, 0)
text.TextAlignmentPoint = old_insertion_point7-增加旋转尺寸线:
我们需要定义3点
起始点,终点和维度文本点,也应该使用数学库来使用弧度法。
import math
acad = ZwCAD()
st_dim = APoint(0, 0)
end_dim = APoint(100, 30)
text_dim = APoint(50, 15)
dim_line = acad.model.AddDimRotated(st_dim, end_dim, text_dim, math.radians(30))
acad.Application.ZoomAll()上述程序可用于增加线性尺寸线的角度位置为水平尺寸0或math.radians(90)的垂直尺寸。
8-增加对齐尺寸线:
与上述相同,但不使用旋转角度。
acad = ZwCAD()
st_dim = APoint(0, 0)
end_dim = APoint(100, 30)
text_dim = APoint(50, 15)
dim_line = acad.model.AddDIMALIGNED(st_dim, end_dim, text_dim)9-覆盖现有维度行文本:
dim_line.TextOverride = "new text""dim_line“指的是想要的维度行对象名。
https://stackoverflow.com/questions/69666916
复制相似问题