<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic LISP that inserts different block based on user input in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622081#M55328</link>
    <description>&lt;P&gt;I'm trying to create a tool that will insert the correct sized block based on a number input from the user. Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;User runs the LISP&lt;/P&gt;&lt;P&gt;User is prompted to input a number&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If user specified number is less than 250, then insert Block A&lt;/LI&gt;&lt;LI&gt;If user specified number is 250 or greater and less than 500, then insert Block B&lt;/LI&gt;&lt;LI&gt;If user specified number is 500 or greater, then insert Block C&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Note: The number the user is inputting may be a decimal&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know how to do basic If statements but I'm not sure how to handle a list of conditions or work with ranges of numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated!&lt;/P&gt;</description>
    <pubDate>Tue, 14 Sep 2021 17:34:53 GMT</pubDate>
    <dc:creator>BL_Apex</dc:creator>
    <dc:date>2021-09-14T17:34:53Z</dc:date>
    <item>
      <title>LISP that inserts different block based on user input</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622081#M55328</link>
      <description>&lt;P&gt;I'm trying to create a tool that will insert the correct sized block based on a number input from the user. Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;User runs the LISP&lt;/P&gt;&lt;P&gt;User is prompted to input a number&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If user specified number is less than 250, then insert Block A&lt;/LI&gt;&lt;LI&gt;If user specified number is 250 or greater and less than 500, then insert Block B&lt;/LI&gt;&lt;LI&gt;If user specified number is 500 or greater, then insert Block C&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Note: The number the user is inputting may be a decimal&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know how to do basic If statements but I'm not sure how to handle a list of conditions or work with ranges of numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 17:34:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622081#M55328</guid>
      <dc:creator>BL_Apex</dc:creator>
      <dc:date>2021-09-14T17:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: LISP that inserts different block based on user input</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622120#M55329</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8670497"&gt;@BL_Apex&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;.... I'm not sure how to handle a list of &lt;FONT color="#0000FF"&gt;cond&lt;/FONT&gt;itions or work with ranges of numbers.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your terminology is right on.&amp;nbsp; This is a perfect application of the &lt;FONT color="#0000FF"&gt;(cond)&lt;/FONT&gt; function [&lt;A href="https://help.autodesk.com/view/ACD/2022/ENU/?guid=GUID-7BA45202-D95F-4F2D-8D83-965024826074" target="_blank" rel="noopener"&gt;read about it&lt;/A&gt;].&amp;nbsp; For example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;(setq num (getreal "\nThe number: "))&lt;/P&gt;
