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

Additional info:

Share this page:

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x