TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: HasanCAD on February 19, 2013, 05:23:48 AM
-
When run this lisp
there is error message
Command: gmf
; error: no function definition: LM:COPYBLOCK
(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 ::")
-
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.
(defun c:Test_Order_Wrong
( / MyPrincFunction
) (MyPrincFunction "test")
; Nested function
(defun MyPrincFunction
(str
) )
)
(defun c:Test_Order_OK
( / MyPrincFunction
)
; Nested function
(defun MyPrincFunction
(str
) )
(MyPrincFunction "test")
)
-
Don't you have the function LM:COPYBLOCK
you must load the fuction..and then run your code...
-
This could be related to the order of the main function.
...
Working
Is it better to include the subroutine in main routine
(defun c:Test_Order_OK ( / MyPrincFunction)
; Nested function
(defun MyPrincFunction (str)
(princ str)
)
(MyPrincFunction "test")
(princ)
)
or make it separate
(defun c:Test_Order_OK ( / MyPrincFunction)
(princ)
)
; Nested function
(defun MyPrincFunction (str)
(princ str)
)
-
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.
-
What is best depends on the situation.
.......
Good tip
Thanks