&lt;P&gt;(command "_.insert"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; (cond &lt;EM&gt;&lt;FONT color="#00CCFF"&gt;; determine Block name from numerical range&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ((&amp;lt; num 250) "BlockA")&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;((&amp;lt; num 500) "BlockB")&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ("BlockC")&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ); cond&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &lt;EM&gt;&lt;FONT color="#00CCFF"&gt;.... on to insertion point, etc.....&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 17:47:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622120#M55329</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2021-09-14T17:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: LISP that inserts different block based on user input</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622130#M55330</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8670497"&gt;@BL_Apex&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm trying to create a tool that will insert the correct sized block based on a number input from the user. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;User runs the LISP&lt;/P&gt;
&lt;P&gt;User is prompted to input a number&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;If user specified number is less than 250, then insert Block A&lt;/LI&gt;
&lt;LI&gt;If user specified number is 250 or greater and less than 500, then insert Block B&lt;/LI&gt;
&lt;LI&gt;If user specified number is 500 or greater, then insert Block C&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Note: The number the user is inputting may be a decimal&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;(defun c:demo (/ d)
(initget 6)
  (princ
    (Strcat "\nBlock to insert: "
	    (cond
	      ((not (setq d (getreal "\nEnter number:"))))	      
	      ((&amp;lt; d 250) "Block A")
	      ((&amp;lt;= 250 d 500) "Block B")
	      ((&amp;gt; d 500) "Block C")
	    )
    )
  )(princ)
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 17:57:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622130#M55330</guid>
      <dc:creator>pbejse</dc:creator>
      <dc:date>2021-09-14T17:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: LISP that inserts different block based on user input</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622614#M55331</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/69526"&gt;@Kent1Cooper&lt;/a&gt;&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/564264"&gt;@pbejse&lt;/a&gt;&amp;nbsp;thank you both for the working solutions! I knew it was simple I just couldn't get it formatted correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the event that I wanted to have a maximum value, let's say 2000, is there a way that the "otherwise" part of the statement could be set up to read "Invalid input. Enter number between 0 and 2000" on the command line and&amp;nbsp; prompt the user for another input?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 21:22:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622614#M55331</guid>
      <dc:creator>BL_Apex</dc:creator>
      <dc:date>2021-09-14T21:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: LISP that inserts different block based on user input</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622679#M55332</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;In the event that I wanted to have a maximum value, let's say 2000, is there a way that the "otherwise" part of the statement could be set up to read "Invalid input. Enter number between 0 and 2000" on the command line and&amp;nbsp; prompt the user for another input?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The asking again part is much easier if that check and prompt are in the getting-the-number part, rather than a none-of-the-above condition when already in the Insert command:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(while&lt;/P&gt;
&lt;P&gt;&amp;nbsp; (and&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; (not (initget 4)); no negative [0 permitted] &lt;FONT size="2"&gt;{wrapped in (not) because (initget) returns nil}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; (setq num (getreal "\nNumber between 0 and 2000: "))&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; (&amp;gt; num 2000)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ); and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;(prompt "\nInvalid input. Enter number between 0 and 2000")&lt;/P&gt;
&lt;P&gt;); while&lt;/P&gt;
&lt;P&gt;(command "_.insert"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; (cond&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;FONT color="#00CCFF"&gt;; determine Block name from numerical range&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ((&amp;lt; num 250) "BlockA")&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;((&amp;lt; num 500) "BlockB")&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ("BlockC")&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ); cond&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;FONT color="#00CCFF"&gt;.... on to insertion point, etc.....&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 22:04:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622679#M55332</guid>
      <dc:creator>Kent1Cooper</dc:creator>
      <dc:date>2021-09-14T22:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: LISP that inserts different block based on user input</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622723#M55333</link>
      <description>&lt;P&gt;Excellent. Makes perfect sense.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 22:26:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10622723#M55333</guid>
      <dc:creator>BL_Apex</dc:creator>
      <dc:date>2021-09-14T22:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: LISP that inserts different block based on user input</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10623228#M55334</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8670497"&gt;@BL_Apex&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the event that I wanted to have a maximum value, let's say 2000, is there a way that the "otherwise" part of the statement could be set up to read "Invalid input. Enter number between 0 and 2000" on the command line and&amp;nbsp; prompt the user for another input?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;LI-CODE lang="general"&gt;(defun BlockNameIsValid ( lmt  / d)
(initget 5)
    (cond
      ((not (setq d (getreal (strcat "\nEnter number between 0 and "
				     (rtos lmt 2 0) ": "))))
       )
      ((&amp;lt; d 250) 	"Block A")
      ((&amp;lt;= 250 d 500) 	"Block B")
      ((&amp;lt;  500 d lmt) 	"Block C")
      (t (alert "Invalid input") (BlockNameIsValid lmt))
    )
  )&lt;/LI-CODE&gt;
&lt;P&gt;Usage&lt;/P&gt;
&lt;P&gt;(BlockNameIsValid 2000)&lt;/P&gt;
&lt;P&gt;Enter number between 0 and &lt;STRONG&gt;2000&lt;/STRONG&gt;:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(BlockNameIsValid 5000)&lt;/P&gt;
&lt;P&gt;Enter number between 0 and &lt;STRONG&gt;5000&lt;/STRONG&gt;:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 05:54:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-that-inserts-different-block-based-on-user-input/m-p/10623228#M55334</guid>
      <dc:creator>pbejse</dc:creator>
      <dc:date>2021-09-15T05:54:46Z</dc:date>
    </item>
  </channel>
</rss>

