×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

No value returned for an area created with automation

No value returned for an area created with automation

No value returned for an area created with automation

(OP)
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.

RE: No value returned for an area created with automation

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...

RE: No value returned for an area created with automation

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources