p1, p2, p3, and p4—into the format required for the vla-addLightweightpolyline function. First, get some help on the topic.
The last issue to deal with is how to transform the individual point variables—To obtain information on a function
AddLightWeightPolyline requires you to specify the polyline vertices as an array of doubles in the form of a variant. Here is how Help describes this parameter:
Help states thatThe array of 2D WCS coordinates specifying the vertices of the polyline. At least two points (four elements) are required for constructing a lightweight polyline. The array size must be a multiple of 2.
A variant is an ActiveX construct that serves as a container for various types of data. Strings, integers, and arrays can all be represented by variants. The variant stores data along with the information identifying the data.
So far, you have four points, each in the format (x, y, z). The challenge is to convert these four points into a list of the following form:
(x1 y1 x2 y2 x3 y3 x4 y4)
append function takes multiple lists and concatenates them. To create a list of the four points in the proper format for the ActiveX function, you can use the following expression:
The(setq polypoints (append (3dPoint->2dPoint p1)
(3dPoint->2dPoint p2)
(3dPoint->2dPoint p3)
(3dPoint->2dPoint p4)))
3dPoint->2dPoint function four times is a bit cumbersome. You can reduce the code further by using the mapcar and apply functions. When selected, mapcar executes a function on individual elements in one or more lists, and apply passes a list of arguments to the specified function. The resulting code looks like the following:
Writing the(setq polypoints (apply 'append (mapcar '3dPoint->2dPoint
(list p1 p2 p3 p4))))
mapcar, the list of points is in this form:
Before the call to((x1 y1 z1) (x2 y2 z2) (x3 y3 z3) (x4 y4 z4))
mapcar you have a list of points in the following form:
After((x1 y1) (x2 y2) (x3 y3) (x4 y4))
append function on the list returned from mapcar, you end up with the following:
And finally, after applying the(x1 y1 x2 y2 x3 y3 x4 y4)