Author Topic: Calling for user command input  (Read 4150 times)

0 Members and 1 Guest are viewing this topic.

Cuddles

  • Guest
Calling for user command input
« on: December 04, 2014, 05:20:42 PM »
Hello to all who read  :-)

Just a quick note before I explain my topic - I'm a bit of a novice / intermediate with Lisp.

My question as follows:

Is it possible (i assume so) to call a command using lisp in which the user chooses the command i.e line, pline, xline, circle etc... and not have the command built into the code???
So in the code, instead of having (command "line"....) or (command "circle" .....), can the code wait for the user to pick a command (on screen) i.e. line, pline, xline from the standard AutoCAD toolbars and then continue executing???

Hope this makes sense.

I'm sure this a simple task but have searched other posts and the net in general, all to no avail.

All help will be greatly appreciated.

Cuddles  :laugh:

ribarm

  • Gator
  • Posts: 3287
  • Marko Ribar, architect
Re: Calling for user command input
« Reply #1 on: December 04, 2014, 05:40:29 PM »
Hope this makes sense.
Cuddles  :laugh:

No it does not make sense...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

danallen

  • Guest
Re: Calling for user command input
« Reply #2 on: December 04, 2014, 06:10:28 PM »
This may be possible with custom toolbars - not the standard acad because they send escape command to cancel current commands. The custom toolbars can avoid this, the text is just entered at command line. For example the object entity snap toolbar does not send escape command.


Code: [Select]
: (getstring)
_center"_center"

You could write code that asked for string input, then hit buttons on your custom toolbar.

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Calling for user command input
« Reply #3 on: December 04, 2014, 06:18:37 PM »
Alternatively, you could prompt the user at the command-line, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:getcommand ( / arg cmd )
  2.     (while
  3.         (not
  4.             (or (= "" (setq cmd (getstring "\nEnter a command: ")))
  5.                 (setq arg (getcname cmd))
  6.             )
  7.         )
  8.         (princ (strcat "\n\"" cmd "\" is not a valid command."))
  9.     )
  10.     (if arg (command arg))
  11.     (princ)
  12. )

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Calling for user command input
« Reply #4 on: December 04, 2014, 07:53:54 PM »
I have to ask the desired result. I can't imagine wanting to do much of the same for circle or line, etcetera, aside from osnap overrides.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Calling for user command input
« Reply #5 on: December 04, 2014, 08:05:17 PM »
Cuddles
Welcome to the Swamp.

Taking control of a command requires that you redirect the user by changing the command call to your routine.
Or with the use of Reactors or as Dan said.

None are foolproof & reactors are a last resort for me.

What is it you hope to accomplish?
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.

Cuddles

  • Guest
Re: Calling for user command input
« Reply #6 on: December 04, 2014, 09:49:42 PM »
Hello All,

Thanks for the suggestions and support so far - much appreciated.

In response to the question "what is the desired result" from CAB and alanjt - the desired result is essentially to allow the user to select a layer (or create a layer if not present in the active drawing) and to prompt the user for a drawing command (line, polyline, arc etc...) in which to draw (whatever it may be) on the particular layer.

I'm trying a slightly different approach to Lee Mac's "Layer Director" - although very useful, is not quite fulfilling my requirements in terms of my drawing style. I'm currently avoiding reactors at the moment as i'm not well clued-up on there operation, but will investigate this non-the-less.

Lee - thanks for the snippet of code. Looks promising but unfortunately have not yet had time to test. Will report back when tested.

Thanks again for the welcome and support.

Cheers,
Cuddles

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Calling for user command input
« Reply #7 on: December 04, 2014, 09:54:54 PM »


Quote
..... is not quite fulfilling my requirements in terms of my drawing style.

Exactly what is your drawing style ??
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.

jsyoung81

  • Guest
Re: Calling for user command input
« Reply #8 on: December 05, 2014, 05:13:09 PM »
Code: [Select]

