+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    419

    Default Limiting the input value of a variable

    Registered forum members do not see this ad.

    How can I limit the input value for a variable?.
    I tried the following lisp unsuccessfully:
    Code:
     
    (defun c:limit()
      (setq s 8)
    (while (and (< s 2.5) (> s 7)) (setq s(getreal "\nGive value between 2.5 and 7:")))
    )
    Thanking in advance.
    Aloy

  2. #2
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    4,008

    Default

    Those conditions cannot be met simultaneously:
    Code:
    (defun c:limit()
     (setq s 8)
     (while (or (< s 2.5)
                (> s 7.0))
      (setq s (getreal "\nGive value between 2.5 and 7.0: "))
     )
    )
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  3. #3
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,261

    Default

    Code:
    (defun c:limit (/ in)
      (while
        (not
          (or (< (setq in (getreal "\n Give value between 2.5 and 7:"))
             2.5
          )
          (> in 7)
          )
        )
         (princ "\n ** Must be Less than 2.5 or Biggar than 7.0 **")
      )
      (princ)
    )

  4. #4
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    4,008

    Default

    Tharwat, I'm afraid that your code is in fact rejecting the values it should accept and vice versa; there is also a conflict among prompter, respectively error message:
    Code:
    (defun c:limit (/ in)
      (while
        (not
          (and (>= (setq in (getreal "\n Give value between 2.5 and 7:"))
             2.5
          )
          (<= in 7)
          )
        )
         (princ "\n ** Must be Less than 2.5 or Bigger than 7.0 **")   ;?!?
      )
      (princ)
    )
    Last edited by MSasu; 22nd Jul 2012 at 05:28 am. Reason: Fixed code to accept limits of interval too
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  5. #5
    Luminous Being BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    2 x 240GB Samsung EVO SSD (RAID 0)
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Discipline
    Civil
    BlackBox's Discipline Details
    Occupation
    Senior Civil Designer
    Discipline
    Civil
    Details
    Public/Private Land Development, Transportation, and Utilities.
    Using
    Civil 3D 2016
    Join Date
    Nov 2009
    Posts
    5,282

    Default

    Also consider the INITGET function.
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD, and Civil 3D Certified Professional | Autodesk Authorized Developer
    Sincpac C3D ~ Exchange Apps ~ Autoloader ~ AutoCAD Security

  6. #6
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,261

    Default

    My understanding of the Op goal is to accept the values between 2.5 to 7.0 and that's what my code does .

    I don't get what conflict you are talking about !

    I got not error message with Cad 2013

  7. #7
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    4,008

    Default

    Quote Originally Posted by Tharwat View Post
    My understanding of the Op goal is to accept the values between 2.5 to 7.0 and that's what my code does .
    That's true, "between"! Your routine accept only values outside this interval...

    Quote Originally Posted by Tharwat View Post
    I got not error message with Cad 2013
    Sorry, but mathematical logic isn't influenced by AutoCAD's version.
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  8. #8
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    419

    Default

    Hi Msasu,
    Thanks very much. It works fine.
    Aloy

  9. #9
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    419

    Default

    Hi Tharwat,
    Thanks for the code. It works; needs a correction to the string to give the intended meaning.
    Regards,
    Aloy

  10. #10
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    419

    Default

    Registered forum members do not see this ad.

    RenderMan,
    I thought 'INITGET' functions accept certain values, but not values within a defined range.
    Regards,
    Aloy

Similar Threads

  1. Set getstring variable using a DCL input box?
    By Brick_top in forum AutoLISP, Visual LISP & DCL
    Replies: 12
    Last Post: 5th Jan 2012, 03:26 pm
  2. Limiting Access to Tool Palettes
    By KnoJa31 in forum CAD Management
    Replies: 5
    Last Post: 26th Aug 2010, 01:49 pm
  3. Assembly - Limiting component movement
    By tonyc in forum Autodesk Inventor
    Replies: 4
    Last Post: 10th Feb 2010, 01:06 pm
  4. no input box
    By alec in forum AutoCAD Beginners' Area
    Replies: 8
    Last Post: 17th May 2009, 09:56 am

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