Author Topic: Intercepting command prompt entries, suggestions?  (Read 3523 times)

0 Members and 1 Guest are viewing this topic.

matthewj

  • Newt
  • Posts: 42
  • Vanilla
Intercepting command prompt entries, suggestions?
« on: March 17, 2010, 02:00:02 AM »
All knowing swamp....
I'm looking for a starting point.  I've got this idea for a transparent unit converter that I want to code, but I'm not sure where to start.  The program would allow users to transparently enter alternate units in their drawing.  e.g. If drawing in inches, you could enter 1mm and it would convert the 1mm to the equivalent inch measurement & input the result.

My thought is to listen to the command prompt, and when a keyword is invoked (say mm, or m or parsecs...) an event would be triggered (a lisp converter) that intercepts the entry and replaces it with the calculated value.

I'm looking forward to coding this, but I'm not sure where to start.  Is there an reactor that listens to entries at the command line?  I haven't found any yet, but my eyesight isn't that good.  ;-)  Any and all suggestions are welcome.  Thanks much.

matthewj

  • Newt
  • Posts: 42
  • Vanilla
Re: Intercepting command prompt entries, suggestions?
« Reply #1 on: March 18, 2010, 07:55:10 PM »
This makes me a sad panda.  So I gather this is either this is too easy to comment on or too hard?

Thanks anyways, I'll continue my search.  If I figure something out (and its not mind numbingly obvious) I'll let you guys know.

pkohut

  • Guest
Re: Intercepting command prompt entries, suggestions?
« Reply #2 on: March 18, 2010, 08:08:30 PM »
This makes me a sad panda.  So I gather this is either this is too easy to comment on or too hard?

Thanks anyways, I'll continue my search.  If I figure something out (and its not mind numbingly obvious) I'll let you guys know.

No disrespect, but you posted this in a VBA forum which I would venture a guess is of little interest to most programmers here.  You would be better served if posting is made again in the lisp forums.  Also, give the post time to gel with the users.  Many of the programmers have busy day jobs, and may even sleep, so let you question gel for a couple days.  Finally if nobody answers, it's probably because nobody is interested.

Might I also suggest that you get the parsing code written first, then worry about how to make it interact with the command line, which is easy to do.  If you have something to show first, others are more than willing to help.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Intercepting command prompt entries, suggestions?
« Reply #3 on: March 18, 2010, 10:15:48 PM »
To add to Pauls comments.

Did you know that VBA support MAY not be usable in future releases of AutoCAD ?
... and is currently running at greatly reduced efficiency if installed on a 64 bit OS using AutoCAD. ??

If you are developing for VBA  consider the potential longevity of your code.

//-------------
Considering the functionality you want :
I've never considered that functionality and can't help, sorry.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

matthewj

  • Newt
  • Posts: 42
  • Vanilla
Re: Intercepting command prompt entries, suggestions?
« Reply #4 on: March 18, 2010, 10:33:06 PM »
Thanks, I meant no disrespect myself, I think sad pandas are funny.  I was looking to move this post to the LISP forum this morning, but to no avail.  Is it possible to get this thread moved?

Below is a rough approximation of the code; I'm reticent to get too specific until I know how to intercept the command line.

Code: [Select]
;Transparent Unit Converter
;Pseudo-code (lispy)

;cli_interceptor is always running
(defun cli_interceptor ()

(setq units_keywords `("km" "m" "mm" "cm" "mi" "ft" "yd"))

(if (member CLI_COMMAND units_keywords)
(trans_conversion (cli_value cli_unit))
(CLI_COMMAND <falls thru to cli>)
)
)

;transparent conversion routine does simple conversions
(defun trans_conversion ( value unit / )
<simple conversion routines>
(result <falls thru to cli>)
)

Serge J. Gianolla

  • Guest
Re: Intercepting command prompt entries, suggestions?
« Reply #5 on: March 19, 2010, 01:13:34 AM »
I know you want to code it, but isn't what the units conversion does inside the QC [Quick Calculator]? Do you need to re-invent the wheel? 8-)

Willie

  • Swamp Rat
  • Posts: 958
  • Going nowhere slowly
Re: Intercepting command prompt entries, suggestions?
« Reply #6 on: March 19, 2010, 01:52:30 AM »
I use 'cal for transparent calculations.
« Last Edit: March 19, 2010, 01:58:48 AM by Willie »
Soli Deo Gloria | Qui Audet Adipiscitur
Windows 8  64-bit Enterprise | Civil 3D 2015 and 2016| ArcGIS 10.1
Yogi Berra : "I'd give my right arm to be ambidextrous."

matthewj

  • Newt
  • Posts: 42
  • Vanilla
Re: Intercepting command prompt entries, suggestions?
« Reply #7 on: March 19, 2010, 02:28:02 AM »
I know you want to code it, but isn't what the units conversion does inside the QC [Quick Calculator]?...

Its true, I do really want to code it.  This idea is actually what got me started in lisp - its high time I tackled it.  :-D

IIRC quickcalc requires you to stop and focus on converting, and then resume your drafting.  I'm looking to use alternate units natively, without having to interrupt my flow.  Also, the general framework wouldn't be restricted to unit conversions.  These implicit commands might be another useful method for triggering scripts, lisps & such.

johnm

  • Guest
Re: Intercepting command prompt entries, suggestions?
« Reply #8 on: March 21, 2010, 02:57:02 PM »
I also looked into writing a similar program awhile back and after a lot of trial and error I found that there is no way to achieve this in lisp. Well there might be a way but it I have not found it. There is just no access to the command line. I even looked into going outside AutoCAD to see about intercepting the keyboard input to the computer but it was way over my head but could be done with C++. The main issue is that a lisp routine and a AutoCAD command cannot run simultaneously. Example: when you start the line command that program has focus and if you use a command reactor the only choice is :vlr-commandwillstart then a call to the grread function to get keyboard input. The problem is that the callback is called before the command actually starts so any input is no good and when your callback function finished then the line command will actually start.
If AutoCAD had a command line reactor that would be great.
Good luck

VovKa

  • Water Moccasin
  • Posts: 1617
  • Ukraine
Re: Intercepting command prompt entries, suggestions?
« Reply #9 on: March 21, 2010, 07:32:54 PM »
this is not what you are looking for, but
Code: [Select]
(defun c:cv (/ val)
  (setq val (strcase (getstring ">> Value: ")))
  (cond ((cvunit (atof val) (vl-string-left-trim "0123456789." val) "inch"))
(val)
  )
)
this is the simplest example
you can call it transparently during any command via 'cv
all you have to do is to type 4 extra characters