.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

load and run .lsp from C#

6 REPLIES 6
Reply
Message 1 of 7
divyasree
3498 Views, 6 Replies

load and run .lsp from C#

Hi

How can i load .lsp or .vlx from preferable path in C# and run the lisp code at the command prompt. can anyone help me please..

Thanks in advance Edited by: divyasree on Aug 27, 2009 3:57 PM
6 REPLIES 6
Message 2 of 7
cadMeUp
in reply to: divyasree

Something like this would work, it uses AutoCAD.Interop:
{code}
[CommandMethod("TLOD", CommandFlags.Modal)]
public void TLOD()
{
/*
;;
;; contents of "C:/_TLOAD.lsp"
;;
(defun c:LISPCOM1 ()
(prompt "\nLoaded: C:/_TLOAD.lsp")
(prompt "\nLISPCOM1 Executed!")
(prompt "\nNice")
(princ)
)
*/

AcadDocument curAcadDoc = (AcadDocument)AcApp.DocumentManager.MdiActiveDocument.AcadDocument;
string lispPath = "C:/_TLOAD.lsp";
string loadStr = String.Format("(load \"{0}\") "/*space after closing paren!!!*/, lispPath);
curAcadDoc.SendCommand(loadStr);
curAcadDoc.SendCommand("LISPCOM1 "/*space after command name!!!*/);
}
{code}

It won't load it application wide. You would have to run 'TLOD' again for each document that you open.
And you can use 'HostApplicationServices.FindFile()' to find a file that might be in AutoCAD's path, if needed.
Message 3 of 7
divyasree
in reply to: divyasree

Thanks a lot. this code helped me.
Message 4 of 7
cadMeUp
in reply to: divyasree

No problem! I thought I woudl follow it up with, if you do want a lisp file to be loaded in all dwgs and subsequent opened dwgs:
{code}
AcadDocument curAcadDoc = (AcadDocument)AcApp.DocumentManager.MdiActiveDocument.AcadDocument;
curAcadDoc.SendCommand("(vl-load-com) "/*space after closing paren!!!*/);
string lispPath = "C:/_TLOAD.lsp";
string loadStr = String.Format("(vl-load-all \"{0}\") "/*space after closing paren!!!*/, lispPath);
curAcadDoc.SendCommand(loadStr);
{code}
Message 5 of 7
Faisal.Cadd
in reply to: cadMeUp

Hi,

 

I know this topic is quite old, but while using the you provided I am getting this error.

 

expected class delegate enum interface or struct (at void)

 

I have modified the code to suit my needs please help me resolve it.

 

code

using Microsoft.Win32;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using acApp = Autodesk.AutoCAD.ApplicationServices.Application;

[CommandMethod("TLOD", CommandFlags.Modal)]

public void TLOD()
{
AcadDocument curAcadDoc = (AcadDocument)AcApp.DocumentManager.MdiActiveDocument.AcadDocument;
curAcadDoc.SendCommand("(vl-load-com) "/*space after closing paren!!!*/);
string lispPath = (string)Registry.LocalMachine.GetValue(@"SOFTWARE\XXXX\YYYY", "InstallDir", null);
string loadStr = String.Format("(vl-load-all \"{0}\") "/*space after closing paren!!!*/, lispPath);
curAcadDoc.SendCommand(loadStr);
}

 

Any help would be appreciated.

Message 6 of 7
Faisal.Cadd
in reply to: Faisal.Cadd

I believe I have to declare the namespace and also public class but I do not know how. Any example Please..

Message 7 of 7
banna.kbet
in reply to: Faisal.Cadd

AcadDocument curAcadDoc = (AcadDocument)Autodesk.AutoCAD.ApplicationServices.Application .DocumentManager.MdiActiveDocument.GetAcadDocument();
            curAcadDoc.SendCommand("(vl-load-com) "/*space after closing paren!!!*/);
            string lispPath = "C:LU.lsp";
            string loadStr = String.Format("(vl-load-all \"{0}\") "/*space after closing paren!!!*/, lispPath);
            curAcadDoc.SendCommand(loadStr)

try with this 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost