Function Syntax: CPL_2 Version: 2 Date: 06.09.2025 AI + https://www.cadtutor.net/forum/topic/49702-centerline-between-two-polylines/ Description This routine defines a single command, CPL_2, intended to draw a simple “centerline” between two selected open curves using only COM/ActiveX methods. It is designed to be silent on load (only (princ) at the end) and does not depend on command calls like OFFSET/LOFT/INTERSECT. What the command does When you run CPL_2: 1) You select objects using a normal selection set (ssget). It accepts any pick/window/crossing selection. 2) It takes only: - the first entity in the selection set (index 0), and - the last entity in the selection set (index n-1). Everything else in the selection is ignored. 3) It converts those two enames to VLA objects and reads their geometry using the curve API: - vlax-curve-getStartPoint - vlax-curve-getEndPoint This supports LINE, (LW)POLYLINE, ARC, SPLINE, ELLIPSE and other “curve-like” objects compatible with the curve functions. 4) It guards against closed curves by rejecting any object where start and end points are equal within tolerance (1e-9). If either selected curve appears closed, nothing is created. 5) It computes two midpoint locations (2D): - midpoint between the two start points (one from each curve), and - midpoint between the two end points (one from each curve). The midpoint computation uses X/Y only; Z is implicitly ignored/forced to 2D because a LightweightPolyline is a 2D entity. 6) It creates a new 2-vertex LWPOLYLINE in ModelSpace via COM: - Builds a COM-safe SAFEARRAY of 4 doubles: [xm1, ym1, xm2, ym2]. - Wraps it in a VARIANT and passes it to ModelSpace.AddLightWeightPolyline. Inputs and outputs - Input: a selection set with at least 2 entities. - Output: one new 2-vertex LWPOLYLINE in ModelSpace, representing the straight “centerline” between the two computed midpoints. - If the selection has fewer than 2 entities, or if either of the chosen entities appears closed, the command exits without creating anything. Important behavioral details - Selection order matters: the routine uses the first and last objects in the selection set. For window/crossing selection, AutoCAD’s internal ordering may not match the user’s visual expectation. If you want explicit control, select exactly two objects and pick them in the intended order. - Not a “true” geometric centerline: it does not analyze the curves’ shapes or spacing along their lengths. It simply connects the midpoint between their startpoints to the midpoint between their endpoints. For non-parallel, differently oriented, or differently parameterized curves, the result may not lie between the curves as a consistent medial axis—this is a deliberate simplification. - 2D output: Z is dropped. If your curves are not planar in WCS XY or have varying elevation, the created LWPOLYLINE will still be placed as a 2D polyline in the current plane (effectively Z=0 behavior for coordinates passed). - No layer/linetype/color handling: the new polyline will inherit current properties (current layer, color ByLayer, etc.) unless the environment dictates otherwise. The routine does not explicitly set layer or other properties. Where this is a good fit - You have two open boundary curves that conceptually represent left/right rails or edges, and you want a fast, lightweight centerline approximation in one action. - You prefer a COM-only implementation (no heavy command macros) and want minimal side effects (no system variables changed). Where it may not be appropriate - If you need a centerline that tracks curvature and maintains “middle” distance along the entire length (true medial/offset-based centerline). - If you need 3D fidelity (Z-aware centerline). - If either selected curve is closed (it intentionally skips those).