Region2Polyline

Short description

Purpose: Convert REGION objects into closed LWPOLYLINEs while preserving curve continuity and arc bulges Typical use: Cleanup of Boolean-created geometry or boundary extractions that output REGION entities Input object: REGION only — all selected REGIONs are processed Output format: Clean, closed LWPOLYLINE with correct bulges and segment ordering

Command:

Command name: Region2Polyline How to run: Type Region2Polyline or call c:Region2Polyline Selection mode: Automatically selects all REGION objects in the drawing (ssget “_x”) Operation: Converts each REGION into a closed LWPOLYLINE using Gilles Chanteau’s algorithm

Description:

The routine collects all REGION entities and processes them one by one by exploding each REGION into its primitive components — lines and arcs. It reorders these exploded segments so that they form a continuous closed loop, maintaining correct sequencing and connectivity between endpoints. For ARCs, it computes the corresponding bulge value using the arc’s total angle, allowing reconstruction of the curvature when converting back to LWPOLYLINE format. After ordering segments, it builds a new closed LWPOLYLINE from the reconstructed point list, applies bulges where needed, restores the elevation and normal vector, and then deletes the original REGION geometry.

Helper function: (if any)​

*error* Handles unexpected termination, prints an error message unless canceled, and ends the undo markarcbulge Calculates bulge from an ARC’s total angle → sin(a/4) ÷ cos(a/4)Explode logic Uses vlax-invoke reg ‘Explode to decompose REGION into lines and arcsSegment ordering scan Reassembles segments by repeatedly finding the next segment whose start or end matches the current chain endpointBulge recording Stores bulge values at the correct vertex indices for each ARC encountered during reconstructionPolyline builder Constructs an LWPOLYLINE using addLightWeightPolyline with transformed planar coordinatesClean-up Deletes original REGION and exploded segments after building the new polyline

Functionalities:

Automatic REGION selection No need to pick objects — all REGIONs are processed automaticallyTopology reconstruction Correctly orders exploded segments into a clean closed loopArc bulge preservation Converts arcs into bulges for accurate curve representation in LWPOLYLINE formatNormal and elevation restoration Preserves the REGION’s original 3D plane orientationDeletion of intermediate entities Exploded parts and original REGION are removed to keep drawing tidyUndo support Protected by an undo mark for safe rollback of the entire conversionRobust endpoint matching Ensures proper polyline closure even when geometry contains reversed or unordered segments

Result:

Polyline output Each REGION is converted into a clean closed LWPOLYLINE that accurately follows the REGION perimeterCurvature preservation All arcs inside the REGION become proper polyline bulges, maintaining geometric fidelityConsistent segment order The exploded segments are automatically sorted to produce a continuous, gap-free outlineCleanup Original REGION objects and intermediate exploded entities are deleted to avoid clutterFinal geometry The resulting LWPOLYLINE is closed, planar, properly oriented, and ready for further use such as hatching, offsetting, area calculations, or contours

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="Region2Polyline">
<src:RibbonToolTip.ExpandedContent>
<StackPanel>
<TextBlock Background="AntiqueWhite" TextAlignment="Left">
<Bold>Function Syntax: Region2Polyline</Bold>
<LineBreak/>
<Hyperlink>AI+https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/bypass-user-selection-in-lisp-to-convert-region-to-polyline/m-p/8169231#M101570</Hyperlink>
<LineBreak/>
<Bold>Description</Bold><LineBreak/>
This AutoLISP routine <Span Foreground="DarkRed">Region2Polyline</Span> converts selected REGION entities into closed lightweight polylines by exploding and rebuilding them with line and arc segments.<LineBreak/>
Written by <Span Foreground="DarkRed">Gilles Chanteau</Span> on 01/01/07.<LineBreak/>

<Bold>Functionalities:</Bold><LineBreak/>
• Command syntax: <Span Foreground="DarkRed">Region2Polyline</Span>.<LineBreak/>
• Prompts the user to select REGION objects in the drawing.<LineBreak/>
• Explodes each REGION into its primitive line and arc components.<LineBreak/>
• Rebuilds the exploded geometry into a closed lightweight polyline.<LineBreak/>
• Handles arc segments by calculating bulge values (<Span Foreground="DarkRed">arcbulge</Span>) to preserve curvature.<LineBreak/>
• Deletes the original REGION objects once converted.<LineBreak/>
• Ensures the new polyline is closed and placed in the correct drawing space (ModelSpace or PaperSpace depending on CVPORT).<LineBreak/>
• Groups the operation into an undo mark for rollback.<LineBreak/>

<Bold>Key Features:</Bold><LineBreak/>
• Converts REGIONS back into editable polylines without loss of arcs.<LineBreak/>
• Works with both ModelSpace and PaperSpace contexts.<LineBreak/>
• Uses robust geometric matching of endpoints to reconstruct polylines.<LineBreak/>
• Preserves geometric accuracy of arcs using calculated bulge factors.<LineBreak/>

<Bold>Function Syntax</Bold><LineBreak/>
• <Span Foreground="DarkRed">Region2Polyline</Span><LineBreak/>

<Bold>Typical Workflow</Bold><LineBreak/>
• Run <Span Foreground="DarkRed">Region2Polyline</Span>.<LineBreak/>
• Select one or more REGION objects.<LineBreak/>
• The program explodes them, rebuilds the edges as closed lightweight polylines, and deletes the original REGIONs.<LineBreak/>
• The resulting polyline(s) are ready for editing, measuring, or further CAD operations.<LineBreak/>


</TextBlock>
            


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



Additional info:

Share this page:

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Tags: 🏷️ Autocad Lisps, 🏷️ Polyline menu
0
Would love your thoughts, please comment.x
()
x