Author Topic: civil 3d cogo Point Outside Surface how to "On Error Resume Next"  (Read 3357 times)

0 Members and 1 Guest are viewing this topic.

jcoon

  • Newt
  • Posts: 157
Could someone provide a sample or link that shows how to allows an On Error Resume Next that will allow an error point not on surface to continue to loop thru selected points.

I used Catch ex As System.Exception
                        ed.WriteMessage(ex.Message + Convert.ToChar(10))
                        Return
                    End Try
This returns Point Outside Surface which is correct when not of surface. How can I resume sampling points against surface when I encounter error not on surface? currently on error dumps out of loop when error is encountered.

get surface elevation with
ElevationOnSurface = surface.FindElevationAtXY(myPoint.Location.X, myPoint.Location.Y)
MsgBox(ElevationOnSurface) 

Thank you
John Coon

in VBA LDT i used something similar to this when point was not on surface
On Error Resume Next
        dblelev = oSurface.FindElevationAtXY(objPoint.EASTING, objPoint.NORTHING)
       
    If Err <> 0 Then
    dblelev = 0
    pointelev = pointelev - pointelev
    'MsgBox Err.Description
    GoTo nextpnt:
    End If

Jeff_M

  • King Gator
  • Posts: 4040
  • C3D user & customizer
Re: civil 3d cogo Point Outside Surface how to "On Error Resume Next"
« Reply #1 on: December 11, 2012, 07:03:00 PM »
John, is this a .NET Surface or a COM Surface? If the former, you can catch that specific error and continue
Code: [Select]
Catch ex As Autodesk.Civil.PointNotOnEntityException 
    ed.WriteMessage(ex.Message + Convert.ToChar(10))
    Continue Next '' or Continue For ''this will stop execution of the current operation in a For...Each & For .... Next loop and start again with the next iteration (I think, I still don't do VB)

TheMaster

  • Guest
Re: civil 3d cogo Point Outside Surface how to "On Error Resume Next"
« Reply #2 on: December 11, 2012, 08:31:27 PM »
Could someone provide a sample or link that shows how to allows an On Error Resume Next that will allow an error point not on surface to continue to loop thru selected points.

I used Catch ex As System.Exception
                        ed.WriteMessage(ex.Message + Convert.ToChar(10))
                        Return
                    End Try
This returns Point Outside Surface which is correct when not of surface. How can I resume sampling points against surface when I encounter error not on surface? currently on error dumps out of loop when error is encountered.

get surface elevation with
ElevationOnSurface = surface.FindElevationAtXY(myPoint.Location.X, myPoint.Location.Y)
MsgBox(ElevationOnSurface) 

Thank you
John Coon

in VBA LDT i used something similar to this when point was not on surface
On Error Resume Next
        dblelev = oSurface.FindElevationAtXY(objPoint.EASTING, objPoint.NORTHING)
       
    If Err <> 0 Then
    dblelev = 0
    pointelev = pointelev - pointelev
    'MsgBox Err.Description
    GoTo nextpnt:
    End If

I would recommend taking a basic course in VB.NET, that should cover exception handling. VB.net and VBA are vastly different when it comes to errors.

You can use Try/Catch to trap an error and continue execution. By default, Catch will simply continue execution if you do not call Throw or call Return. So, the simple answer to your question is that you don't use Return in your Catch block, you just let the code continue as if the error didn't occur (but skipping any processing of the point that triggered it, and continuing with the next point).

Before you can migrate existing code from VBA to VB.NET and the .NET framework, you really should invest some time in learning VB.NET.

jcoon

  • Newt
  • Posts: 157
Re: civil 3d cogo Point Outside Surface how to "On Error Resume Next"
« Reply #3 on: December 12, 2012, 07:29:20 AM »
Jeff,

it's a .net surface. I'll try that tonight. Thanks Jeff! with this remaining task I should be able to finally move a majority of my old VBA routines to dot net. thank you all.

TT,
recommend taking a basic course in VB.NET > yes I'd love to if they had one in my area that was under 2K for three day classes. local colleges don't offer weekend classes.

Thank you
john

jcoon

  • Newt
  • Posts: 157
Re: civil 3d cogo Point Outside Surface how to "On Error Resume Next"
« Reply #4 on: December 12, 2012, 07:43:18 PM »
Jeff,

Thank you. I was able to add catch statement and it worked like a charm after reading about 20 pages on on code project on the subject.

Thanks
John

For Each myPointID As ObjectId In ss
Try
Dim myPoint As CogoPoint = myPointID.GetObject(OpenMode.ForRead)
mySW.WriteLine(myPoint.PointNumber & "," & myPoint.Location.X.ToString & "," & myPoint.Location.Y.ToString & "," & myPoint.Location.Z.ToString & "," & Left(myPoint.FullDescription, 15))
ElevationOnSurface = surface.FindElevationAtXY(myPoint.Location.X, myPoint.Location.Y)
MsgBox(ElevationOnSurface)

doing more stuff with points
Catch ex As Autodesk.Civil.PointNotOnEntityException
ed.WriteMessage(ex.Message + Convert.ToChar(10))
 End Try
 Next

TheMaster

  • Guest
Re: civil 3d cogo Point Outside Surface how to "On Error Resume Next"
« Reply #5 on: December 12, 2012, 09:00:12 PM »
Quote from: jcoon link=topic=43375.msg486040#msg486040
TT,
recommend taking a basic course in VB.NET > yes I'd love to if they had one in my area that was under 2K for three day classes. local colleges don't offer weekend classes.

Thank you
john

There is plenty of free learning materials and online courseware on the .NET that you can use to learn the basics of VB.NET and the .NET framework (as your last post seems to suggest you've found).

I recommend doing that, because it will allow you to get up to speed a lot faster, and without having to post a lot of questions asking others to explain the basics for you.

« Last Edit: December 12, 2012, 09:03:52 PM by TT »