Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

No value returned for an area created with automation 1

Status
Not open for further replies.

RichiePete

Marine/Ocean
Jul 8, 2001
2
I have developed a program in visual basic which draws a cross sectional area using values supplied by a user, a region is then created using this profile. The purpose of this is for autocad to automatically return the area of the region, and place it back into my program for it to be analysed. However this is not the case, as it returns a value of zero. I have used the following code for this:

Dim retArea As Double
retArea = region.Area
txtOutput = retArea

(where region is the object name of the region)



The thing that puzzles me is that when I go into tools-inquiry-area, autocad recognises the shape constructed to be a closed region and returns an area. Has anyone else suffered from this problem.
 
Replies continue below

Recommended for you

I tried combinations of
Dim myRegion As AcadRegion
or
Dim myRegion As Variant
and
Set myRegion =
or
myRegion =

although this produced differences in behavior of
myRegion.color etc.,
made no difference to
myRegion.Area

Eventually, I found out that the Sub is exited at the line
Set myRegion = or myRegion =
I moved this line into another Sub, called from Sub GetRegionArea
but did not help. The Sub just does not execute after this line.
Of course myRegion.Area has to come after the region is defined. SO, the Sub never gets there.
Hope someone takes from here...
 
This worked on Acad14! The trick is request the area as MyRegion(0).Area
Funny but must be a thing from the pointer practice.

Sub Example_AddRegion()
On Error Resume Next
' This example creates a region from an arc and a line.

Dim curves(0 To 1) As Object

' Define the arc
Dim centerPoint(0 To 2) As Double
Dim radius As Double
Dim startAngle As Double
Dim endAngle As Double
centerPoint(0) = 5#: centerPoint(1) = 3#: centerPoint(2) = 0#

radius = 2#
startAngle = 0
endAngle = 3.141592

Set curves(1) = ThisDrawing.ModelSpace.AddArc(centerPoint, radius, startAngle, endAngle)
Set curves(0) = ThisDrawing.ModelSpace.AddLine(curves(1).StartPoint, curves(1).EndPoint)
' Define the line


' Create the region
Dim regionObj As Variant
regionObj = ThisDrawing.ModelSpace.AddRegion(curves)

regionObj(0).Color = acRed
ThisDrawing.ActiveViewport.ZoomAll
Debug.Print regionObj(0).Area
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor