MiddleLinePolylines_2

Short description

Purpose: Create a simple two vertex centerline between two selected open curves using only their endpoints Supported objects: LINE, LWPOLYLINE, POLYLINE, ARC, SPLINE, ELLIPSE when they are open curves Usage style: Quick central axis between two roughly parallel edges selected as first and last items in a selection set

Command:

Command name: CPL_2 How to run: Type CPL_2 then press Enter Selection: Use any selection method to choose at least two open curves; the routine uses the first and the last selected entities Silent rules: If fewer than two objects are selected or if the chosen curves are closed, the routine simply ends without creating anything

Description:

The routine takes the first and last entities from the user selection and reads their geometric start and end points through the curve API, which works for lines, polylines, arcs, splines, and ellipses. It rejects closed curves by checking that each start point is different from its corresponding end point, which prevents creating a centerline from closed loops. From these endpoints, it computes the midpoint between the two starts and the midpoint between the two ends in the XY plane, then creates a two vertex LWPOLYLINE that connects those midpoints, effectively representing a simple centerline between the two boundary curves.

Helper function: (if any)​

vlax-curve-getStartPoint and getEndPoint Used to obtain pure geometry for any supported curve object through the curve APIvlax-make-safearray Builds a safe array of doubles containing the vertex coordinates for the new polylinevlax-make-variant Wraps the safe array into a variant value required by the COM methodvla-AddLightWeightPolyline Called on ModelSpace to actually create the two vertex LWPOLYLINE objectvl-load-com Ensures the Visual LISP COM interface is loaded before any COM calls are made

Functionalities:

Automatic curve type handling Uses the generic curve API so the same logic works across lines, polylines, arcs, splines, and ellipsesFirst and last driven logic Only the first and the last objects in the selection are used, which allows flexible window or crossing selection while still defining two sidesClosed curve safeguard Skips processing when a selected curve has identical start and end points, avoiding problematic closed inputMidpoint centerline Calculates midpoints between the two start points and between the two end points then draws the centerline through these midpointsPlanar output Uses only X and Y from the picked curves and ignores Z so the resulting LWPOLYLINE is a clean two dimensional objectSilent behaviour No command line prompts are issued; if the conditions are not met, nothing is created and the routine exits quietly

Result:

Geometric result A new two vertex LWPOLYLINE is added in ModelSpace that represents the centerline between the two selected boundary curvesNon destructive The original entities remain unchanged; only an additional centerline object is createdWorkflow benefit Provides an extremely fast way to generate a central axis for profiles, corridors, or similar parallel edge situations

Images, animations etc.

Pixel

XAML code:

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:Autodesk.Windows;assembly=AdWindows">
    
<src:RibbonToolTip x:Key="CenterPline_2">
<src:RibbonToolTip.ExpandedContent>
<StackPanel>
<TextBlock Background="AntiqueWhite" TextAlignment="Left">
<Bold>Function Syntax: CPL_2</Bold>
<LineBreak/>
<Bold>Version: 2 Date: 06.09.2025</Bold>
<LineBreak/>
<LineBreak/>
<Hyperlink>AI + https://www.cadtutor.net/forum/topic/49702-centerline-between-two-polylines/</Hyperlink>
<LineBreak/>
<Bold>Description</Bold><LineBreak/>
This routine defines a single command, <Run Foreground="Red">CPL_2</Run>, 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 <Run Foreground="DarkRed">(princ)</Run> at the end) and does not depend on command calls like OFFSET/LOFT/INTERSECT.<LineBreak/>
<LineBreak/>

<Bold>What the command does</Bold><LineBreak/>
When you run <Run Foreground="Red">CPL_2</Run>:<LineBreak/>
1) You select objects using a normal selection set (<Run Foreground="DarkRed">ssget</Run>). It accepts any pick/window/crossing selection.<LineBreak/>
2) It takes only:<LineBreak/>
   - the <Run Foreground="DarkRed">first</Run> entity in the selection set (index 0), and<LineBreak/>
   - the <Run Foreground="DarkRed">last</Run> entity in the selection set (index n-1).<LineBreak/>
   Everything else in the selection is ignored.<LineBreak/>
3) It converts those two enames to VLA objects and reads their geometry using the curve API:<LineBreak/>
   - <Run Foreground="DarkRed">vlax-curve-getStartPoint</Run><LineBreak/>
   - <Run Foreground="DarkRed">vlax-curve-getEndPoint</Run><LineBreak/>
   This supports LINE, (LW)POLYLINE, ARC, SPLINE, ELLIPSE and other “curve-like” objects compatible with the curve functions.<LineBreak/>
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.<LineBreak/>
5) It computes two midpoint locations (2D):<LineBreak/>
   - midpoint between the two <Run Foreground="DarkRed">start points</Run> (one from each curve), and<LineBreak/>
   - midpoint between the two <Run Foreground="DarkRed">end points</Run> (one from each curve).<LineBreak/>
   The midpoint computation uses X/Y only; Z is implicitly ignored/forced to 2D because a LightweightPolyline is a 2D entity.<LineBreak/>
6) It creates a new 2-vertex <Run Foreground="DarkRed">LWPOLYLINE</Run> in ModelSpace via COM:<LineBreak/>
   - Builds a COM-safe <Run Foreground="DarkRed">SAFEARRAY</Run> of 4 doubles: [xm1, ym1, xm2, ym2].<LineBreak/>
   - Wraps it in a VARIANT and passes it to <Run Foreground="DarkRed">ModelSpace.AddLightWeightPolyline</Run>.<LineBreak/>
<LineBreak/>

<Bold>Inputs and outputs</Bold><LineBreak/>
- Input: a selection set with at least 2 entities.<LineBreak/>
- Output: one new <Run Foreground="DarkRed">2-vertex LWPOLYLINE</Run> in ModelSpace, representing the straight “centerline” between the two computed midpoints.<LineBreak/>
- If the selection has fewer than 2 entities, or if either of the chosen entities appears closed, the command exits without creating anything.<LineBreak/>
<LineBreak/>

<Bold>Important behavioral details</Bold><LineBreak/>
- <Run Foreground="DarkRed">Selection order matters</Run>: 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.<LineBreak/>
- <Run Foreground="DarkRed">Not a “true” geometric centerline</Run>: 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.<LineBreak/>
- <Run Foreground="DarkRed">2D output</Run>: 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).<LineBreak/>
- <Run Foreground="DarkRed">No layer/linetype/color handling</Run>: 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.<LineBreak/>
<LineBreak/>

<Bold>Where this is a good fit</Bold><LineBreak/>
- 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.<LineBreak/>
- You prefer a COM-only implementation (no heavy command macros) and want minimal side effects (no system variables changed).<LineBreak/>
<LineBreak/>

<Bold>Where it may not be appropriate</Bold><LineBreak/>
- If you need a centerline that tracks curvature and maintains “middle” distance along the entire length (true medial/offset-based centerline).<LineBreak/>
- If you need 3D fidelity (Z-aware centerline).<LineBreak/>
- If either selected curve is closed (it intentionally skips those).<LineBreak/>


</TextBlock>
            
<Grid>
<Image Source="PNG" Stretch="Uniform"/>
</Grid>


<Grid>
<MediaElement
Source="centerPline.gif"
Stretch="Uniform"
Visibility="Visible"/>
</Grid>


</StackPanel>
</src:RibbonToolTip.ExpandedContent>
</src:RibbonToolTip>
</ResourceDictionary>



Additional info:

Share this page:

Leave a Reply

Page Tag: 🏷️ Autocad Lisps

  • MiddleLinePolylines_2

    Short description Purpose: Create a simple two vertex centerline between two selected open curves using only their endpoints Supported objects: LINE, LWPOLYLINE, POLYLINE, ARC, SPLINE, ELLIPSE when they are open curves Usage style: Quick central axis between two roughly parallel edges selected as first and last items in a selection set Command: Command name: CPL_2…

  • MiddleCenterLineTools

    Short description Comming soon … Command: Comming soon … Description: Comming soon … Helper function: (if any)​ Comming soon … Functionalities: Comming soon … Result: Comming soon … Images, animations etc. Lisp code: Expand Code ⬇ Select Code Copy Code Comming soon … Share this page:

  • Lengthen

    Short description Sort / Purpose: Interactively extend lines, arcs and polylines at both start and end by user defined distances, using a dialog with separate values for each side and safe Apply or Undo control. • Scope: Works on LINE, ARC, LWPOLYLINE and classic POLYLINE entities, handling straight and bulged segments at both ends. •…

  • InteriorPolylinesArea

    Short description Purpose: Provide a unified dialog interface for running multiple area-processing operations inside closed polylines Use cases: Creating inside boundaries, breaking curves, converting regions to polylines, filtering out open polylines, or joining areas Memory: Stores last chosen option in *BR2P-last-option* and auto-selects it next run Command: Command name: BR2P Dialog: Seven radio options select…

  • DoubleOffset

    Short description Comming soon … Command: Comming soon … Description: Comming soon … Helper function: (if any)​ Comming soon … Functionalities: Comming soon … Result: Comming soon … Images, animations etc. Lisp code: Expand Code ⬇ Select Code Copy Code Comming soon … Share this page:

  • CopySelection

    Short description Purpose: Duplicate only a chosen segment of a LWPolyline between two picked points and generate it on a selected layer Supported objects: Single LWPOLYLINE only Usage style: Extract partial polyline segments and place them on a different layer using a filterable layer picker dialog Command: Command name: CopySelection How to run: Type COPYSELECTION…

  • CloseParalelPolylines

    Short description Purpose: Automatically connect two open or parallel-like entities and merge them into one continuous polyline Supported objects: LWPOLYLINE, LINE, ARC, SPLINE Usage style: Cleanup or closing gaps between two aligned open objects Command: Command name: CloseParallelPolylines How to run: Type CLOSEPARALLELPOLYLINES and press Enter User prompt: Select two open polylines, arcs, splines, or…

  • AnnoAllOff

    Short description Opens a DCL picker to choose Model/Layout tabs, then sets ANNOALLVISIBLE to 0 on the selected tabs. Provides quick selection controls for All or None before applying the change. Command: Command: AAOFF Description: Builds a temporary DCL dialog at runtime that lists all tabs (including Model) and allows multi-selection. After the user confirms…

  • SelectLayout

    Short description Select Layout from Dialog Displays a dialog box listing all paper space layouts for quick selection and activation. Command: Command: SelectLayout Description: This command creates an interactive dialog box to switch between layouts: Retrieves all paper space layouts from the current drawing (excludes Model space) Generates a temporary DCL dialog file with a…

  • GoToLayout

    Short description Opens a DCL dialog to filter layout names with wildcards and quickly switch the current tab to the selected match. Includes optional preview switching while browsing and remembers the last used filter pattern across runs. Command: Command: GoToLayout Description: Builds a unique temporary DCL file each run and launches a dialog titled Go…