How autoload subroutines code

How autoload subroutines code

MANTONIOPM
Advocate Advocate
997 Views
6 Replies
Message 1 of 7

How autoload subroutines code

MANTONIOPM
Advocate
Advocate

Goodnight. I would like to know how to load subroutines that I have in a directory, so that they only load when executing their command. The initial code is the following:

 

;loads all needed subroutines
(vl-load-com)
(if (findfile ".\\Subrutinas\\LeeMac")
(mapcar '(lambda (x)
(if (wcmatch (strcase x) "*.LSP")
(load
(strcat (findfile ".\\Subrutinas\\LeeMac") "\\" x)
) ;_load
) ;_ if
) ;_ lambda
(vl-directory-files
(findfile ".\\Subrutinas\\LeeMac")
) ;_ vl-directory-files
) ;_ mapcar
) ;_ if

 

 

I tried to change "load" for "autoload", but it does not work.

0 Likes
998 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant

@MANTONIOPM wrote:

Goodnight. I would like to know how to load subroutines that I have in a directory, so that they only load when executing their command. ….

….
(load
(strcat (findfile ".\\Subrutinas\\LeeMac") "\\" x)
) ;_load
….


 

The (autoload) function also needs to be given a list of command names defined in the file, to be able to recognize those when called for, and load the file itself:

 

(autoload

  (strcat (findfile ".\\Subrutinas\\LeeMac") "\\" x)

  '("CommandName1" "CommandName2" "CommandName3")

)

 

[Even if only one command is defined, it needs to be put into a list like that.]

Kent Cooper, AIA
0 Likes
Message 3 of 7

dgorsman
Consultant
Consultant

Most run of the mill routines won't affect anything when loaded.  Just load them when the drawing is opened.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 4 of 7

MANTONIOPM
Advocate
Advocate

Good morning, excuse me, but it doesn't work. I wrote this code:

 

(autoload

(strcat (findfile ".\\Subrutinas\\LeeMac") "\\" x)

'("cajaenvolvente" "strike" "strike2" "strike3" "under" "under2" "overunder2")
)

0 Likes
Message 5 of 7

dbhunia
Advisor
Advisor

@MANTONIOPM wrote:

Goodnight. I would like to know how to load subroutines that I have in a directory, so that they only load when executing their command. The initial code is the following:

.......


You can try like this.......

 

(setq LispPath "D:\\Subrutinas\\LeeMac");;;Put here the full path of the Directory containing your subroutines(Lisp)
(foreach Lisp (vl-directory-files LispPath "*.lsp" 1)
  (autoload (strcat LispPath Lisp) '("cajaenvolvente" "strike" "strike2" "strike3" "under" "under2" "overunder2"))
)

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant

@MANTONIOPM wrote:

Good morning, excuse me, but it doesn't work. I wrote this code:

 

(autoload

(strcat (findfile ".\\Subrutinas\\LeeMac") "\\" x)

'("cajaenvolvente" "strike" "strike2" "strike3" "under" "under2" "overunder2")
)


Not knowing your whole file structure, etc., I can't diagnose completely.  But in the containing code, 'x' represents a different file name  for every file found in that folder as it goes through them.  Surely the set of command names defined in each file differs.  Does each file define one  command?  If so, you can't (autoload) the whole set of them for every file, because when a listed command is called for, it has to be associated with one  file that is to be loaded.  That may be why the code is set up to use (load) instead of (autoload), because (load) doesn't care what or how many commands are defined.

 

If there's one  command per file, and if the file name [minus the .lsp filetype ending] is the same as the command name  for each one, maybe this will work, taking the .lsp off the end to put that command name into the list [untested]:

(autoload (strcat (findfile ".\\Subrutinas\\LeeMac") "\\" x) (list (substr x 1 (- (strlen x) 4))))

Kent Cooper, AIA
0 Likes
Message 7 of 7

MANTONIOPM
Advocate
Advocate

Hello, in leemac folder y have three files .lsp.

 

StrikethroughV1-1.lsp define "strike", "strike2", "strike3", "under", "under2", "overunder2"

cajaenvolvente(minboundingbox).lsp load minboundingbox.lsp.

 

according to what is written here now I have the following code:

 

(autoload

(strcat (findfile ".\\Subrutinas\\LeeMac") "\\" cajaenvolvente(minboundingbox) minboundingbox StrikethroughV1-1)

'("cajaenvolvente" "strike" "strike2" "strike3" "under" "under2" "overunder2")
)

0 Likes