Good day to all.
I have a routine that uses the “intersectwith” function, from AutoCAD 2009.
I recently upgraded to 2011, and I get the following error:
IntersectWith(entityPointer As Autodesk.AutoCAD.DatabaseServices.Entity,
intersectType As Autodesk.AutoCAD.DatabaseServices.Intersect,
points As Autodesk.AutoCAD.Geometry.Point3dCollection,
thisGraphicSystemMarker As Integer,
otherGraphicSystemMarker As Integer)' is obsolete: 'Use the overload taking IntPtr instead.'.
Does anyone know how to fix this, or maybe where there is an example?
Cheers,
Martin. 😄
Man this was a while ago!
I got an fix in the form aof a function from the great Tony T.
Here it is:
Imports System.Runtime.CompilerServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports System.Reflection
Public Module PlatformCompatibilityExtensionMethods
Sub New()
Dim types1 As Type() = Nothing
Dim types2 As Type() = Nothing
If (IntPtr.Size > 4) Then
types1 = New Type() {GetType(Entity), GetType(Intersect), GetType(Point3dCollection), GetType(Long), GetType(Long)}
types2 = New Type() {GetType(Entity), GetType(Intersect), GetType(Plane), GetType(Point3dCollection), GetType(Long), GetType(Long)}
Else
types1 = New Type() {GetType(Entity), GetType(Intersect), GetType(Point3dCollection), GetType(Integer), GetType(Integer)}
types2 = New Type() {GetType(Entity), GetType(Intersect), GetType(Plane), GetType(Point3dCollection), GetType(Integer), GetType(Integer)}
End If
PlatformCompatibilityExtensionMethods.intersectWithMethod1 = GetType(Entity).GetMethod("IntersectWith", (BindingFlags.Public Or BindingFlags.Instance), Nothing, types1, Nothing)
PlatformCompatibilityExtensionMethods.intersectWithMethod2 = GetType(Entity).GetMethod("IntersectWith", (BindingFlags.Public Or BindingFlags.Instance), Nothing, types2, Nothing)
End Sub
Public Function IntersectWith(ByVal entity As Entity, ByVal other As Entity, ByVal intersectType As Intersect, ByVal points As Point3dCollection) As Integer
Dim start As Integer = points.Count
Dim args As Object() = Nothing
If (IntPtr.Size > 4) Then
args = New Object() {other, intersectType, points, CLng(0), CLng(0)}
Else
args = New Object() {other, intersectType, points, CInt(0), CInt(0)}
End If
PlatformCompatibilityExtensionMethods.intersectWithMethod1.Invoke(entity, args)
Return (points.Count - start)
End Function
Public Function IntersectWith(ByVal entity As Entity, ByVal other As Entity, ByVal intersectType As Intersect, ByVal plane As Plane, ByVal points As Point3dCollection) As Integer
Dim start As Integer = points.Count
Dim args As Object() = Nothing
If (IntPtr.Size > 4) Then
args = New Object() {other, intersectType, plane, points, CLng(0), CLng(0)}
Else
args = New Object() {other, intersectType, plane, points, CInt(0), CInt(0)}
End If
PlatformCompatibilityExtensionMethods.intersectWithMethod2.Invoke(entity, args)
Return (points.Count - start)
End Function
Public Function IntersectWith(ByVal entity As Entity, ByVal other As Entity, ByVal intersectType As Intersect, ByVal points As Point3dCollection, ByVal thisGsMarker As IntPtr, ByVal otherGsMarker As IntPtr) As Integer
Dim start As Integer = points.Count
Dim args As Object() = Nothing
If (IntPtr.Size > 4) Then
args = New Object() {other, intersectType, points, thisGsMarker.ToInt64, otherGsMarker.ToInt64}
Else
args = New Object() {other, intersectType, points, thisGsMarker.ToInt32, otherGsMarker.ToInt32}
End If
PlatformCompatibilityExtensionMethods.intersectWithMethod1.Invoke(entity, args)
Return (points.Count - start)
End Function
Public Function IntersectWith(ByVal entity As Entity, ByVal other As Entity, ByVal intersectType As Intersect, ByVal plane As Plane, ByVal points As Point3dCollection, ByVal thisGsMarker As IntPtr, ByVal otherGsMarker As IntPtr) As Integer
Dim start As Integer = points.Count
Dim args As Object() = Nothing
If (IntPtr.Size > 4) Then
args = New Object() {other, intersectType, plane, points, thisGsMarker.ToInt64, otherGsMarker.ToInt64}
Else
args = New Object() {other, intersectType, plane, points, thisGsMarker.ToInt32, otherGsMarker.ToInt32}
End If
PlatformCompatibilityExtensionMethods.intersectWithMethod2.Invoke(entity, args)
Return (points.Count - start)
End Function
Private intersectWithMethod1 As MethodInfo = Nothing
Private intersectWithMethod2 As MethodInfo = Nothing
End Module
Even easier is to replace the last two integer arguments with intptr. For those I usually use 0,0 - I find these two arguments are rarely used.
It worked for me to simply replace the last two parameters "0,0" with "New Intptr(), New IntPtr()"
Thanks to cadcamm99 in another post.