+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
  1. #1
    Junior Member
    Discipline
    Construction
    Using
    AutoCAD 2018
    Join Date
    Nov 2017
    Posts
    22

    Default Error in this line

    Registered forum members do not see this ad.

    Hi All

    #(setq Cloud (getstring("\nEnter an Option P or O )))#
    Can you tell me why this line is producing an error?

    This is the error:
    .Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).
    Converting (command) calls to (command-s) is recommended.

    However this line works if I substitute it for the one above but obviously it doesn't give me a choice
    #(setq Cloud O)#

  2. #2
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,422

    Default

    Code:
    (setq Cloud (progn (initget "P O") (getkword "\nEnter an Option [P/O]: " )))

  3. #3
    Quantum Mechanic
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,402

    Default

    Tunzagibbo pick the # not type it or [ c o d e] and [ / c o d e] if you want to type it.
    A man who never made mistakes never made anything

  4. #4
    Junior Member
    Discipline
    Construction
    Using
    AutoCAD 2018
    Join Date
    Nov 2017
    Posts
    22

    Default

    Hi Grrr
    Thanks for your code
    I'm still having a bit of a problem here. Can you please help me with this code?
    I know that by just running the "revcloud" command in Autocad I can make a selection of either P or O, but my Lisp is only part of the bigger picture.
    If I cut and paste the 2 DEFUNS ("objectcloud" & "polygoncloud") into the Autocad command line they both run fine on their own.
    It's when I try to combine them into a lisp program that I get the error.

    It seems to fail when I enter either P or O

    Code:
    (defun c: mycloud ()
    (setq Cloud (progn (initget "P O") (getkword "\nEnter an Option [P/O]: " )))
    (if (= Cloud O) (objectcloud))
    (if (= Cloud P) (polygoncloud))
    
    (defun polygoncloud ()
       (setvar "orthmode" 1) 
       (command-s"._revcloud" "_P")
    )
    (defun objectcloud () 
       (command "._revcloud" "_O" pause "No")
    )

  5. #5
    Junior Member
    Using
    AutoCAD 2015
    Join Date
    Jun 2017
    Posts
    23

    Default

    Because you are storing a string in the variable 'cloud' its value will be either "P" or "O" not P or O

    Code:
    (defun c:mycloud ( / Cloud ) ; localise cloud variable
      (initget 1 "P O")
      (setq Cloud (getkword "\nEnter an Option [P/O]: " ))
      (if (= Cloud "P")
          (polygoncloud) ; if "P"
          (objectcloud) ; else "O"
      )
    )

  6. #6
    Junior Member
    Discipline
    Construction
    Using
    AutoCAD 2018
    Join Date
    Nov 2017
    Posts
    22

    Default

    This the actual code I am trying to run But still having trouble.

    Code:
    (defun c:bbb (/ Cloud)
    (initget 1 "P O p o") 
    (setq Cloud (getkword "\nEnter an Option [P/O] " ))
    (if (= Cloud "O") (objectcloud) (polygoncloud))
    
    (defun polygoncloud ()
       (setvar "orthmode" 1) 
       (command-s"._revcloud" "_P")
    )
    (defun objectcloud () 
       (command-s "._revcloud" "_O" pause "No")
    )
    )

  7. #7
    Junior Member
    Using
    AutoCAD 2015
    Join Date
    Jun 2017
    Posts
    23

    Default

    hmm.. it works if you declare the subfunctions first, I didn't know this was an issue, have always just put them at the top by habit. Good idea allowing for upper & lower case, adding strcase will make sure the variable is always capital.

    Code:
    (defun c:bbb (/ polygoncloud objectcloud Cloud)
      (defun polygoncloud ()
        (setvar "orthomode" 1)
        (command "._revcloud" "_P")
      )
      (defun objectcloud ()
        (command "._revcloud" "_O" pause "No")
      )
    
      (initget 1 "P O")
      (setq Cloud (strcase (getkword "\nEnter an Option [P/O]: ")))
      (if (= Cloud "O") (objectcloud) (polygoncloud))
      (princ)
    )
    Last edited by FranknBeans; 15th Apr 2018 at 08:02 am. Reason: formatting

  8. #8
    Junior Member
    Discipline
    Construction
    Using
    AutoCAD 2018
    Join Date
    Nov 2017
    Posts
    22

    Default

    Thanks for your help Frank. All works good now

    Regards

    Tony

  9. #9
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,422

    Default

    Quote Originally Posted by FranknBeans View Post
    hmm.. it works if you declare the subfunctions first, I didn't know this was an issue, have always just put them at the top by habit.
    In this case they appear to be local for the main function, and its important to be declared first - Everything that you put inside in a function (main or sub) is being evaluated from top to bottom order.
    Exceptions from the default 'top2bottom' order are calling from functions that have been evaluated already.

    Top to bottom evaluation order applies when apploading the .lsp file aswell, it evaluates all the declared function one by one starting to the top till the bottom is reached.
    Then once all the main(s) and subfunction(s) are declared/evaluated, you can run the main without any worries for undefined (sub)functions.
    Notice that when the interpreter evaluates a function, it just checks it content - where potentially you could recieve 'extra left/right paren on input' error,
    but it DOESN'T run the function (which means running/checking all the evaluations inside):
    Code:
    _$ (defun test ( / ) ; <- The function /main/
      ; These things will be evaluated from top to bottom order, starting from this row
      ; <code> ... bla bla
      (MyUndefinedFunction ; <- a subfunction we use inside of our main, but we didn't define it anywhere (so the main will try to run it, but will crash because it was never evaluated)
      ) ; <- our main should crash at this evaluation, and will stop going thru the next bottom lines 
      ; <code> ... bla bla
      ; we could define/evaluate the subfoo here, but since we already attempted to run it before defining it, we will recieve an error
      ; (defun MyUndefinedFunction ( / ) <code> .. bla bla)
    ); defun test
    TEST ; <- This means our main function evaluated successfuly (no syntax errors)
    
    _$ (test) ; <- Now we run it, it will step through all the evaluations inside (TOP to BOTTOM order)
    
    Error: no function definition: MYUNDEFINEDFUNCTION ; <- it doesn't recognise it, because we never define it (or we tried to define it after we ran it)
    _1$ 
    
    _$ test ; <- lets check if our main is defined/evaluated
    #<USUBR @000000b646f7c570 TEST> ; <- yes it is
    _$ MyUndefinedFunction ; <- lets check if our subfunction is defined/evaluated
    nil ; <- no its not
    Overall related things in this thread.
    IMO Anyway in this case its not required, and probably better to avoid defining subfoos.


    Quote Originally Posted by FranknBeans View Post
    Good idea allowing for upper & lower case, adding strcase will make sure the variable is always capital.
    Although in my example its not strictly required to check for lower/upper case, I agree that its a good overall practice to perform 'just in case' techniques.


    Quote Originally Posted by FranknBeans View Post
    Code:
    ...(initget 1 "P O")...
    I wouldn't advise to force user's input, because if he decides to exits you leave no other option than making him to trigger an error.
    [Time ago Lee pointed that out in my code, when I used (while T ...)]

    Even here you can trace this bad example from the adsk techs, by calling:
    Code:
    (command "._revcloud" "_O")

    That said, it would be better to pass your own arguments and decide whether to call the "REVCLOUD" command, rather than calling it first and regretting it (instantly) :

    Code:
    (defun C:MyCloud nil
      (eval 
        (cdr 
          (assoc (progn (initget "P O X") (cond ((getkword "\nEnter an Option [P/O/eXit] <O>: " ))("O")))
            '(
              ("O" 
                '( ( / e ) 
                  (and 
                    (setq e (entsel "\nPick object: ")) 
                    (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getEndParam (list (car e)))))
                    (command "._REVCLOUD" "_O" e "No" )
                  )
                )
              )
              ("P" 
                '( (x / v)
                  (setq v (getvar x))
                  (initcommandversion)
                  (command "._REVCLOUD" "_P") 
                  (while (= 1 (logand 1 (getvar 'CMDACTIVE))) (setvar x 1) (command pause)) 
                  (setvar x v)
                ) 
                'orthomode
              )
            )
          )
        )
      )
      (princ)
    ); defun C:MyCloud
    (vl-load-com) (princ)
    I know that the structure of my code would be more readable/simple for someones, if cond function was used rather than assoc, but I just think this was the plain conception when LISP was designed (to use/manipulate/evaluate lists).

  10. #10
    Junior Member
    Discipline
    Construction
    Using
    AutoCAD 2018
    Join Date
    Nov 2017
    Posts
    22

    Default

    Registered forum members do not see this ad.

    Thank you to all involved here I really appreciate your help

    Regards
    Tony

Similar Threads

  1. Custom Line Type Error!
    By sivapathasunderam in forum The CUI, Hatches, Linetypes, Scripts & Macros
    Replies: 4
    Last Post: 2nd Feb 2016, 12:13 pm
  2. Plotting to PDF, same layer: different line weight error?
    By iancampbell4 in forum AutoCAD Drawing Management & Output
    Replies: 0
    Last Post: 30th Apr 2011, 01:18 pm
  3. Memory Error line 56 on this Web Site.
    By muck in forum Feedback
    Replies: 3
    Last Post: 1st Jul 2010, 02:46 pm
  4. Bad Function error from command line
    By Bill Tillman in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 21st Apr 2009, 03:55 pm
  5. Centre-line LISP Error
    By Lee Mac in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 26th Nov 2008, 09:21 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts