Modified: Added using Directives.It's been slow around here lately!
As I'm using the 2007 version of the managed API I'm noticing that they are including more and more of the ARX API with each release. However here's one that they haven't got around to exposing yet. The error message is long enough to verge on excess, but at least you won't have any questions if it's thrown
Anybody else have any interesting API shortfall workarounds?
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace GratuitousNameExposure.BobbyCJones
{
public sealed class AcadFileUtilities
{
private const int maxResultLength = 511;
[DllImport("acad.exe", CharSet=CharSet.Auto, CallingConvention=CallingConvention.Cdecl)]
private static extern int acedFindFile(string fileName, StringBuilder result);
private AcadFileUtilities() { }
public static string FindFile(string fileName)
{
StringBuilder fullyQualifiedFileName = new StringBuilder(maxResultLength);
acedFindFile(fileName, fullyQualifiedFileName);
if (fullyQualifiedFileName.Length > 0)
{
return fullyQualifiedFileName.ToString();
}
else
{
throw new System.IO.FileNotFoundException("File not found in the current directory, the current drawing file directory, the AutoCAD search path, in the AutoCAD installation directory, or in the specified location (if it was specified).", fileName);
}
}
}
}