14.5.2 AddX, AddY
In certain cases, a simpler approach than defining a list of points to create a sketch is to specify relative distances between each point and the previous one, rather than providing their absolute coordinates.
Therefore, we will create a function that takes a list of points and the distance by which we want to move the point to be added to the list as its arguments. Our approach will be grounded in the UDO commands (12.2.1 Syntax of geometrical UDOs commands):
ADDX (< dx >) - Insert a line parallel to X-axis from (x1, y1) to (x1 + dx, y1).
ADDY (< dy >) - Insert a line parallel to Y-axis from (x1, y1) to (x1, y1 + dy).
ADDXY (< dx >,< dy >) - Insert line from previous point (x1, y1) to point (x1 + dx, y1 + dy).
def AddX(p,dx):
size = len(p)-1
last_point = p[size]
new_point_x = last_point[0] + dx
new_point_y = last_point[1]
p.append( (new_point_x, new_point_y) )
def AddY(p,dy):
size = len(p)-1
last_point = p[size]
new_point_x = last_point[0]
new_point_y = last_point[1] + dy
p.append( (new_point_x, new_point_y) )
def AddXY(p,dx, dy):
size = len(p)-1
last_point = p[size]
new_point_x = last_point[0] + dx
new_point_y = last_point[1] + dy
p.append( (new_point_x, new_point_y) )
It should be noted that these functions add a point to the list based on the coordinates of its last element. Therefore, these functions should not be called if the points list is empty. In particular, the coordinates of the first point in the sketch should be defined manually.