Swamp,
I don't know if there is another version of this routine out there...
This routine is similar to the (findfile ) expression in LISP.
I wrote this from scratch using the other examples (from Daniel, TonyT, Gile, etc...) for package invoke entry points for guidance.
I included the LISPFunction attribute for testing.
Do you think the string in string out overload of the function would be useful to .NET?
Would it be useful to create a library of acad.exe entry points like the old ads commands?
Constructive criticism is gratefully appreciated.
PeterJ
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime
Imports System.Runtime.InteropServices 'for DllImport()
Imports System.Security
Imports System.Text.StringBuilder
Public Class vbvlClass
<System.Security.SuppressUnmanagedCodeSecurity(), DllImport("acad.exe", _
CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedFindFile")> _
Private Shared Function acedFindFile(ByVal strEnvironmentName As String, _
ByVal stbReturnValue As System.Text.StringBuilder) As Integer
End Function
' Function that performs like the the (findfile "filename.txt") lisp expression.
' The Findfile1 function returns a (resultbuffer) list instead of a string.
' It searches the support path for a provided file name.
<LispFunction("FindFile1")> _
Public Shared Function FindFile1(ByVal rbfFileName As ResultBuffer) As ResultBuffer
Dim rbfReturn As New ResultBuffer
Try
If Not IsNothing(rbfFileName) Then
Dim strFileName As String = rbfFileName.AsArray(0).Value.ToString
rbfReturn.Add(New TypedValue(&H138D, FindFile1(strFileName)))
Else
rbfReturn.Add(New TypedValue(&H138D, "Error: too few arguments"))
End If
Catch Ex As Exception
rbfReturn.Add(New TypedValue(&H138D, "Error " & Ex.Message))
Finally
rbfFileName.Dispose()
End Try
Return rbfReturn
End Function
' Overload of the findfile1 function that accepts a string and returns a string
Public Shared Function FindFile1(ByVal strFileName As String) As String
Dim stbReturn As New System.Text.StringBuilder(1024)
Try
If Not IsNothing(strFileName) Then
acedFindFile(strFileName, stbReturn)
Return stbReturn.ToString
Else
Return "Error: too few arguments"
End If
Catch Ex As Exception
Return "Error " & Ex.Message
Finally
End Try
End Function
End Class