(initget 1 "Line Circle..."); this is where you would enter your list of commands that you want
(setq x
(getkword "\nChoose Command:...[Line/Circle/Rectangle]")
);END SETQ
(COMMAND X)

Or Something to that effect I think is what you are looking for. If you want each one to be on a differant layer then use if statements. Also would help if at the start of your LISP you searched the Layer Table and added in any layers that you need.

However this still does require using the command bar


danallen

  • Guest
Re: Calling for user command input
« Reply #9 on: December 05, 2014, 06:23:22 PM »
In response to the question "what is the desired result" from CAB and alanjt - the desired result is essentially to allow the user to select a layer (or create a layer if not present in the active drawing) and to prompt the user for a drawing command (line, polyline, arc etc...) in which to draw (whatever it may be) on the particular layer.

I think you still need to provide more info for us to help you. What you describe could easily be done with toolbar to select current layer (or command LAYMCUR if I recall correctly - I'm on Bricscad), then use the standard toolbars to draw. You don't describe any other custom actions.

Cuddles

  • Guest
Re: Calling for user command input
« Reply #10 on: December 08, 2014, 06:25:20 AM »
Hello All,

Thanks for the suggestions and comments so far - appreciated.

Lee - have tested your code and works a treat - thank you.

Cuddles

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Calling for user command input
« Reply #11 on: December 08, 2014, 12:14:41 PM »
Lee - have tested your code and works a treat - thank you.

You're most welcome Cuddles.

Though, I am curious as to why my Layer Director was not deemed suitable for this task -
What is the drawing style that you are referring to?

Lee

Cuddles

  • Guest
Re: Calling for user command input
« Reply #12 on: December 09, 2014, 05:00:03 AM »
Hello Lee,

I'll try to keep this short.

The "drawing style" I refer is a little hard to explain but it is essentially the way in which my work colleagues draw (should have corrected myself earlier - not the way I draw!).
Many of my colleagues use basic commands to perform their tasks (the term "basic" can vary from person to person), obviously resulting in low productivity. I have discussed the benefits of using Auto-lisp functions with them, such as your layer director, among others, to automate drawing processes and increase productivity. I have provided these functions to them but I see they're rarely used. They obviously like to keep to old ways - a real shame! Trying my best to get them to change.

One of my colleagues (whom is catching on to the idea of the benefits of auto lisp functions) suggested a slightly different approach to auto-layering if you will, which I didn't particularly agree with, but have taken on the task to create this auto-layering system for him regardless (it's good practice for me too  :-)).

Take note:
Quote
I'm trying a slightly different approach to Lee Mac's "Layer Director" - although very useful, is not quite fulfilling my requirements in terms of my drawing style.
"my requirements" - by that I mean my colleagues requirements.

Personally myself I have no issues in using your layer director and use it to great effect at both work and home.

Hope this description helps and sorry for the misunderstanding.

Thanks,

Cuddles

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Calling for user command input
« Reply #13 on: December 09, 2014, 05:51:14 AM »
... suggested a slightly different approach to auto-layering ...
Could you explain a bit about this? I.e. what the user does and when/how the layer is changed / set.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12916
  • London, England
Re: Calling for user command input
« Reply #14 on: December 09, 2014, 02:41:48 PM »
Thank you for the response Cuddles - though, I'm rather puzzled by this statement:

I have discussed the benefits of using Auto-lisp functions with them, such as your layer director, among others, to automate drawing processes and increase productivity. I have provided these functions to them but I see they're rarely used.

Just to confirm, utilities such as my Layer Director require no user input and don't need to be run manually - the application will be enabled automatically upon opening a drawing and uses a reactor which runs silently in the background to automatically set the appropriate layer when a command is issued.

Therefore, are you saying that your users are intentionally disabling the utility?
And if so, why?

As Irnéb has requested, I would also be curious to understand more about the alternative approach to automatically configuring the layer for certain commands, as I can't immediately think of a method which would be less intrusive than the method used by my Layer Director.

Lee