Creating a new command without using an alias

Creating a new command without using an alias

jack1594
Explorer Explorer
1,284 Views
5 Replies
Message 1 of 6

Creating a new command without using an alias

jack1594
Explorer
Explorer

Hello all!

 

So I use an LSP. Routine which allows for any command such as "Pline" to automatically go on its own layer, with all the layer settings pre-set; layer name, colour, plot visibility, linetype etc...

 

So my 'dream' is to be able to type a command name i choose such as "PLSWS" (Polyline surface water sewer) and this be able to create a polyline. My LSP routine will then pick up on this command and generate its style automatically to suit our offices standard sewer style system.

 

Unfortunately the LSP. routine doesn't allow for Alias's and so its as if i need to create an exact copy of the Polyline command and all its settings, just change the name that triggers it. 

 

I hope this makes sense and thanks for any help!

0 Likes
Accepted solutions (1)
1,285 Views
5 Replies
Replies (5)
Message 2 of 6

dbroad
Mentor
Mentor

This isn't really the forum for AutoLisp. That said, changing layers during a command is a pretty simple AutoLisp task and you haven't really described why you can't do what you want.  IMO though, it is generally best to keep all settings to bylayer and be populating various layers with your content that each control the appearance.

 

One approach to automatic layer changing is to wrap your lisp program inside another. The main program controls the  layering. The subcommand is called with a (c:xxxx) form rather than (command "xxxx").  This approach is more difficult to use where the lisp is used as a front end for another command if the desire is also to switch back to the original layer after the command is finished.

 

A second approach is to use reactors to toggle layers.  Reactors are a complex topic not suitable for a forum post but they can accomplish things not possible otherwise.

Architect, Registered NC, VA, SC, & GA.
Message 3 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@jack1594 wrote:

.... my 'dream' is to be able to type a command name i choose such as "PLSWS" (Polyline surface water sewer) and this be able to create a polyline. My LSP routine will then pick up on this command and generate its style automatically to suit our offices standard sewer style system.

....


 

I'm not positive I understand completely, but it sounds like very common practice in AutoLisp command definitions.  In very simplest terms:

 

(defun C:PLSWS ()

  (setvar 'clayer "YourSurfaceSewerLayerName")

  (command "_.pline")

)

 

That would set the Layer, start a Pline command, and leave you in the Pline command to continue with.  It's also very common to have that kind of thing save the current Layer [whatever it is] at the beginning, change the current Layer, let you do stuff, and then reset the previous Layer, if you need that added.

 

Maybe what you're after would be clearer if you post your routine so we can see what it does, and figure out how that might relate to "alias" command names.

Kent Cooper, AIA
Message 4 of 6

john.uhden
Mentor
Mentor

I do this all the time...

(defun c:PlineSomething () ...)

 

Now I don't really want to type "PlineSomething"

so I create an "alias"...

(defun c: PLS ()(c:PlineSomething))

 

That way, not the entire code is duplicated, but you are creating a very tiny new command function that invokes the bigger function.

John F. Uhden

Message 5 of 6

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

I do this all the time...

(defun c:PlineSomething () ...)

Now I don't really want to type "PlineSomething" so I create an "alias"...

(defun c: PLS ()(c:PlineSomething))

.... creating a very tiny new command function that invokes the bigger function.


 

For what it's worth:  The way I typically handle the relationship between a longer more descriptive something and a shorter command name is to name the AutoLisp file  PlineSomething.lsp, but call the command name  inside it just C:PLS.  I don't bother with giving a command a name that I'm pretty sure I'll never  type in, in its entirety, and it doesn't seem worth the overhead to me to define a short command name that does nothing but call a long command name, so I just use a short name, and leave it to the file name to be more descriptive.

Kent Cooper, AIA
Message 6 of 6

john.uhden
Mentor
Mentor
Very commendable.

I got into my habit from when I used to sell packages of lisp programs and
provided my own CV_ALIAS program for users to change the command names to
their liking.

John F. Uhden