TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: HasanCAD on February 19, 2013, 05:23:48 AM

Title: The Lisp asks every time for subroutine
Post by: HasanCAD on February 19, 2013, 05:23:48 AM
When run this lisp
there is error message
Code: [Select]
Command: gmf
; error: no function definition: LM:COPYBLOCK


Code: [Select]
(defun c:GMF ( / BLK DWG E INSPNT N OSN OSOLD SEL SS ) (vl-load-com)

  <...>
 
;SUB

(defun *error* (m) ;  Author: Lee Mac,
    ...  )
  (defun insblk (/) ; HasanCAD
    ...    )   
(defun algn ( / CMN CMO DXFDATA ENTITY OLD-DXF PNT1 PNT2 SEL)  (vl-load-com) ; HasanCAD
  ...  ) 
  (defun round (number by)
    ... )
  (defun LM:ObjectDBXDocument ( / acVer) ;  Author: Lee Mac,
  ...  )
  (defun LM:Itemp ( coll item) ;  Author: Lee Mac,
  ...  )
    (defun LM:CopyBlock ( block filename / acapp acdoc acblk acdocs dbxDoc item ) ;  Author: Lee Mac,
  ...  )
  (defun LM:ObjectDBXDocument ( / acVer ) ;  Author: Lee Mac,
  ...  )
  (defun LM:Popup ( title msg flags / wsh res ) ;  Author: Lee Mac,
  ...  )
 
  )
(princ "\n:: GMF.lsp | Version 1.0 | Type GMF to invoke the lisp ::")
Title: Re: The Lisp asks every time for subroutine
Post by: roy_043 on February 19, 2013, 05:44:59 AM
This could be related to the order of the main function. The nested functions should come before the rest of the code. See the examples below. Alternatively you can 'un-nest' the nested functions. If you are nesting functions, declaring their names as local variables makes more sense.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test_Order_Wrong ( / MyPrincFunction)
  2.   (MyPrincFunction "test")
  3.  
  4.   ; Nested function
  5.   (defun MyPrincFunction (str)
  6.     (princ str)
  7.   )
  8.  
  9.   (princ)
  10. )
  11.  
  12. (defun c:Test_Order_OK ( / MyPrincFunction)
  13.  
  14.   ; Nested function
  15.   (defun MyPrincFunction (str)
  16.     (princ str)
  17.   )
  18.  
  19.   (MyPrincFunction "test")
  20.   (princ)
  21. )
Title: Re: The Lisp asks every time for subroutine
Post by: kraz on February 19, 2013, 06:26:20 AM
Don't you have the function LM:COPYBLOCK

you must load the fuction..and then run your code...
Title: Re: The Lisp asks every time for subroutine
Post by: HasanCAD on February 19, 2013, 07:29:26 AM
This could be related to the order of the main function.
...
Working
Is it better to include the subroutine in main routine
Code: [Select]
(defun c:Test_Order_OK ( / MyPrincFunction)
 
  ; Nested function
  (defun MyPrincFunction (str)
    (princ str)
  )
 
  (MyPrincFunction "test")
  (princ)
)

or make it separate
Code: [Select]
(defun c:Test_Order_OK ( / MyPrincFunction)
(princ)
)
  ; Nested function
  (defun MyPrincFunction (str)
    (princ str)
  )
Title: Re: The Lisp asks every time for subroutine
Post by: roy_043 on February 19, 2013, 11:19:14 AM
What is best depends on the situation.

If a sub-routine is used by only one function I will typically nest the sub-routine (and declare it as a local variable). In all other cases I do not nest sub-routines.

For testing it is easier not to have nested sub-routines. Testing a nested sub-routine separately is harder.
Title: Re: The Lisp asks every time for subroutine
Post by: HasanCAD on February 20, 2013, 01:27:14 AM
What is best depends on the situation.
.......
Good tip
Thanks