Author Topic: acedFindFile  (Read 2927 times)

0 Members and 1 Guest are viewing this topic.

Bobby C. Jones

  • Swamp Rat
  • Posts: 514
  • Cry havoc and let loose the dogs of war.
acedFindFile
« on: May 10, 2006, 11:25:28 AM »
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?

Code: [Select]
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);
      }
    }
  }
}
« Last Edit: May 10, 2006, 11:56:57 AM by Bobby C. Jones »
Bobby C. Jones

Draftek

  • Water Moccasin
  • Posts: 1501
Re: acedFindFile
« Reply #1 on: May 10, 2006, 11:54:54 AM »
That's really cool Bobby.

I have done similar in vb using the Declare statement, but hadn't considered importing arx dll's in c#.

Thanks
Soli Deo Gloria

Bobby C. Jones

  • Swamp Rat
  • Posts: 514
  • Cry havoc and let loose the dogs of war.
Re: acedFindFile
« Reply #2 on: May 10, 2006, 02:13:17 PM »
That's really cool Bobby.

I have done similar in vb using the Declare statement, but hadn't considered importing arx dll's in c#.

Thanks
De nada. 

Well, it is cool which is much more than nada.  What I meant was that I did nada :-)

There are lots of examples of importing ARX functions in .NET on this forum and others.  This is just one that I needed today and thought that I would share and try to drum up some conversations.  And dig to see if there are others out there that wanted to share some code that I could steal ;-)
Bobby C. Jones

Draftek

  • Water Moccasin
  • Posts: 1501
Re: acedFindFile
« Reply #3 on: May 10, 2006, 02:35:43 PM »
There are lots of examples of importing ARX functions in .NET on this forum and others.

ack! GOT to get our more often.

I don't have anything worth stealing yet. All inside the box stuff.
Soli Deo Gloria

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: acedFindFile
« Reply #4 on: May 16, 2006, 01:24:43 PM »
It seems you can do anything by importing ARX functions.
Can someone do one that does what GRDRAW does in lisp?  I need it BAD.

Is there a technical limit to this importing?  like, what categories of ARX classes would it not work on?
James Maeding

Bobby C. Jones

  • Swamp Rat
  • Posts: 514
  • Cry havoc and let loose the dogs of war.
Re: acedFindFile
« Reply #5 on: May 16, 2006, 05:09:12 PM »
It seems you can do anything by importing ARX functions.
Can someone do one that does what GRDRAW does in lisp?  I need it BAD.

Is there a technical limit to this importing?  like, what categories of ARX classes would it not work on?
Hey James,
What version of acad are you using?  The 2007 Editor class has a DrawVector() and a DrawVectors() method.  I haven't used either of them.

In 2006 and 2007 you could use a Jig.  The arx sdk has examples.

And if needed, I suppose that you could use p/invoke to call acedGrDraw() or acedGrVecs() in 2006.
Bobby C. Jones

Alexander Rivilis

  • Bull Frog
  • Posts: 212
  • Programmer from Kyiv (Ukraine)
Re: acedFindFile
« Reply #6 on: May 20, 2006, 05:57:29 PM »
Can someone do one that does what GRDRAW does in lisp?  I need it BAD.
Code: [Select]
    [DllImport("acad.exe", CharSet=CharSet.Auto, CallingConvention=CallingConvention.Cdecl)]
    private static extern int acedGrDraw(double [] from, double[] to, Int32 col, Int32 hl);
    [CommandMethod("GrDraw")]
    static public void GrDraw()
    {
      double[] from = {0,0,0};
      double[] to = {10,10,0};
      acedGrDraw(from,to,1,0);
    }

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: acedFindFile
« Reply #7 on: May 25, 2006, 03:52:07 PM »
que bueno!  finding goodies here more and more, thanks
James Maeding