Author Topic: The Linkage between 2 Codes  (Read 1856 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 462
The Linkage between 2 Codes
« on: June 18, 2010, 12:03:57 AM »
I have a piece of code (Code 1) associating with 2 different codes (Code 2 & Code 3).
I want to do this because I think it would allow me to modify Code 1 easily later.
I have already setup the auto loading link in acad2011doc.lsp but it doesn't work.
There is no problem when the code is a single piece.
The Code 1 is a simple defun.
I have tried many times but cannot get it to work.
It doesn't work even I save the following angle convertion function as Code 1:
Code: [Select]
(defun DTR (A)
(* pi (/ A 180.0))
); end of DTR

Thanks for your help.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: The Linkage between 2 Codes
« Reply #1 on: June 18, 2010, 12:36:36 AM »
Are you talking about functions that you use in other routines?

I use something as simple as this in an .mnl file:
Code: [Select]
;;INSTALL DIRECTORY PATH
(defun rjp-installdir (file /)
  (if (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*")
    (strcat (getenv "programfiles") " (x86)\\AutoCAD Tools" file)
    (strcat (getenv "programfiles") "\\AutoCAD Tools" file)
  )
)

;;LOADS GLOBAL LISP FUNCTIONS
(if (findfile (rjp-installdir "\\Functions.lsp"))
  (load (rjp-installdir "\\Functions.lsp"))
  (alert "\n   <<Couldn't Load Lisp Functions>>")
)
(princ)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MeasureUp

  • Bull Frog
  • Posts: 462
Re: The Linkage between 2 Codes
« Reply #2 on: June 18, 2010, 12:50:34 AM »
Are you talking about functions that you use in other routines?

I use something as simple as this in an .mnl file:
Code: [Select]
;;INSTALL DIRECTORY PATH
(defun rjp-installdir (file /)
  (if (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*")
    (strcat (getenv "programfiles") " (x86)\\AutoCAD Tools" file)
    (strcat (getenv "programfiles") "\\AutoCAD Tools" file)
  )
)

;;LOADS GLOBAL LISP FUNCTIONS
(if (findfile (rjp-installdir "\\Functions.lsp"))
  (load (rjp-installdir "\\Functions.lsp"))
  (alert "\n   <<Couldn't Load Lisp Functions>>")
)
(princ)
Yes, I want to load functions used in other routines.
But I don't prefer to load the function.lsp with .mnl file.

kpblc

  • Bull Frog
  • Posts: 396
Re: The Linkage between 2 Codes
« Reply #3 on: June 18, 2010, 01:32:03 AM »
Anyway you have to load your lsp-files (or put all code inside one lisp-file).
If you're saving all lsp-codes within one directory (for example, "d:\autocad\lsp"), you can add to startup suite just one file with code like this:
Code: [Select]
(defun _kpblc-browsefiles-in-directory-nested (path mask)
;|
*    Based on code by ZZZ : http://www.caduser.ru/cgi-bin/f1/board.cgi?t=32891aD

*    Function returns file list (with mask) placed in one directory with proceeding nested directories
*    Call parameters:
*  path - directory to proceed
*  mask - file name mask.
*    Call samples:
(_kpblc-browsefiles-in-directory-nested "c:\\documents" "*.dwg")
(_kpblc-browsefiles-in-directory-nested "c:\\autocad\\lsp" "*.lsp")
|;
  (apply
    (function append)
    (cons
      (if (vl-directory-files path mask)
        (mapcar (function (lambda (x) (strcat path "\\" x)))
                (vl-directory-files path mask)
                ) ;_ end of mapcar
        ) ;_ if
      (mapcar
        (function (lambda (x)
                    (_kpblc-browsefiles-in-directory-nested
                      (strcat path "\\" x)
                      mask
                      ) ;_ end of kpblc-browsefiles-in-directory-nested
                    ) ;_ end of lambda
                  ) ;_ end of function
        (vl-remove
          ".."
          (vl-remove "." (vl-directory-files path nil -1))
          ) ;_ end of vl-remove
        ) ;_ mapcar
      ) ;_ cons
    ) ;_ end of apply
  ) ;_ end of defun

;; sample for autostart executing code
;; (_kpblc-browsefiles-in-directory-nested "d:\\autocad\\lsp" "*.lsp")
And then all your codes will be 'downloaded' to active AutoCAD document.
P.S. Sorry for my English.
Sorry for my English.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: The Linkage between 2 Codes
« Reply #4 on: June 18, 2010, 09:23:01 AM »
Are you talking about functions that you use in other routines?

I use something as simple as this in an .mnl file:
Code: [Select]
;;INSTALL DIRECTORY PATH
(defun rjp-installdir (file /)
  (if (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*")
    (strcat (getenv "programfiles") " (x86)\\AutoCAD Tools" file)
    (strcat (getenv "programfiles") "\\AutoCAD Tools" file)
  )
)

;;LOADS GLOBAL LISP FUNCTIONS
(if (findfile (rjp-installdir "\\Functions.lsp"))
  (load (rjp-installdir "\\Functions.lsp"))
  (alert "\n   <<Couldn't Load Lisp Functions>>")
)
(princ)
Yes, I want to load functions used in other routines.
But I don't prefer to load the function.lsp with .mnl file.

So did your question get answered :? The key is to put all your functions in one file then call that file via your "preferred" method. :whistle:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: The Linkage between 2 Codes
« Reply #5 on: June 21, 2010, 12:20:00 PM »
At least, put the "common" functions in a single file and load that.  After a while these can expand to where its difficult to find something, then it can be better to split the functions into logical groupings, and then the group of files is loaded from a central loading function.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

kpblc

  • Bull Frog
  • Posts: 396
Re: The Linkage between 2 Codes
« Reply #6 on: June 21, 2010, 01:40:12 PM »
I don't like this method - if you have 500 lisp functions, you'll get too much troubles.
Sorry for my English.

MeasureUp

  • Bull Frog
  • Posts: 462
Re: The Linkage between 2 Codes
« Reply #7 on: June 22, 2010, 06:50:40 PM »
Thanks to all your helps.
 :lol: