TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mmason on May 20, 2009, 03:15:00 PM
-
Using the following happy code:
(setq LispFolder "C:\\mlm_DEV\\")
(if (findfile (strcat LispFolder "FE_EraseBlankText.lsp"))
(autoload (strcat LispFolder "FE_EraseBlankText") '("EBT"))
)
(setq LispFolder "C:\\mlm_DEV\\") returns
"C:\\mlm_DEV\\" OK so far...
(strcat LispFolder "FE_EraseBlankText.lsp") returns
"C:\\mlm_DEV\\FE_EraseBlankText.lsp" As it should...
(findfile (strcat LispFolder "FE_EraseBlankText.lsp")) returns
"C:\\mlm_DEV\\FE_EraseBlankText.lsp" Still good, the file is there...
(autoload (strcat LispFolder "FE_EraseBlankText") '("EBT")) returns
nil Ummmm...
EBT returns
The file C:mlm_DEVFE_EraseBlankText(.lsp/.exe/.arx) was not found in your
search path folders.
Check the installation of the support files and try again.nil
What?
This has gotten me all confused, unhappy, frustrated, tired and extremely thirsty.
What happened to my little slash thingys in the filepath?
Didn't this used to work?
Isn't this supposed to still work?
Oh! My head! Al, please take your heimers back!
-
Is "LispFolder" in your support file search path? If not add it then you don't have to check for it.
-
(setq LispFolder "C:\\mlm_DEV\\")
(if (findfile (strcat LispFolder "FE_EraseBlankText.lsp"))
(autoload (vl-string-translate "\\" "/" (strcat LispFolder "FE_EraseBlankText.lsp")) '("EBT"))
)
causes some kind of crazy loop for me... that was cool.
-
Is "LispFolder" in your support file search path? If not add it then you don't have to check for it.
I know that works, but I'm kinda lookin' at a situation where I'd rather not add some folders to everyboy's search paths.
Besides, I thought this worked! The help file says that it will use search paths if a filepath is not specified - one would assume that if a filepath IS specified, the routine would look there.
Of course, we all know about assuming...
-
(setq LispFolder "C:\\mlm_DEV\\")
(if (findfile (strcat LispFolder "FE_EraseBlankText.lsp"))
(autoload (vl-string-translate "\\" "/" (strcat LispFolder "FE_EraseBlankText.lsp")) '("EBT"))
)
causes some kind of crazy loop for me... that was cool.
:-) I tried the slashes both ways, but I never got loopy.
-
I thought this worked in older versions, as you said. However, after looking at the code for (autoload) ...this is just another lisp in the acadXXXXdoc.lsp file..... I see that it is stripping out the backslashes when using folders. If you do this it should work:
(setq LispFolder "C:\\\\mlm_DEV\\\\")
(autoload (strcat LispFolder "FE_EraseBlankText") '("EBT"))
Looking back at the code from Acad2002 it is identical, so the problem must've been there, too.
-
I thought this worked in older versions, as you said. However, after looking at the code for (autoload) ...this is just another lisp in the acadXXXXdoc.lsp file..... I see that it is stripping out the backslashes when using folders.
Looking back at the code from Acad2002 it is identical, so the problem must've been there, too.
And thus, I refer back to the thread subject...
I'll be danged if I can figure out why they would want to do that?
-
I don't think they 'wanted' to do that, it's just the way it worked out and evidently they neglected to test for it. The command works fine as long as you give just the filename, sans path. Once you include the path (even though help says you can) is when it falls apart.....which is due to the way they constructed the code. Essentially they create a new lisp command on the fly, using the CMD name(s) you provide, and use the ai_ffile (a fancy version of (findfile) that looks for lsp, arx, exp, & exe files) to locate the specified file. The trouble is, when you wrap the (strcat ..... filename .....) inside a (read) function, the "\"'s get used incorrectly. I'm sure there's a way to add a check, prior to the creation of the new defun, for the "\"'s and insert additional backslashes as needed.....but I don't have time to do so right now.
-
Devils advocate: why dont you just build your own autoload. -i.e. build a simple "hook".
-
Hi,
I found the autoloader a little bit tempermental at times. So wrote this as an alternative..works pretty well
(defun autoloader (fname ListCommands)
(if
(findfile fname)
(MAPCAR
'(LAMBDA (f)
(eval
(read
(strcat
"(defun c:"f" () (load \"" fname "\") (c:" f "))"))))
ListCommands
)
(print (strcat "\n*** Unable to locate " fname " ***"))
)
)
;Sample
(autoloader "acad commands.lsp" '("bf" "mc"))
-
Why not just LOAD the lisp and be done with it? 8-)
-
Why not just LOAD the lisp and be done with it? 8-)
CAB,
I thought the same thing too (I never even heard of "autoload" before today) but i assumed there was some sort of reason for its use (maybe the preserving of variable definitions re-defined in the lisp or something).
jammie,
kinda what i was thinking.
-
AUTOLOAD saves memory the lisp routine would be occuping. I use it but most have lots of memory these days. :)
My autload file, jut a small segment. So I would not LOAD all these but if you have a path problem just LOAD that one.
;;; ===============================================
;;; Lisp Routine Loader
;;; AUTOLOAD only loads the routine when needed
;;; ===============================================
;;;------ Lisp name -- Function name(s) ------- Discription -----------------------
(AUTOLOAD "AlignAllDCL CAB" '("AlignAll")) ; Align Text or Objects
(AUTOLOAD "Angle Bisect" '("BISECT")) ;
(AUTOLOAD "AreaPrt" '("AreaPrt")) ; Print the Area of "POLYLINE" "LWPOLYLINE" "CIRCLE" "ELLIPSE"
(AUTOLOAD "arrow line" '("arw")) ; draw a arrow line on stairs, plan view
(AUTOLOAD "ArrowDrainage" '("darrow")) ; draw a drainage arrow
(AUTOLOAD "Arrows by Tim W" '("DPA")) ; draw a hollow arrow, by Tim Willey
(AUTOLOAD "AttrMatch CAB" '("AttrMatch" "attrm" "attm")) ; Match block Attributes
(AUTOLOAD "Block 2 Layer 0-CAB" '("FixBlock")) ; Repair Block Layers
(AUTOLOAD "Block UnmirrorCAB" '("bum")) ; Unmirror blocks picked
(AUTOLOAD "BlockDel CAB" '("BlockDel")) ; Delete ALL matching blocks & purge the DWG
-
CAB, ah. I see. kinda cool.
jammie,
I had a closer look at your routine and i couldnt really get you procedure to work so i whiped up my own.
I was thinking something along these lines. ...this could be modified to accept a list of commands to closer resemble autoload, but this is more of a proof of concept kinda thing.
This is a brief example on how I would go about making my own `autoload' procedure.
For example:
In my lisp file (C:\test.lsp) I have the following:
(defun c:ebt ( / ) (alert "I'm a lisp command"))
In my other lisp file I would define a simple hook procedure.
(defun hook ( func path )
;; given: (hook "EBT" "C:\\test.lsp")
;; >
;; (DEFUN C:EBT (/) (DEFUN C:EBT (/) (PRINC "\n[ EBT ] Command not availble") (PRINC)) (LOAD "C:/test.lsp") (C:EBT))
(eval
(list
'defun
(read (strcat "c:" func))
'( / )
(list 'defun
(read (strcat "c:" func))
'( / )
(list 'princ
(strcat "\n[ " func " ] Command not availble"))
(list 'princ))
(list 'load path)
(list (read (strcat "c:" func))))) )
Then I can just hook the commands I want to be `autoloaded' (hooked)
(hook "EBT" "C:\\test.lsp")
(hook "TBE" "C:\\test.lsp") ; not defined in file
Simple and effective? ...maybe. I still kinda agree with CAB though; just load it.
-
OBTW welcome to The Swamp jammie 8-)
-
This does not work:
(autoloader "C:\\Program Files\\ACAD2000\\LISP Routines\\SubRoutines\\test.lsp" '("ttt" ))
But this does
(autoloader "C:/Program Files/ACAD2000/LISP Routines/SubRoutines/test.lsp" '("ttt" ))
This fails to findfile
(autoloader "C:\\\\Program Files\\\\ACAD2000\\\\LISP Routines\\\\SubRoutines\\\\test.lsp" '("ttt" ))