Short description
Command:
Description:
Helper function: (if any)
Functionalities:
Result:
Images, animations etc.
Log in
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>

Leave a Reply
You must be logged in to post a comment.