Function error

Discussion in 'AutoCAD' started by John Georgiev, Jun 29, 2004.

  1. I have routine containing the following part:
    (cond
    ((> (getvar "cvport") 1)
    (setq xpf (rtos (/ 1 (caddr (trans '(0 0 1) 2 3))) 2 0))
    (setq setsc (strcat "mode" xpf))
    (setsc)
    )
    ((= (getvar "cvport") 1)
    (psmode)
    )

    The problem is that all functions called here (in result of the string SETSC
    or directly called as PSMODE) cannot be found even that they are defined by
    *.mnl file and when I type any of them on the command row:
    Command: (function)
    everything is OK and they run.
    Called from the routine I have the following errors:
    error: bad function: "function" - when function is called using SETSC
    string
    error: no function definition: PSMODE - when function is called directly
    Tim Willey suggested that in the first error the quotes are the problem and
    if we eliminate them somehow, the problem will be solved. Maybe he is
    partially right, but I'm not sure that the quotes are the only problem,
    because the function PSMODE at the end of the routine is defined already and
    the function name doesn't come from string and have no quotes in the error
    message (see second error).
    Thank you.
    John
     
    John Georgiev, Jun 29, 2004
    #1
  2. John Georgiev

    ECCAD Guest

    Change:
    (setq setsc (strcat "mode" xpf))
    (setsc)
    )
    ((= (getvar "cvport") 1)
    (psmode)
    )
    To:
    (setq setsc (strcat "mode" xpf))
    (C:setsc)
    )
    ((= (getvar "cvport") 1)
    (C:psmode)
    )
    And, in your .mnl file, do:
    (defun C:setsc ()
    and
    (defun C:psmode ()
    .........

    Bob
     
    ECCAD, Jun 29, 2004
    #2
  3. Thanks Bob,
    The SETSC are actually set of functions with similar names containing two
    parts - "mode"+number. The row (setq setsc (strcat "mode" xpf) creating the
    function name as string combining the word "mode" and the value of xpf. So
    there is no SETSC function at all.
    About the PSMODE - I did what you said and I got the following error:
    error: invalid AutoCAD command: nil
    But the function is there and works from the command line.
    Thanks again.
    John
     
    John Georgiev, Jun 29, 2004
    #3
  4. John Georgiev

    ECCAD Guest

    In that case, try:
    (setq setsc (strcat "mode " xpf)); note the space..
    Bob
     
    ECCAD, Jun 29, 2004
    #4
  5. No Bob, I don't need space.
    See - let say one of my functions from the *.mnl file is called MODE20.
    I have to combine MODE and 20. There is a case when XPF has value 20 and
    this case require the function MODE20 to be called.
    Final result after STRCAT in this case is that SETSC value is MODE20. All is
    correct up to this point. I have this function defined and tested from the
    command row. It works. But called from the Lisp it cannot be accessed - I
    got:
    ; error: bad function: "mode20"
    This is the result in both cases - when the function is defined as AutoCAD
    function
    defun C:mode20 ()
    or just
    defun mode20 ()

    I tried (command setsc), and also (command (getstring setsc)), and only
    (getstring setsc) with no success.

    Thanks.
    John
     
    John Georgiev, Jun 29, 2004
    #5
  6. John Georgiev

    Barr Guest

    Can you post the entire routine?
    Also include those sections of the mnl file which you mentioned.
     
    Barr, Jun 29, 2004
    #6
  7. The routine:

    (if (null db:svr)
    (setq db:svr (vlr-sysvar-reactor
    '("CVPORT")
    '(:)vlr-sysvarchanged . setscale))
    )
    )
    )
    (defun setscale (r data)
    (if (member (car data) (vlr-data r))
    (cond
    ((> (getvar "cvport") 1)
    (setq xpf (rtos (/ 1 (caddr (trans '(0 0 1) 2 3))) 2 0))
    (setq setsc (strcat "mode" xpf))
    (setsc)
    )
    ((= (getvar "cvport") 1)
    (psmode)
    )
    )
    )
    )


    From the *.mnl file (just one of the functions):

    (defun mode20 ()
    (command "insert" "*setup20" "0,0" "" "")
    (setvar "celtscale" 20)
    (setvar "textstyle" "note20")
    (setvar "textsize" 2.1875)
    (command "dim1" "restore" "20_dims")
    (command "-units" "2" "4" "" "2" "" "")
    (command "limits" "" "70.0000,50.0000")
    (command "regen")
    (princ)
    )
     
    John Georgiev, Jun 29, 2004
    #7
  8. John Georgiev

    MP Guest

    John, try this idea

    (setq funcname "Mode20")
    (eval(read(strcat "(" funcname")")))

    (defun Mode20()
    (princ"\nTest mode20")
    )
    hth
    Mark
     
    MP, Jun 29, 2004
    #8
  9. John Georgiev

    Barr Guest

    Still not enough for me to see where the error is. I'd like
    to see the defuns (psmode) and (setsc) from your mnl file.
     
    Barr, Jun 29, 2004
    #9
  10. John Georgiev

    ECCAD Guest

    MP,
    That works good. I was trying to remember the (eval...
    but could not recall the (read...
    Good one.
    Bob
     
    ECCAD, Jun 29, 2004
    #10
  11. John Georgiev

    T.Willey Guest

    ((eval (read setsc)))

    This worked. Nice one Mark. I did the read part, and it didn't work, but I didn't know about eval. It worked in my test drawing.

    Tim
     
    T.Willey, Jun 29, 2004
    #11
  12. Barr, there is no SETSC function. See the beginning of the conversation with
    ECCAD. As I mentioned many times the problem is not in the functions in
    *.mnl file - they all work well from command line, the problem is that I
    can't call them from the routine.
    John
     
    John Georgiev, Jun 29, 2004
    #12
  13. John Georgiev

    Barr Guest

    Not knowing what version of Acad you're using, all I could do was compare it to
    my setup.

    Neither setsc nor (setsc) are a command within Acad2000. Thus I assumed it was
    loaded from your company's acad.lsp or mnl file. Pardon my confusion.
    -doug
     
    Barr, Jun 29, 2004
    #13
  14. Yes Tim, this converted the string, but still didn't solve the problem. See
    the Alan Henderson suggestion above and my answer.
    I think there is something terrible wrong (and probably very simple) in my
    code but I can't catch it.
    John
     
    John Georgiev, Jun 29, 2004
    #14
  15. John Georgiev

    ECCAD Guest

    Barr,
    Didn't someone mention NOT to use 'command's when using a Reactor / call-back function. I think this might be a problem.

    Bob
     
    ECCAD, Jun 29, 2004
    #15
  16. I'm using 2004.
    The SETSC are actually set of functions with similar names containing two
    parts - "mode"+number. The row (setq setsc (strcat "mode" xpf) creating the
    function name as string combining the word "mode" and the value of xpf. So
    there is no SETSC function at all.
    Then the value of SETSC is executed as command.
    About the PSMODE - it is simple function from the *.mnl file, but when I
    call it from the routine I got this error:
    error: invalid AutoCAD command: nil
    The function is there and works from the command line.
    Thanks.
    John
     
    John Georgiev, Jun 29, 2004
    #16
  17. John Georgiev

    T.Willey Guest

    (cond
    ((> (getvar "cvport") 1)
    (setq xpf (rtos (/ 1 (caddr (trans '(0 0 1) 2 3))) 2 0))
    (setq setsc (strcat "mode" xpf))
    ((eval(read setsc)));; notice there is an extra set of "()" around the "eval" function
    )
    ((= (getvar "cvport") 1)
    (psmode)
    )

    This version worked. Here it is straight from Acad.

    Command: (defun mode48()
    (_> (princ "It worked.")
    (_> (princ)
    (_> )
    MODE48

    Command: (cond
    (_> ((> (getvar "cvport") 1)
    ((_> (setq xpf (rtos (/ 1 (caddr (trans '(0 0 1) 2 3))) 2 0))
    ((_> (setq setsc (strcat "mode" xpf))
    ((_> ((eval(read setsc)))
    ((_> )
    (_> ((= (getvar "cvport") 1)
    ((_> (psmode)
    ((_> )
    (_> )
    It worked.

    If it still doesn't work, post what happens.

    Tim
     
    T.Willey, Jun 29, 2004
    #17
  18. John Georgiev

    ECCAD Guest

    I think the problem now is, the .mnl is being loaded (after) startup - and (after) the reactor fires. You will need to place the (defun mode20 () ...and others into your acaddoc.lsp, which is loaded (earlier). That way, the functions will be available..

    Bob
     
    ECCAD, Jun 29, 2004
    #18
  19. John Georgiev

    MP Guest

    so did you try my suggestion to your original post?
     
    MP, Jun 29, 2004
    #19
  20. Tim, this really worked with the simple example function you used - I
    created this function in my *.mnl file restarted AutoCAD and it worked.
    But it still didn't work with my function (which is in the same *.mnl file):

    (defun MODE20 ()
    (command "insert" "*setup20" "0,0" "" "")
    (setvar "celtscale" 20)
    (setvar "textstyle" "note20")
    (setvar "textsize" 2.1875)
    (command "dim1" "restore" "20_dims")
    (command "-units" "2" "4" "" "2" "" "")
    (command "limits" "" "70.0000,50.0000")
    (command "regen")
    (princ)
    )

    Then I got it - the error message
    ; error: invalid AutoCAD command: nil
    actually might be for the first row - command "insert", not for MODE20.
    Maybe Bob is right that reactors can't be used with COMMAND.
    Then I replaced COMMAND with VL-CMDF and the error message was gone. The
    problem is that the file SETUP20 I need to insert was not inserted - so
    generally this is killing the whole idea this routine was created for.
    Now the question is how to make the above function MODE20 to insert this
    file.
    John
     
    John Georgiev, Jun 29, 2004
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.