I am trying to write some code that will perform the bounded volumes routine following the selection of some polylines and the volume surface. The issue I am having is that the bounded volumes expects a variant array of doubles which no longer exists in VB.Net. Anyone have any tips/pointers for dealing with this?
Thanks,
Hi,
You probably need to create an array of objects and resize to the correct size. Which method are you using here?
Augusto Goncalves
Autodesk Developer Network
Hi Augusto,
Here is the code I use to create the array and try to pass to the Bounded Volumes. I am an amateur programmer so it may not be the prettiest or most correct but does generally it seems to work. The oCutFillSurface1 is a Tin Volume Surface selected earlier in the program.
'Get the polyline from the object ID stored in DataTable.
oBound = Table.Rows(i).Item(8)
oPolyline = g_oCivil3DDoc.ObjectIdToObject(oBound)
If TypeOf oPolyline Is Autodesk.AutoCAD.Interop.Common.AcadPolyline Then
Dim oCounter As Integer = 0
Dim oArrayCount As Integer = 0
oPolyline1 = oPolyline
'Create the x,y coordinate array.
oArray = oPolyline1.Coordinates
oCount = oArray.Length / 2
'Creating an x,y,z coordinate array with z=0.
For j = 0 To oArray.Length + oCount - 1
If oCounter = 2 Then
oPoints.Add(0)
oCounter = 0
Else
oPoints.Add(oArray(oArrayCount))
oCounter = oCounter + 1
oArrayCount = oArrayCount + 1
End If
Next
oArray = oPoints.ToArray
oCutFillSurface1.Statistics.BoundedVolumes(oArray, oCut, oFill, oNet)
At this point I reviewed the following error.
System.ArgumentException was caught
Message=Value does not fall within the expected range.
Source=Autodesk.AECC.Interop.Land
StackTrace:
at Autodesk.AECC.Interop.Land.IAeccTinVolumeSurfaceStatistics.BoundedVolumes(Object varPoints, Double& pCut, Double& pFill, Double& pNet)
at EarthworkCalc.Form1.Button6_Click(Object sender, EventArgs e)
InnerException:
Thanks in advance for your help.
Hi,
Try with:
Dim oArray As New List(Of Object)
And:
oCutFillSurface1.Statistics.BoundedVolumes(oArray.ToArray, oCut, oFill, oNet)
I have completed some more testing to make sure that the issue is not with the surface and I am able to do other manipulations and pull other statistics from the surface.
As far as I can tell with my limited expertise is that the issue has to do with the array containing the coordinates and how the bounded volumes interprets that array.
Hi,
Sorry I do not have resource to prepare a sample project and test your app, if you care to provide a more ready to use code, I can try it further.
Usually these errors related to Variants on VB.NET are related to a cast conversion, mainly because the way it receive the data. Also it could be related to data it self, like the last point on the collection being equals the first, but as you said the same code worked on VBA, I´m suspecting it the first case.
Regards,
Augusto Goncalves
Autodesk Developer Network
I have actually managed to figure out the issue I was having.
First, your post mentioned that the first point has to be the same as the last point. I didnt have this in my original code and made that fix.
The second thingwas I changed the oArray variable to
Dim oArray As New List(Of Double)
This has fixed the problem.
Thanks for your help.