TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Cuddles on December 04, 2014, 05:20:42 PM

Title: Calling for user command input
Post by: Cuddles 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:
Title: Re: Calling for user command input
Post by: ribarm on December 04, 2014, 05:40:29 PM
Hope this makes sense.
Cuddles  :laugh:

No it does not make sense...
Title: Re: Calling for user command input
Post by: danallen 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.
Title: Re: Calling for user command input
Post by: Lee Mac 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. )
Title: Re: Calling for user command input
Post by: alanjt 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.
Title: Re: Calling for user command input
Post by: CAB 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?
Title: Re: Calling for user command input
Post by: Cuddles 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
Title: Re: Calling for user command input
Post by: Kerry 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 ??
Title: Re: Calling for user command input
Post by: jsyoung81 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

Title: Re: Calling for user command input
Post by: danallen 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.
Title: Re: Calling for user command input
Post by: Cuddles 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
Title: Re: Calling for user command input
Post by: Lee Mac 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
Title: Re: Calling for user command input
Post by: Cuddles 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
Title: Re: Calling for user command input
Post by: irneb 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.
Title: Re: Calling for user command input
Post by: Lee Mac 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

Title: Re: Calling for user command input
Post by: ronjonp on December 09, 2014, 02:47:46 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.

...
...
..., as I can't immediately think of a method which would be less intrusive than the method used by my Layer Director.

Lee
X2
Title: Re: Calling for user command input
Post by: Cuddles on December 10, 2014, 04:04:08 AM
Hello Lee,

You are correct. Some colleagues are intentionally disabling the layer director, whilst others use fine but for only a few layers (3-4 at most).
One of the reasons for a different approach is because of the following:

1: Due to the number of layers used in my office (office standard layers), many of the layers generally need to be drawn with the same or similar commands i.e line, pline, xline, arc and so forth. So for example, if the "line" command is picked by the user, within your layer director, only the first layer that requires a line command to execute will be created. So therefore, other layers down the "tree" which require the line command to be invoked and created, will essentially never be created because of the way in which the layer director reads the layers entered by the user.

2: From point 1, Below is a snippet of what the layers would look like in the layer director (there are some 20 odd standard layers used in my office):

Code: [Select]
("[PX]LINE" "TCL00 bold" 4 "Continuous" 60 1 )
("[PX]LINE,LINE"         "TCL01 thick" 6 "Continuous" 20 1 )
("LINE" "TCL02 thin" 4 "Continuous" 9 1 )
("[P]LINE" "TCL03 centre" 4 "Centre" 9 1 )
("[DM]TEXT,TEXT"         "TCL06 text" 7 "Continuous" 20 1 )
("DIMLINEAR"         "TCL07 dim"         8 "Continuous" 20 1 )

Looking at line 3, this line will never be invoked because the layer director picks the 2nd line first, and invokes this. Same for "Pline" in lines 1 and 2.
Therefore, to draw on layer TCL02 thin, I would have to enter this myself into the autoCAD layer tree and then draw on that layer. Hence the layer director is limited when a lot of layers are used which require the same command to implement.

For objects such as text and dimensions, which for me are all on there respective layers (dims on dim layer, text on text layer), the layer director is perfect for this. It's just for multiple layers requiring the same command where the issue lies.

The idea of using a toolbar with layer buttons is to be able to select the layer to draw on, a single click, and you are then prompted to pick the command in which to draw on that layer i.e line, pline etc... Once the drawing is done and the drawing command is exited, the programme will then restore back to the previous layer (same as the layer director). This gives the user a little more flexibility to choose the layer upon which to draw.

I have attached a PDF of the layers used by my office. Please feel free to experiment yourself and see if you have the same result.

I do apologise for being nit-picky and no disrespect to you, but I hope all this makes sense.

Cuddles.