Jump to content

Subtracting a regions


andresperezcera

Recommended Posts

The subtract region operation is something i have already done, but what i'm having trouble with is determining when a region is inside another one. Here I attach a sample file:

cadtutor forum.dwg

 

The main task is checking regions one by one, then determining whether it as or not another region inside. If it does, subtract the interior one. I don't know how to check if one contains another inside. Help!!

Link to comment
Share on other sites

Wouldn't the Subtract command fail if that were the case?

Not really, if you subtract the region which is inside, it will create a tubular region. I work for a fenestration company, therefore we have to design aluminum profiles; the tubular ones have to include some additional information. But i don't have but a visual way to inspect hundreds of profiles & I'd like to automate most of that work.

Link to comment
Share on other sites

I’ve had good success by comparing the Bounding Box of one Region to see if it was completely contained within the Bounding Box of another Region. If so then subtract.

 

 

 

Which API are you using?

Link to comment
Share on other sites

Most of my coding time these days is devoted to .NET, though I have done a fair bit of VBA work over the years. For that particular task (Bounding Box comparison), the .NET API has some enhancements that could be beneficial. That notwithstanding, VBA is well up to the task – accurate and efficient.

 

 

 

If the geometry is laid out as in your sample file (i.e.,items are not nested) then I suspect the comparison routine would have minimal impact on code execution.

Link to comment
Share on other sites

Yes, they will allways be in such manner. I receive them as polylines, then convert all of them to regions, then find those hollow profiles and obtain all the information I need. I think there is only one case in which bounding box comparison wont work, i'll try to ilustrate it. See attachment:

illustrate1.dwg

 

In this sample, a small piece is inserted in the provided groove, for such cases comparing bounding boxes will generate an error, is there any criteria other than bounding box which i can add to prevent this type of error?

Link to comment
Share on other sites

That is the type of nesting that can throw a wrench in the works.

 

 

 

One possible methodology would be to copy all inner regions (regions determined to be contained within a particular outer Region). Subtract each inner, and then check if the Area property has changed for the outer region. If it has changed, erase the copy.

 

 

 

Though, I don’t remember exactly how the Region.Boolean Subtract method reacts to calls made on non intersecting entities. It may require an error trap.

Link to comment
Share on other sites

Hi,

 

It seems to me that once you have the regions initially as polylines it would be easier to determine whether one polyline is inside another. In order one polyline to be totally inside another its area should be bigger. So you can first checkbetween two polylines which area is bigger. Then you can try the .IntersectWith method. Both .Area and .IntersectWith methods are available in VBA. So if .IntersectWith method returns no intersection points then the polyline with smaller area is inside the one with bigger area, unless they don't have any common areas at all. I guess this can then be checked comparing the .GetBoundingBox coordinates.

This method is more complex than using the .GetBoundingBox alone, but it is more precise, as in some cases you might have one boundingBox totally within the other, byt the real polylines might be intersecting.

 

Hope this helps

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...