.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Join Regions

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
ahmedshawkey95
388 Views, 2 Replies

Join Regions

Hi,
Is there any way to allow joining multiple selected regions (not intersected) to generate only one region representing them as shown below?
Input regions:

ahmedshawkey95_0-1680763651254.png


Required output as one region:

ahmedshawkey95_1-1680763735659.png


I tried to use the following boolean operation code which is inspired by @_gile 's post, but it only returns the outlining boundary because the inner regions are fully contained inside the outlining region.

 

 

 public static Region JoinRegions(List<Region> selectedRegions)
        {
            var boundaryRegion = selectedRegions.First();
            foreach (var region in selectedRegions.Skip(1))
            {
                boundaryRegion.BooleanOperation(BooleanOperationType.BoolUnite, region);
            }

            foreach (var region in selectedRegions.Skip(1))
            {
                //TODO:Join region inside the boundary region
                //boundaryRegion.BooleanOperation(BooleanOperationType.BoolSubtract, region);
            }
            return boundaryRegion;
        }

 

 


Thanks in advance.

Tags (2)
Labels (2)
2 REPLIES 2
Message 2 of 3
_gile
in reply to: ahmedshawkey95

Hi,

 

You have to substract the inner regions to the boundary one.

        public static Region JoinRegions(List<Region> selectedRegions)
        {
            var boundaryRegion = selectedRegions.Aggregate((r1, r2) => r1.Area < r2.Area ? r2 : r1);
            foreach (var region in selectedRegions)
            {
                if (region != boundaryRegion)
                {
                    boundaryRegion.BooleanOperation(BooleanOperationType.BoolSubtract, region);
                }
            }
            return boundaryRegion;
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3
ahmedshawkey95
in reply to: _gile

Thanks, @_gile for your valuable help.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report