Can you do an APPLOAD from a C# program?

Can you do an APPLOAD from a C# program?

ganderson
Advocate Advocate
2,060 Views
11 Replies
Message 1 of 12

Can you do an APPLOAD from a C# program?

ganderson
Advocate
Advocate

Hi,

   I have some AutoLisp functions that I use in conjunction with my .NET c# program. Is there a way to load them from the C# program. Right now I'm using APPLOAD before I run my dll, but it occurs to me that I might be able to load them from the dll. Any suggestions? Code samples?

     Thanks,

                  ~Vonnie A.

0 Likes
2,061 Views
11 Replies
Replies (11)
Message 2 of 12

SENL1362
Advisor
Advisor
is this what you are loooking after:
var lispPathname="c:\temp\x.lsp".Replace('\','/');
var loadLispCmd=string.format("(load {0} {1}",Quote(lispPathname),Quote("Failed to load Lisp"));
doc.SendStringToExecute(loadLispCmd);
...

public static string Quote(string str)
{
string quoted = string.Format("\"{0}\"", str);
return quoted;
}


0 Likes
Message 3 of 12

ganderson
Advocate
Advocate

Not sure I understand your code. Is public static string Quote(string str) what I call to load the lisp program? I understand the var statements, I just don't see the call.

           Thanks for the help,

                     ~Giovonnae

0 Likes
Message 4 of 12

_gile
Consultant
Consultant

Hi,

 

From .NET, you can use SendStringToExecute() to load your LISP files.

SENL 1362 reply focuses on the string format of the LISP expression to pass to the SendStringToExecute() method.

 

Using the same path example (C:\Temp\x.lsp), it can be written:

 

doc.SendStringToExecute("(load \"C:\\\\Temp\\\\x.lsp\") ", false, false, true);

or:

 

 

doc.SendStringToExecute(@"(load ""C:\\Temp\\x.lsp"") ", false, false, true);

 

Anyway, you have to keep in mind SendStringToExecute() runs asynchronously, and a .NET app is loaded once per session while a LISP function have to be loaded in each document.

 

By my side I won't load LISP files from .NET but use some LISP auto loading mechanism instead.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 12

erdem_babayigit
Explorer
Explorer

Hello Folks, I swear yesterday my code was working and I was able to load .FAS files on command from my dll file. Can anyone see in my code what could be wrong I keep getting the error message VLA-OBJECT nil

 

[CommandMethod("LoadFAS")]
public void LoadFAS()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;

string getpathdynamically = doc.Name;
string FasFolder = "FAS Dateien";
string relativePath = Path.Combine(Path.GetDirectoryName(getpathdynamically), FasFolder);


string[] FasFiles = new string[]
{
"KARISDAT_DB64",
"KARISDAT_INF64",
"KARISDAT_DB64",
"KARISDAT_INF64",

};

foreach (string fileName in FasFiles)
{
string filePath = Path.Combine(relativePath, fileName + ".FAS");

ed.WriteMessage("\nFILEPATH: " + filePath);

if (File.Exists(filePath))
{
filePath = ReplaceBackslashes(filePath);
doc.SendStringToExecute($"(load \"{filePath}\") ", false, false, true);
}
else
{
ed.WriteMessage("\nThe file does not exist.");
Application.ShowAlertDialog($"The file '{filePath}' does not exist.");
}
}
}

0 Likes
Message 6 of 12

erdem_babayigit
Explorer
Explorer
string ReplaceBackslashes(string input)
{
return input.Replace("\\", "\\\\");
}
0 Likes
Message 7 of 12

norman.yuan
Mentor
Mentor

The SendStringToExecute() is executed asyncly, as @_gile mentioned in previous reply. That means, it only gets called AFTER your command method ends, thus, only one of the *.FAS file is loaded. That is, you CANNOT run SendStringToExecye() inside a "for/do/while" loop, unless there is only one loop and the loop is the LAST statement of your command method.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 8 of 12

a.kouchakzadeh
Advocate
Advocate

nicely explained! 

0 Likes
Message 9 of 12

erdem_babayigit
Explorer
Explorer

I must say I am very surprised and very happy that we do get such a quick response to a question to a post thats 8 years old, for me it was just a shot into the blue, but here we go! I shall edit the code and report here soon! Best wishes, from Germany, Erdem.

0 Likes
Message 10 of 12

erdem_babayigit
Explorer
Explorer

Dismissing the loop for now or dll script for now, when I simply put the command (load "C:\\Karisdat\\FAS Dateien\\Karisdat_db64.fas") into the autocad command line; I get following ERROR message:

Command: (load "C:\\Karisdat\\FAS Dateien\\Karisdat_db64.fas")
; Error: ActiveX-Server returns: Error loading type library/DLL

0 Likes
Message 11 of 12

erdem_babayigit
Explorer
Explorer

the file definitely exist btw

0 Likes
Message 12 of 12

erdem_babayigit
Explorer
Explorer

Okay it seems I found out why, when opening another version of autocad ( MAP 2020 ) it does work and asks me if I want to load it. So now I wonder if there is purge feature, or some other debugging issues, or perhaps it has to do with which drawing I'm loading?

0 Likes