Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help needed with region subtract 1

Status
Not open for further replies.

CadDesigner

Programmer
Nov 25, 2003
18
FR
Hi guys,

If am trying to make a little program in VBA that subtracts 2 ellipse regions.
You'll find the program-code below.
When executing, everything goes well, except for the subtracting in the last sentence.
An error is given.
I can't figure it out, possible something stupid I oversee.
I am working with autocad 2000(i)

Can anyone give me a hint/ correct the code what I'm doing wrong?

Thanks,
Paul

Code:
Sub startup()

Dim EllipseObj(0 To 0) As AcadEllipse
Dim SmallEllipseObj(0 To 0) As AcadEllipse
Dim RegObj As Variant
Dim SmallRegObj As Variant
Dim Radius As Double
Dim RadiusY As Double
Dim SmallRadius As Double
Dim SmallRadiusY As Double
Dim Center(0 To 2) As Double
Dim RadiRatio As Double
Dim RadyPoint(0 To 2) As Double

Center(0) = 0: Center(1) = 0: Center(2) = 0
Radius = 100
RadiusY = 60
SmallRadius = 80
SmallRadiusY = 40

' Create ellipse 1
RadiRatio = RadiusY / Radius
RadyPoint(0) = Radius: RadyPoint(1) = 0: RadyPoint(2) = 0
Set EllipseObj(0) = ThisDrawing.ModelSpace.AddEllipse(Center, RadyPoint, RadiRatio)

' Create ellipse 2
RadiRatio = SmallRadiusY / SmallRadius
RadyPoint(0) = SmallRadius: RadyPoint(1) = 0: RadyPoint(2) = 0
Set SmallEllipseObj(0) = ThisDrawing.ModelSpace.AddEllipse(Center, RadyPoint, RadiRatio)

' Create ellipse region 1&2
RegObj = ThisDrawing.ModelSpace.AddRegion(EllipseObj)
SmallRegObj = ThisDrawing.ModelSpace.AddRegion(SmallEllipseObj)

' Subtract both ellipse regions
[COLOR=red]RegObj.Boolean acSubtraction, SmallRegObj[/color red]

End Sub
 
Hi CadDesigner,

You need to add this:
Code:
Dim outerReg As AcadRegion
Dim innerReg As AcadRegion

Set outerReg = RegObj(0)
Set innerReg = SmallRegObj(0)

Then change the last line to this:
Code:
' Subtract both ellipse regions
outerReg.Boolean acSubtraction, innerReg

HTH
Todd
 
Thanks Todd, you're great!!

Now I see the solution I must admit I always have troubles with variable declarations.
Is'nt there a tutorial to explain this topic easy?

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top