LISP problem

Discussion in 'AutoCAD' started by Xolo, Jun 22, 2004.

  1. Xolo

    Tom Smith Guest

    I'd suggest double-checking to see that shlang actually has a value as
    intended, at the point that the polar calculation is done. Also slend and
    shlss, which you haven't mentioned before.

    An old-fashioned but effective way to do this is to put (print shlang) etc.
    immediately before the polar calc. There's a newfangled vlisp way of
    watching a variable's value, which I don't know how to use, as I don't use
    the vlide interfgace at all.
     
    Tom Smith, Jun 22, 2004
    #21
  2. Xolo

    Xolo Guest

    Tom,

    I have made shlang to equal to a number. It's either 0 or 90.

    Well, here's what I have so far....it's by no means finished, but you can
    try it out to see why it isn't able to get past that point;

    ;;;-------------------------------------------------------------------------
    ----------;
    ;;; June 22, 2004 WRITTEN BY THOMAS M. STORZUK VESSEL.lsp ;
    ;;;-------------------------------------------------------------------------
    ----------;
    ;;; This program draws a vertical or horizontal vessel with 2:1 SE heads
    ;
    ;;;-------------------------------------------------------------------------
    ----------;

    ;;;------Set up degrees-to-radians and radians-to degrees
    calculations--------------;;;
    (defun DTR (deg) (* pi (/ deg 180.0)))
    (defun RTD (rad) (* 180.0 (/ rad pi)))
    ;;;------Define what the function is called and make variables local to the
    LISP----;;;
    (defun C:VESSEL (/ svce svom)
    ;;;------Set all system variables that need to be
    changed---------------------------;;;
    (setq svce (getvar "cmdecho"))
    (setq svom (getvar "osmode"))
    (setvar "cmdecho" 0)
    (setvar "osmode" 0)
    ;;;------For changing the entities drawn to the correct layer as
    required-----------;;;
    (defun chglayer (layname)
    (entmod (subst (cons 8 layname) (assoc 8 (entget (entlast))) (entget
    (entlast))))
    )
    ;;;------Get user input for the
    vessel----------------------------------------------;;;
    (initget "V H")
    (setq answ (getkword
    "\n\nWhat type of vessel do you want to draw [V,H]: "))
    (cond
    ((= answ "V") (setq shlang 0.00))
    ((= answ "H") (setq shlang 90.00)))
    ;;; vang is the angle the vessel is to be drawn at
    (setq shlod (getreal "\nWhat is the OD of the shell: "))
    ;;; shlod is the shell OD
    (setq shlthk (getreal "\nWhat is the thickness of the shell wall: "))
    ;;; shlthk is the shell wall thickness
    (setq shlss (getreal "\nWhat is the S/S length of the shell: "))
    ;;; shlss is the seam-to-seam length fo the shell
    (setq insshl '(0.00,0.00))
    ;;; insshl is the insertion point of the shell datum to 0,0 for ordinate
    dimensions-;;;
    ;;;-------------------------------------------------------------------------
    --------;;;
    ;;;-------------------------------------------------------------------------
    --------;;;
    ;;;------Set the points needed for the centerline of the shell and insertion
    of the-;;;
    ;;;------2:1 SE
    heads---------------------------------------------------------------;;;
    (setq shlend (polar insshl (DTR shlang) shlss))
    ;;;------Set the points needed to draw one side of the
    shell------------------------;;;
    (setq shlout1 (polar insshl (DTR (+ shlang 90.0)) (/ OD 2)))
    (setq shlout2 (polar shlend (DTR (+ shlang 90.0)) (/ OD 2)))
    (setq shlin1 (polar insshl (DTR (+ shlang 90.0)) (- (/ OD 2) THK)))
    (setq shlin2 (polar shlend (DTR (+ shlang 90.0)) (- (/ OD 2) THK)))
    ;;;------Set the points needed to draw the other side of the
    shell------------------;;;
    (setq shlout3 (polar insshl (DTR (- shlang 90.0)) (/ OD 2)))
    (setq shlout4 (polar shlend (DTR (- shlang 90.0)) (/ OD 2)))
    (setq shlin3 (polar insshl (DTR (- shlang 90.0)) (- (/ OD 2) THK)))
    (setq shlin4 (polar shlend (DTR (- shlang 90.0)) (- (/ OD 2) THK)))
    ;;;------Draw the
    shell-------------------------------------------------------------;;;
    (command "_PLINE" shlout1 shlout2 "")
    (chglayer "EQUIP")
    (command "_PLINE" shlin1 shlin2 "")
    (chglayer "HIDDEN")
    (command "_PLINE" shlout3 shlout4 "")
    (chglayer "EQUIP")
    (command "_PLINE" shlin3 shlin4 "")
    (chglayer "HIDDEN")
    ;;;------Draw the centerline of the
    shell-------------------------------------------;;;
    (command "_PLINE" insshl shlend "")
    (chglayer "CENTER")
    ;;;------Get user input to draw the 2:1 SE
    heads------------------------------------;;;
    (setq OD (getdist "\nEnter the outside diameter of the head: "))
    (setq SF 2)
    (setq HTHK (getdist "\nEnter the thickness of the vessel head: "))
    ;;;------Calculate the depth of the 2:1 SE
    heads------------------------------------;;;
    (setq DEPTH (+(/(- OD (* 2 HTHK)) 4) SF HTHK))


    ;;;------Re-set all changed system
    variables----------------------------------------;;;
    (setvar "cmdecho" svce)
    (setvar "osmode" svom)
    (princ)
    )
    ;;;---------------------------------------END OF THE
    FILE---------------------------;;;

    That's it so far, but like I said, it's geting stuck on the (setq shlend
    (polar insshl (DTR shlang) shlss)) line and it doesn't like what shlang is
    set to??? I think (but I'm usually wrong)??

    Thanks

    Xolo

    Yes, the dtr function expects a number representing an angle in degrees. If
    you look at that function, it's dividing the deg vaiable by 180 and then
    multiplying it by pi.

    As with any programming languages, you must always be conscious of the
    "type" of a variable -- string, integer, real number, or whatever.
     
    Xolo, Jun 22, 2004
    #22
  3. Xolo

    ECCAD Guest

    (setq insshl '(0.00,0.00))
    could be the culprit. remove the "," from the 'list

    Bob
     
    ECCAD, Jun 22, 2004
    #23
  4. Xolo

    Tom Smith Guest

    That's it so far, but like I said, it's geting stuck on the (setq shlend
    It's because you set insshl incorrectly in (setq insshl '(0.00,0.00)). The
    illegal comma prevents the list from being evaluated properly, and the polar
    function thinks that insshl is '(0) -- not a valid point.

    Use (setq insshl '(0 0)) or (setq insshl (list 0 0 0)) -- no commas in a
    list.
     
    Tom Smith, Jun 22, 2004
    #24
  5. Here is the problem:
    (setq insshl '(0.00,0.00))

    should be:
    (setq insshl '(0.00 0.00))

    You also have problems past that with variable names that you have obviously
    changed, e.g. OD isn't defined, but shlod is.

    --
    R. Robert Bell


    Tom,

    I have made shlang to equal to a number. It's either 0 or 90.

    Well, here's what I have so far....it's by no means finished, but you can
    try it out to see why it isn't able to get past that point;

    ;;;-------------------------------------------------------------------------
    ----------;
    ;;; June 22, 2004 WRITTEN BY THOMAS M. STORZUK VESSEL.lsp ;
    ;;;-------------------------------------------------------------------------
    ----------;
    ;;; This program draws a vertical or horizontal vessel with 2:1 SE heads
    ;
    ;;;-------------------------------------------------------------------------
    ----------;

    ;;;------Set up degrees-to-radians and radians-to degrees
    calculations--------------;;;
    (defun DTR (deg) (* pi (/ deg 180.0)))
    (defun RTD (rad) (* 180.0 (/ rad pi)))
    ;;;------Define what the function is called and make variables local to the
    LISP----;;;
    (defun C:VESSEL (/ svce svom)
    ;;;------Set all system variables that need to be
    changed---------------------------;;;
    (setq svce (getvar "cmdecho"))
    (setq svom (getvar "osmode"))
    (setvar "cmdecho" 0)
    (setvar "osmode" 0)
    ;;;------For changing the entities drawn to the correct layer as
    required-----------;;;
    (defun chglayer (layname)
    (entmod (subst (cons 8 layname) (assoc 8 (entget (entlast))) (entget
    (entlast))))
    )
    ;;;------Get user input for the
    vessel----------------------------------------------;;;
    (initget "V H")
    (setq answ (getkword
    "\n\nWhat type of vessel do you want to draw [V,H]: "))
    (cond
    ((= answ "V") (setq shlang 0.00))
    ((= answ "H") (setq shlang 90.00)))
    ;;; vang is the angle the vessel is to be drawn at
    (setq shlod (getreal "\nWhat is the OD of the shell: "))
    ;;; shlod is the shell OD
    (setq shlthk (getreal "\nWhat is the thickness of the shell wall: "))
    ;;; shlthk is the shell wall thickness
    (setq shlss (getreal "\nWhat is the S/S length of the shell: "))
    ;;; shlss is the seam-to-seam length fo the shell
    (setq insshl '(0.00,0.00))
    ;;; insshl is the insertion point of the shell datum to 0,0 for ordinate
    dimensions-;;;
    ;;;-------------------------------------------------------------------------
    --------;;;
    ;;;-------------------------------------------------------------------------
    --------;;;
    ;;;------Set the points needed for the centerline of the shell and insertion
    of the-;;;
    ;;;------2:1 SE
    heads---------------------------------------------------------------;;;
    (setq shlend (polar insshl (DTR shlang) shlss))
    ;;;------Set the points needed to draw one side of the
    shell------------------------;;;
    (setq shlout1 (polar insshl (DTR (+ shlang 90.0)) (/ OD 2)))
    (setq shlout2 (polar shlend (DTR (+ shlang 90.0)) (/ OD 2)))
    (setq shlin1 (polar insshl (DTR (+ shlang 90.0)) (- (/ OD 2) THK)))
    (setq shlin2 (polar shlend (DTR (+ shlang 90.0)) (- (/ OD 2) THK)))
    ;;;------Set the points needed to draw the other side of the
    shell------------------;;;
    (setq shlout3 (polar insshl (DTR (- shlang 90.0)) (/ OD 2)))
    (setq shlout4 (polar shlend (DTR (- shlang 90.0)) (/ OD 2)))
    (setq shlin3 (polar insshl (DTR (- shlang 90.0)) (- (/ OD 2) THK)))
    (setq shlin4 (polar shlend (DTR (- shlang 90.0)) (- (/ OD 2) THK)))
    ;;;------Draw the
    shell-------------------------------------------------------------;;;
    (command "_PLINE" shlout1 shlout2 "")
    (chglayer "EQUIP")
    (command "_PLINE" shlin1 shlin2 "")
    (chglayer "HIDDEN")
    (command "_PLINE" shlout3 shlout4 "")
    (chglayer "EQUIP")
    (command "_PLINE" shlin3 shlin4 "")
    (chglayer "HIDDEN")
    ;;;------Draw the centerline of the
    shell-------------------------------------------;;;
    (command "_PLINE" insshl shlend "")
    (chglayer "CENTER")
    ;;;------Get user input to draw the 2:1 SE
    heads------------------------------------;;;
    (setq OD (getdist "\nEnter the outside diameter of the head: "))
    (setq SF 2)
    (setq HTHK (getdist "\nEnter the thickness of the vessel head: "))
    ;;;------Calculate the depth of the 2:1 SE
    heads------------------------------------;;;
    (setq DEPTH (+(/(- OD (* 2 HTHK)) 4) SF HTHK))


    ;;;------Re-set all changed system
    variables----------------------------------------;;;
    (setvar "cmdecho" svce)
    (setvar "osmode" svom)
    (princ)
    )
    ;;;---------------------------------------END OF THE
    FILE---------------------------;;;

    That's it so far, but like I said, it's geting stuck on the (setq shlend
    (polar insshl (DTR shlang) shlss)) line and it doesn't like what shlang is
    set to??? I think (but I'm usually wrong)??

    Thanks

    Xolo

    Yes, the dtr function expects a number representing an angle in degrees. If
    you look at that function, it's dividing the deg vaiable by 180 and then
    multiplying it by pi.

    As with any programming languages, you must always be conscious of the
    "type" of a variable -- string, integer, real number, or whatever.
     
    R. Robert Bell, Jun 22, 2004
    #25
  6. Xolo

    Xolo Guest

    Thanks a lot guys,

    I really appreciate the help with this one.....I'm sure to need more at a
    later date too.

    Take care,

    Xolo
    Here is the problem:
    (setq insshl '(0.00,0.00))

    should be:
    (setq insshl '(0.00 0.00))

    You also have problems past that with variable names that you have obviously
    changed, e.g. OD isn't defined, but shlod is.

    --
    R. Robert Bell


    Tom,

    I have made shlang to equal to a number. It's either 0 or 90.

    Well, here's what I have so far....it's by no means finished, but you can
    try it out to see why it isn't able to get past that point;

    ;;;-------------------------------------------------------------------------
    ----------;
    ;;; June 22, 2004 WRITTEN BY THOMAS M. STORZUK VESSEL.lsp ;
    ;;;-------------------------------------------------------------------------
    ----------;
    ;;; This program draws a vertical or horizontal vessel with 2:1 SE heads
    ;
    ;;;-------------------------------------------------------------------------
    ----------;

    ;;;------Set up degrees-to-radians and radians-to degrees
    calculations--------------;;;
    (defun DTR (deg) (* pi (/ deg 180.0)))
    (defun RTD (rad) (* 180.0 (/ rad pi)))
    ;;;------Define what the function is called and make variables local to the
    LISP----;;;
    (defun C:VESSEL (/ svce svom)
    ;;;------Set all system variables that need to be
    changed---------------------------;;;
    (setq svce (getvar "cmdecho"))
    (setq svom (getvar "osmode"))
    (setvar "cmdecho" 0)
    (setvar "osmode" 0)
    ;;;------For changing the entities drawn to the correct layer as
    required-----------;;;
    (defun chglayer (layname)
    (entmod (subst (cons 8 layname) (assoc 8 (entget (entlast))) (entget
    (entlast))))
    )
    ;;;------Get user input for the
    vessel----------------------------------------------;;;
    (initget "V H")
    (setq answ (getkword
    "\n\nWhat type of vessel do you want to draw [V,H]: "))
    (cond
    ((= answ "V") (setq shlang 0.00))
    ((= answ "H") (setq shlang 90.00)))
    ;;; vang is the angle the vessel is to be drawn at
    (setq shlod (getreal "\nWhat is the OD of the shell: "))
    ;;; shlod is the shell OD
    (setq shlthk (getreal "\nWhat is the thickness of the shell wall: "))
    ;;; shlthk is the shell wall thickness
    (setq shlss (getreal "\nWhat is the S/S length of the shell: "))
    ;;; shlss is the seam-to-seam length fo the shell
    (setq insshl '(0.00,0.00))
    ;;; insshl is the insertion point of the shell datum to 0,0 for ordinate
    dimensions-;;;
    ;;;-------------------------------------------------------------------------
    --------;;;
    ;;;-------------------------------------------------------------------------
    --------;;;
    ;;;------Set the points needed for the centerline of the shell and insertion
    of the-;;;
    ;;;------2:1 SE
    heads---------------------------------------------------------------;;;
    (setq shlend (polar insshl (DTR shlang) shlss))
    ;;;------Set the points needed to draw one side of the
    shell------------------------;;;
    (setq shlout1 (polar insshl (DTR (+ shlang 90.0)) (/ OD 2)))
    (setq shlout2 (polar shlend (DTR (+ shlang 90.0)) (/ OD 2)))
    (setq shlin1 (polar insshl (DTR (+ shlang 90.0)) (- (/ OD 2) THK)))
    (setq shlin2 (polar shlend (DTR (+ shlang 90.0)) (- (/ OD 2) THK)))
    ;;;------Set the points needed to draw the other side of the
    shell------------------;;;
    (setq shlout3 (polar insshl (DTR (- shlang 90.0)) (/ OD 2)))
    (setq shlout4 (polar shlend (DTR (- shlang 90.0)) (/ OD 2)))
    (setq shlin3 (polar insshl (DTR (- shlang 90.0)) (- (/ OD 2) THK)))
    (setq shlin4 (polar shlend (DTR (- shlang 90.0)) (- (/ OD 2) THK)))
    ;;;------Draw the
    shell-------------------------------------------------------------;;;
    (command "_PLINE" shlout1 shlout2 "")
    (chglayer "EQUIP")
    (command "_PLINE" shlin1 shlin2 "")
    (chglayer "HIDDEN")
    (command "_PLINE" shlout3 shlout4 "")
    (chglayer "EQUIP")
    (command "_PLINE" shlin3 shlin4 "")
    (chglayer "HIDDEN")
    ;;;------Draw the centerline of the
    shell-------------------------------------------;;;
    (command "_PLINE" insshl shlend "")
    (chglayer "CENTER")
    ;;;------Get user input to draw the 2:1 SE
    heads------------------------------------;;;
    (setq OD (getdist "\nEnter the outside diameter of the head: "))
    (setq SF 2)
    (setq HTHK (getdist "\nEnter the thickness of the vessel head: "))
    ;;;------Calculate the depth of the 2:1 SE
    heads------------------------------------;;;
    (setq DEPTH (+(/(- OD (* 2 HTHK)) 4) SF HTHK))


    ;;;------Re-set all changed system
    variables----------------------------------------;;;
    (setvar "cmdecho" svce)
    (setvar "osmode" svom)
    (princ)
    )
    ;;;---------------------------------------END OF THE
    FILE---------------------------;;;

    That's it so far, but like I said, it's geting stuck on the (setq shlend
    (polar insshl (DTR shlang) shlss)) line and it doesn't like what shlang is
    set to??? I think (but I'm usually wrong)??

    Thanks

    Xolo

    Yes, the dtr function expects a number representing an angle in degrees. If
    you look at that function, it's dividing the deg vaiable by 180 and then
    multiplying it by pi.

    As with any programming languages, you must always be conscious of the
    "type" of a variable -- string, integer, real number, or whatever.
     
    Xolo, Jun 22, 2004
    #26
  7. Xolo

    MP Guest

    also just a heads up
    (/ OD 2)
    if od happens to be an integer, like 3, that will return 1 instead of 1.5
    (/ OD 2.0) is safer way to be sure you don't get unwanted truncation
     
    MP, Jun 22, 2004
    #27
  8. Xolo

    Xolo Guest

    Tom,

    The new fangled way to check if something has a value set to it is by
    putting an exclamation mark before the variable name at the command
    line.......e.g.

    !shlang

    And thanks for the tip. Even the most basic debugging sometimes slips the
    thought process.

    Xolo
     
    Xolo, Jun 27, 2004
    #28
  9. Xolo

    Xolo Guest

    Wow,

    All of these pointers and help are really going to help make my code a lot
    better than it normally would have been. Thanks MP, I always try to keep
    that one in mind, but I'm still pretty green with this stuff.

    Xolo
     
    Xolo, Jun 27, 2004
    #29
  10. Xolo

    Paul Turvill Guest

    "...new fangled..."? AFAIK, that method has been around since the very
    introduction of AutoLISP, many years ago.
    ___
     
    Paul Turvill, Jun 27, 2004
    #30
  11. Xolo

    Tom Smith Guest

    The exclamation mark isn't new, it's shorthand for the eval function and has
    been around forever. At the command prompt, it will let you check the value
    of a global variable -- one which has had a value assigned, and then been
    left dangling. Unless there is a specific reason for doing so, this is
    normally very poor programming practice.

    If the variable is declared local, as it should be, then it will be nil
    before and after the execution of the code, and there will be nothing to be
    learned by evaluating it at the command line.

    I'm talking about checking the value of a variable as the program is
    running, specifically checking it at the point in the program where it
    matters. An old way of doing this is to use print commands for debugging
    purposes. In the VLIDE, there is a "watch" provision, but since I find the
    entire VLIDE awkward and intrusive, I've never been able to stand running it
    long enough to figure out how anything in it works. I use a normal text
    editor.
     
    Tom Smith, Jun 28, 2004
    #31
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.