Can't get LSP to run in Core Console

Can't get LSP to run in Core Console

matthew_schwartz5CELZ
Contributor Contributor
828 Views
8 Replies
Message 1 of 9

Can't get LSP to run in Core Console

matthew_schwartz5CELZ
Contributor
Contributor

I'm at my wit's end trying to get this simple thing to work. I have a LSP that works just fine when I run it. If I try and have it run in the command line version, defun C:FART and then run the command from the command line, I get an error that it isn't found. So through another post I found that I can just add running the command to the bottom of the LSP routine. (attached)


My SCR file is:
(load "C:/Autodesk/FART.lsp")
QSAVE

My BAT is:
set accoreexe="C:\Program Files\Autodesk\AutoCAD 2020\accoreconsole.exe"
set source=N:\100\10\01\Design\Civil\test
set script="C:\Autodesk\NORTHSIDE"
FOR /f "delims=" %%f IN ('dir /b "%source%\*.dwg"') DO %accoreexe% /i "%source%\%%f" /s %script%

 

It saves the file, but does not accomplish the simple text replace from the LSP. I have no idea what's going on. There is a temp file that gets generated like accc306042 with:

m_kernelList still has 1 entry.
ERROR: Can't delete temp file C:\Users\MATTHE~1.SCH\AppData\Local\Temp\accc306042. (errno=13).

 

What is it that I am not doing?

0 Likes
Accepted solutions (2)
829 Views
8 Replies
Replies (8)
Message 2 of 9

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Without being able to test.
Steps:
You launch a SINGLE Autocad session (no drawing open as a precaution) and in the new drawing you copy and paste the code directly into the command line: You optionally validate the copy by enter.
You then choose a folder containing the drawings you want to process.
Normally the created script should launch with AcCoreConsole.

((lambda ( / f_exe ShlObj Folder FldObj Out_Fld file_scr file_bat)
	(vl-load-com)
	(setq f_exe (findfile "accoreconsole.exe"))
	(setq
		ShlObj (vla-getinterfaceobject (vlax-get-acad-object) "Shell.Application")
		Folder (vlax-invoke-method ShlObj 'BrowseForFolder 0 "" 0)
	)
	(vlax-release-object ShlObj)
	(if Folder
		(progn
			(setq
				FldObj (vlax-get-property Folder 'Self)
				Out_Fld (vlax-get-property FldObj 'Path)
			)
			(vlax-release-object Folder)
			(vlax-release-object FldObj)
		)
	)
	(setq file_scr (open (strcat (getvar "ROAMABLEROOTPREFIX") "support\\update.scr") "w"))
(write-line "(defun FART (find replace / ss i ent txtobj)" file_scr)
(write-line "  (setq ss (ssget \"X\" '((0 . \"TEXT,MTEXT\"))))" file_scr)
(write-line "  (if ss" file_scr)
(write-line "    (progn" file_scr)
(write-line "      (setq i 0)" file_scr)
(write-line "      (while (< i (sslength ss))" file_scr)
(write-line "        (setq ent (ssname ss i))" file_scr)
(write-line "        (setq txtobj (entget ent))" file_scr)
(write-line "        (cond" file_scr)
(write-line "          ((= (cdr (assoc 0 txtobj)) \"TEXT\")" file_scr)
(write-line "            (if (wcmatch (cdr (assoc 1 txtobj)) (strcat \"*\" find \"*\"))" file_scr)
(write-line "              (progn" file_scr)
(write-line "                (setq txtobj (subst (cons 1 (vl-string-subst replace find (cdr (assoc 1 txtobj))))" file_scr)
(write-line "                                    (assoc 1 txtobj)" file_scr)
(write-line "                                    txtobj))" file_scr)
(write-line "                (entmod txtobj)" file_scr)
(write-line "              )" file_scr)
(write-line "            )" file_scr)
(write-line "          )" file_scr)
(write-line "          ((= (cdr (assoc 0 txtobj)) \"MTEXT\")" file_scr)
(write-line "            (if (wcmatch (cdr (assoc 1 txtobj)) (strcat \"*\" find \"*\"))" file_scr)
(write-line "              (progn" file_scr)
(write-line "                (setq txtobj (subst (cons 1 (vl-string-subst replace find (cdr (assoc 1 txtobj))))" file_scr)
(write-line "                                    (assoc 1 txtobj)" file_scr)
(write-line "                                    txtobj))" file_scr)
(write-line "                (entmod txtobj)" file_scr)
(write-line "              )" file_scr)
(write-line "            )" file_scr)
(write-line "          )" file_scr)
(write-line "        )" file_scr)
(write-line "        (setq i (1+ i))" file_scr)
(write-line "      )" file_scr)
(write-line "    )" file_scr)
(write-line "  )" file_scr)
(write-line "  (princ)" file_scr)
(write-line ")" file_scr)
(write-line "(FART \"NORTH SIDE\" \"NORTHSIDE\")" file_scr)
(write-line "(command \"_.saveas\" \"_LT2018\" \"\")" file_scr)
	(close file_scr)
	(setq file_bat (open (strcat (getvar "ROAMABLEROOTPREFIX") "support\\update.bat") "w"))
	(write-line (eval (read "(strcat \"set accoreexe=\" \"\\\"\" f_exe \"\\\"\")")) file_bat)
	(write-line (eval (read "(strcat \"set source=\" \"\\\"\" Out_Fld \"\\\"\")")) file_bat)
	(write-line (eval (read "(strcat \"set script=\" \"\\\"\" (getvar \"ROAMABLEROOTPREFIX\") \"support\\\\update.scr\" \"\\\"\")")) file_bat)
	(write-line "FOR /f \"delims=\" %%f IN ('dir /b \"%source%\\\*.dwg\"') DO %accoreexe% /i \"%source%\\%%f\" /s %script%" file_bat)
	(close file_bat)
	(startapp (strcat (getvar "ROAMABLEROOTPREFIX") "support\\update.bat"))
	(princ"\Job finished")
	(prin1)
))
0 Likes
Message 3 of 9

paullimapa
Mentor
Mentor

Try attached FindReplaceAll.lsp code which works with coreconsole:

You script just needs to be modified slightly:

(load "c:/autodesk/FindReplaceAll.lsp")
(c:FindReplaceAll "NORTH SIDE" "NORTHSIDE")
_.QSAVE


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 9

matthew_schwartz5CELZ
Contributor
Contributor

I gave your script a try and had the same results. I can run it in AutoCAD and it works, but not with Core Console. 

0 Likes
Message 5 of 9

paullimapa
Mentor
Mentor

Odd..because worked fine on my end. Perhaps it's your bat file then. Maybe simplify to this to try:

FOR %%f in ("N:\100\10\01\Design\Civil\test\*.dwg") DO "C:\Program Files\Autodesk\AutoCAD 2020\AcCoreConsole.exe" /i "%%f" /s "C:\Autodesk\NORTHSIDE.scr" /l en-US

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 9

matthew_schwartz5CELZ
Contributor
Contributor

I did as you said, detached the XREF files and move the test file off the network to my local machine and I'm still not having any luck. The script runs, no errors, the file saves, but when I open the file the changes aren't there. Neither the text nor the mtext shows changes.

I don't know what I'm missing, but I will try from my home computer this evening and see if I have any success.

0 Likes
Message 7 of 9

paullimapa
Mentor
Mentor
Accepted solution

I did not tell you to detach any xref files. I just told you to simplify your batch file by not using those set statements and to change the for loop format....review my previous post.

Also since you're loading the lisp from c:\autodesk folder, make sure this folder is added under Options>Files>Trusted Locations: 

paullimapa_0-1716244413960.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 8 of 9

matthew_schwartz5CELZ
Contributor
Contributor
Yes, thank you! Adding the path to trusted locations did it!
0 Likes
Message 9 of 9

paullimapa
Mentor
Mentor

glad to have helped...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos