Author Topic: cast error with COM Objet and A2010  (Read 7154 times)

0 Members and 1 Guest are viewing this topic.

Spike Wilbury

  • Guest
Re: cast error with COM Objet and A2010
« Reply #15 on: June 03, 2009, 02:25:02 PM »
I'd rather use something like the findfile LISP function.

then, let see if this works... not fully tested (on A2009) - maybe :)

Code: [Select]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "acedFindFile")]
static extern int FindFile(StringBuilder fname, StringBuilder result);

[CommandMethod("TestFind")]
public void testfind()
{
    Document doc = acadApp.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    StringBuilder sResult = new StringBuilder(128);
    StringBuilder sSearch = new StringBuilder("acad.exe");
    FindFile(sSearch, sResult);
    ed.WriteMessage("{0}", sResult);
}

T.Willey

  • Needs a day job
  • Posts: 5251
Re: cast error with COM Objet and A2010
« Reply #16 on: June 03, 2009, 02:46:36 PM »
.Net has a findfile, no need to import from a dll.  FYI...

HostApplicationServices.Current.FindFile
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Spike Wilbury

  • Guest
Re: cast error with COM Objet and A2010
« Reply #17 on: June 03, 2009, 02:49:42 PM »
.Net has a findfile, no need to import from a dll.  FYI...

HostApplicationServices.Current.FindFile

I saw that... and did not tested... :)

Thanks, Tim.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: cast error with COM Objet and A2010
« Reply #18 on: June 03, 2009, 02:50:19 PM »
.Net has a findfile, no need to import from a dll.  FYI...

HostApplicationServices.Current.FindFile

I saw that... and did not tested... :)

Thanks, Tim.

I use it in one of my codes.  You're welcome Luis.

Edit:  Added said code.

Code: [Select]
public static string WillLoad (string FilePath, Database db) {
    string FoundAt = "";
    string[] tempStrAr = FilePath.Split('.');
    string FileExt = tempStrAr[tempStrAr.Length - 1];
[color=red]    try { FoundAt = HostApplicationServices.Current.FindFile(FilePath, db, FindFileHint.Default); }[/color]
    catch {}
    if ( !string.Compare(FoundAt, string.Empty).Equals( 0 ) )
            return FoundAt;
    if (string.Compare(FilePath.Substring(0, 2), "..").Equals(0) || string.Compare(FilePath.Substring(0, 1), ".").Equals(0)) {
        string[] XrPathArray = FilePath.Split('\\');
        string PartialPath = "";
        for (int i = 1; i < XrPathArray.Length; ++i) {
            PartialPath = PartialPath + "\\" + XrPathArray[i];
        }
        FileInfo DwgInfo = new FileInfo(db.Filename);
        string tempFilePath = DwgInfo.DirectoryName + PartialPath;
        try { FoundAt = HostApplicationServices.Current.FindFile(tempFilePath, db, FindFileHint.Default); }
        catch {}
        if ( !string.Compare(FoundAt, string.Empty).Equals( 0 ) )
                return FoundAt;
    }
    return string.Empty;
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Spike Wilbury

  • Guest
Re: cast error with COM Objet and A2010
« Reply #19 on: June 03, 2009, 02:52:21 PM »
.Net has a findfile, no need to import from a dll.  FYI...

HostApplicationServices.Current.FindFile

I saw that... and did not tested... :)

Thanks, Tim.

I use it in one of my codes.  You're welcome Luis.

10-4

been out of the c# coding for a while until early today, that I played a little bit :)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: cast error with COM Objet and A2010
« Reply #20 on: June 03, 2009, 03:15:49 PM »
Thank you both  :-o

But all this is quite over my head, the only attributes I use at the moment are CommandMethod and LispFunction.
Today, I'm proud I've been able to get the support files search path folders (using COM, Registry reading, ConfigurationManager or DWGPREFIX sysvar) and iterate through them to search a file.

I'll try to study all this, but it's so far from my little LISP knowledge.
Speaking English as a French Frog

xsfhlzh

  • Guest

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.