can't delete regions

can't delete regions

Anonymous
Not applicable
457 Views
4 Replies
Message 1 of 5

can't delete regions

Anonymous
Not applicable
I make some regions then create other regions that I use for boolean subtracting so I can make holes in the primary region then I take that region and make a solid out of it.

I cannot delete the hole region once I have use it to punch a hole in the primary region because it does not exist anymore.

So then I even tried this method which I do not like because I have to loop through everything.

Public Sub deleteRegions()

Dim i As Long
Dim modelSpaceObject As AcadObject
Dim objectcount As Long

objectcount = ThisDrawing.ModelSpace.count
For i = 0 To objectcount - 1
On Error Resume Next
Set modelSpaceObject = ThisDrawing.ModelSpace(i)
If modelSpaceObject.ObjectName = "AcDbRegion" Then
modelSpaceObject.Delete
End If
Next

End Sub

This will pick up the regions and act like it deletes them, but they are still there.

Once you subtract 1 region from another the "hole region" does not exist. but looping through all the modelspace objects you find it again, and delete it but it is still there. I even tried setting it to visible=false or truecolor = color.black (my UDT) and it goes through and does nothing.

Does anyone know how to go around this??
0 Likes
458 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
I'm on 2006.
1) Draw 2 circles, 1 inside the other
2) Make regions
3) Subtract inside from outer.
Windowing these I have 1 object
4) Extrude w/ code
Set S = ThisDrawing.ModelSpace.AddExtrudedSolid(regionObj, 5, 0)
Windowing I have 4 objects, a 3dsolid, a region and 2 circles.
Delete the circles
0 Likes
Message 3 of 5

Anonymous
Not applicable
Thanks for your reply Bryco.

I posted a mini version of the code I am using:

sub test

Dim objReg As AcadRegion, solReg As AcadRegion
Dim objArr As Variant, shtArr As Variant
Dim a(2) As Double, b(2) As Double, c(2) As Double
Dim d(2) As Double

'region that gets a piece taken out of it
a(0) = 0): a(1) = 0: a(2) = 0
b(0) = 20: b(1) = 0: b(2) = 0
c(0) = 20: c(1) = 0: c(2) = 10
d(0) = 20: d(1) = 0: d(2) = 10
shtArr = drawRegion(a, b, c, d)
Set solReg = shtArr

'region of the hole
a(0) = 3: a(1) = 0: a(2) = 3
b(0) = 5: b(1) = 0: b(2) = 3
c(0) = 5: c(1) = 0: c(2) = 8
d(0) = 3: d(1) = 0: d(2) = 8

objArr = drawRegion(a, b, c, d)
Set objReg = objArr
solReg.Boolean acSubtraction, objReg
'now objArr is nothing and solReg has the hole subtracted from it
'I can't do anything with it anymore, but I can get it back by looping though modelspace as I showed in last post. And it will seem to work but does not.

drawSolid solReg

end sub

Public Sub drawSolid(ByRef region As AcadRegion)

Dim sol As Acad3DSolid

Set sol = ThisDrawing.ModelSpace.AddExtrudedSolid(region, 5, 0)
region.Delete'the region with the hole gets deleted
Set sol = Nothing

End Sub

Function drawRegion(ByRef a, ByRef b, ByRef c, ByRef d) As Variant

Dim aLin(3) As AcadLine

Set aLin(0) = ThisDrawing.ModelSpace.AddLine(a, b)
Set aLin(1) = ThisDrawing.ModelSpace.AddLine(b, c)
Set aLin(2) = ThisDrawing.ModelSpace.AddLine(c, d)
Set aLin(3) = ThisDrawing.ModelSpace.AddLine(d, a)

drawRegion = ThisDrawing.ModelSpace.AddRegion(aLin)
aLin(0).Delete: aLin(1).Delete
aLin(2).Delete: aLin(3).Delete

End Function

Once the hole region does its job to subract a hole in the larger region there seems to be no way to do anything with it after it is not needed anymore.
0 Likes
Message 4 of 5

Anonymous
Not applicable
I ran your code and after adding (0) to Set solReg = shtArr(0) it ran fine and left only a solid w/ modelspace.count=1 so I'm not sure where your problem is.
0 Likes
Message 5 of 5

Anonymous
Not applicable
thanks Bryco for your help.

I ran my test code, it worked then I found in the real code a duplicate line making the hole array twice! I should have ran my test code but was so convinced it would not work either.
0 Likes