Author Topic: getstring with getpoint?  (Read 4998 times)

0 Members and 1 Guest are viewing this topic.

EddieFromDc

  • Newt
  • Posts: 34
getstring with getpoint?
« on: June 10, 2013, 01:45:50 PM »
Hello,

Is there a combimation of "getstring" and "getpoint". I would like to start my duct lisp routine with this..

Duct width [8.00]/Start point.

If user enters a number that will be the width of the new duct width and start my program.
If the users picks a point that will be the start of my program with the default width of 8".

Any suggestions would be appreciated...Thanks.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: getstring with getpoint?
« Reply #1 on: June 10, 2013, 02:30:18 PM »
I would  re-engineer the input sequence so it was consistently asking for size (with the default value) then start point or vice versa.  Flexiblity can be good but being too flexible adds a lot of uneccesary work.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: getstring with getpoint?
« Reply #2 on: June 10, 2013, 02:43:27 PM »
Code - Auto/Visual Lisp: [Select]
  1. ;;  return number or nil
  2. (defun txt2num (txt / num)
  3.   (or (setq num (distof txt 5))
  4.       (setq num (distof txt 2))
  5.       (setq num (distof txt 1))
  6.       (setq num (distof txt 4))
  7.       (setq num (distof txt 3))
  8.   )
  9.   (if (numberp num) num)
  10. )
  11.  
  12. (defun getpoint-or-dist (/ ans)
  13.   (initget 128)
  14.   (setq ans (getpoint "\nDuct width [8.00]/Start point. "))
  15.   (cond
  16.     ((null ans) (alert "Nothing entered."))
  17.     ((vl-consp ans) (princ "\nPoint Entered."))
  18.     ((and (= (type ans) 'str )
  19.           (princ "/nString entered")
  20.           (setq ans (txt2num ans))
  21.           (princ " and is a valid number.")
  22.     ))
  23.   )
  24.   ans
  25. )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: getstring with getpoint?
« Reply #3 on: June 10, 2013, 05:31:08 PM »
@CAB, minor suggestion for txt2num:
Code: [Select]
(defun txt2num ( txt )
    (vl-some '(lambda ( x ) (distof txt x)) '(5 2 1 4 3))
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: getstring with getpoint?
« Reply #4 on: June 10, 2013, 06:38:34 PM »
Thanks Lee, I should have dug up a more modern version but that was handy.
This is latest version.  8)
Code - Auto/Visual Lisp: [Select]
  1.   (defun txt2num (txt) ; CAB 10/2005
  2.     (cond
  3.         ((distof txt 5))
  4.         ((distof txt 2))
  5.         ((distof txt 1))
  6.         ((distof txt 4))
  7.         ((distof txt 3))
  8.     )
  9.   )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: getstring with getpoint?
« Reply #5 on: June 10, 2013, 06:57:46 PM »
Well, that was interesting...

Code: [Select]
Command: (benchmark '( (txt2num_LEE "25648645413219876846521684.584974654987")
(txt2num_CAB "25648645413219876846521684.584974654987")) )
Elapsed milliseconds / relative speed for 16384 iteration(s):

    (TXT2NUM_CAB "2564864541321987684652...).....1872 / 2.13 <fastest>
    (TXT2NUM_LEE "2564864541321987684652...).....3978 / 1.00 <slowest>

Command: (benchmark '( (txt2num_LEE "100.25") (txt2num_CAB "100.25")) )
Elapsed milliseconds / relative speed for 16384 iteration(s):

    (TXT2NUM_CAB "100.25").....1404 / 2.88 <fastest>
    (TXT2NUM_LEE "100.25").....4041 / 1.00 <slowest>
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: getstring with getpoint?
« Reply #6 on: June 11, 2013, 03:25:08 AM »
Well, that was interesting...
Might be due to the quoted lambda. Perhaps a (function (lambda ...)) might perform a bit faster. Or even a full on defun defined outside.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: getstring with getpoint?
« Reply #7 on: June 11, 2013, 03:30:02 AM »
In BricsCAD (distof) already does its own 'guess work'. No need for a (text2num) function.
Code - Auto/Visual Lisp: [Select]
  1. (distof "1e-1") => 0.1
  2. (distof "3.75") => 3.75
  3. (distof "1' 11.25\"") => 23.25
  4. (distof "1' 11 1/4\"") => 23.25
  5. (distof "3 1/3") => 3.33333

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: getstring with getpoint?
« Reply #8 on: June 11, 2013, 07:47:11 AM »
Well, that was interesting...
Might be due to the quoted lambda. Perhaps a (function (lambda ...)) might perform a bit faster. Or even a full on defun defined outside.
It did make some of a difference.

Code: [Select]
(defun txt2num_1 (txt)
  (vl-some (function (lambda (x) (distof txt x))) '(5 2 1 4 3))
)

(defun txt2num_2 (txt)
  (vl-some '(lambda (x) (distof txt x)) '(5 2 1 4 3))
)

(defun txt2num_3 (txt)
  (cond
    ((distof txt 5))
    ((distof txt 2))
    ((distof txt 1))
    ((distof txt 4))
    ((distof txt 3))
  )
)

Code: [Select]
Elapsed milliseconds / relative speed for 16384 iteration(s):

    (TXT2NUM_3 "256486454132198768465216...).....1092 / 2.1 <fastest>
    (TXT2NUM_1 "256486454132198768465216...).....1467 / 1.56
    (TXT2NUM_2 "256486454132198768465216...).....2294 / 1 <slowest>


Elapsed milliseconds / relative speed for 32768 iteration(s):

    (TXT2NUM_3 "256486454132198768465216...).....1732 / 2.07 <fastest>
    (TXT2NUM_1 "256486454132198768465216...).....2028 / 1.77
    (TXT2NUM_2 "256486454132198768465216...).....3588 / 1 <slowest>
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

EddieFromDc

  • Newt
  • Posts: 34
Re: getstring with getpoint?
« Reply #9 on: June 11, 2013, 07:59:30 AM »
Thank you guys...I don't what just happen but thank you!!

tedg

  • Swamp Rat
  • Posts: 811
Re: getstring with getpoint?
« Reply #10 on: June 11, 2013, 10:32:40 AM »
Can I just say you guys amaze me!
 
I'm happy if I get my routine to (just) work....
You guys are looking at how stream-lined and efficiently they can work.
 
One of the pleasures of hanging around here at TheSwamp!
 
My head hurts.
 
:beer:
Windows 10 Pro 64bit, AutoCAD 2023, REVIT 2023

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: getstring with getpoint?
« Reply #11 on: June 12, 2013, 01:49:46 AM »
It did make some of a difference.
And just to be complete, this version using the dynamic scoping of AutoLisp (though it's not a very good practise to do this)

Code - Auto/Visual Lisp: [Select]
  1. (defun distof_txt_helper (x) (distof txt x))
  2.  
  3. (defun txt2num_4 (txt)
  4.   (vl-some 'distof_txt_helper '(5 2 1 4 3))
  5. )

It's only "slightly" more efficient than the  lambda function. Still not getting to the direct cond idea.
Code: [Select]
Benchmarking ...................Elapsed milliseconds / relative speed for 65536 iteration(s):

    (TXT2NUM_3 "256486454132198768465216...).....1591 / 2.03 <fastest>
    (TXT2NUM_4 "256486454132198768465216...).....1716 / 1.88
    (TXT2NUM_1 "256486454132198768465216...).....1779 / 1.82
    (TXT2NUM_2 "256486454132198768465216...).....3229 / 1.00 <slowest>

In BricsCAD (distof) already does its own 'guess work'. No need for a (text2num) function.
I wonder how fast that would be in comparison to these for acad. It's definitely a lot less coding!
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: getstring with getpoint?
« Reply #12 on: June 12, 2013, 08:57:56 AM »
I don't suppose this make any difference?
Code: [Select]
(defun txt2num_4 (txt / distof_txt_helper)
     (defun distof_txt_helper (x) (distof txt x))
     (vl-some 'distof_txt_helper '(5 2 1 4 3))
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: getstring with getpoint?
« Reply #13 on: June 12, 2013, 09:41:38 AM »
That's a bit slower again, txt2num_4a as per your code:
Code: [Select]
Benchmarking ...................Elapsed milliseconds / relative speed for 65536 iteration(s):

    (TXT2NUM_3 "256486454132198768465216...).....1623 / 2.07 <fastest>
    (TXT2NUM_4 "256486454132198768465216...).....1748 / 1.92
    (TXT2NUM_4A "25648645413219876846521...).....1825 / 1.84
    (TXT2NUM_1 "256486454132198768465216...).....1841 / 1.82
    (TXT2NUM_2 "256486454132198768465216...).....3354 / 1.00 <slowest>
_$
The reason I think is it's defining the function on each iteration. Why the dynamically scoped version already has the function defined prior to it being called (i.e. as if it's a built-in function).
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: getstring with getpoint?
« Reply #14 on: June 12, 2013, 09:44:30 AM »
That's a bit slower again, txt2num_4a as per your code:
Code: [Select]
Benchmarking ...................Elapsed milliseconds / relative speed for 65536 iteration(s):

    (TXT2NUM_3 "256486454132198768465216...).....1623 / 2.07 <fastest>
    (TXT2NUM_4 "256486454132198768465216...).....1748 / 1.92
    (TXT2NUM_4A "25648645413219876846521...).....1825 / 1.84
    (TXT2NUM_1 "256486454132198768465216...).....1841 / 1.82
    (TXT2NUM_2 "256486454132198768465216...).....3354 / 1.00 <slowest>
_$
The reason I think is it's defining the function on each iteration. Why the dynamically scoped version already has the function defined prior to it being called (i.e. as if it's a built-in function).
An interesting lesson to be learned: if you have subroutines for your subroutines, within a program, do not define them within the subroutine, but rather define them within the main program.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox