I was working on a project to create a tool that helps engineers to automate drawing tasks and as my company using ZWcad instead of Autocad I found myself obliged to use pyzwcad but I could not find enough information about it in one place or I was not searching in the correct places since I'm a beginner programmer and I need to gather all the Data I collect in one place.
how to use python libirary pyzwcad to automate tasks and draw in ZWcad?
468 Views Asked by ahmad.arafa At
2
There are 2 best solutions below
0
On
3- Add Circle:
# add insertion point
x_coo = 50
y_coo = 50
c1 = APoint(x_coo, y_co)
radius = 500
circle= acad.model.AddCircle(c1, radius)
4- Rotate object:
# 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 code
5- Add text:
# 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- Change text alignment:
# 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_point
7- Add rotated dimension line:
we need to define 3 points
start point, end point and dimension text point,also we should use math lib to use the radians method
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()
the above code could be used to add liner dimention line by use 0 in angle place for horizontal dimension or math.radians(90) for vertical dimensions.
8- Add Aligned dimension line:
same as above but without using rotation angle.
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- override existing dimension line text:
dim_line.TextOverride = "new text"
"dim_line" is referring to the wanted dimension line object name.
first of all you need to import pyzwacad
or just import the used methods
my preferred way to automate tasks using API is to let the user start the program before using the tool.
so we now need to define the cad object
in the next paragraphs I will summarize some of pyzwacad methods I use in my project.
Add line type in the current drawing file.
Draw square:
X_coo: is the X coordinate for the center point of the square shape.
y_coo: is the Y coordinate for the center point of the square shape.
we need to make an array/list for square points coordinate for example first point will take the first two positions in the list so
list[0] is the first point X coordinate and
list1 is the first point Y coordinate.