Re-define built-in commands?

Re-define built-in commands?

ynemchev
Contributor Contributor
1,976 Views
11 Replies
Message 1 of 12

Re-define built-in commands?

ynemchev
Contributor
Contributor

Hello all, 

 

Recently, I have been thinking of the built-in commands in AutoCAD and how they are connected to the lisp "commands". I trying to find any coding behind all predefined commands in AutoCAD and would like to kindly ask if there is a way to re-define any built-in command, such as line, polyline, rectangle, etc.?

 

Is it possible, for example, to redefine command named "line" to create instead of a line, a completely different object? In other words, can AutoCAD's "source-code" can be revised/modified?

 

0 Likes
1,977 Views
11 Replies
Replies (11)
Message 2 of 12

paullimapa
Mentor
Mentor

In some ways, yes you can but I would not do that.

For example, you can use AutoCAD's UNDEFINE command and enter LINE as the command to Undefine.

Then use AutoLISP code to define a new set of commands when the command LINE is entered:

(defun c:line ()(command"_.CIRCLE"))

Now when the LINE command is entered, AutoCAD will start the CIRCLE command.

 

But you can still go back to the original command by preceding the command with a period ie:

.LINE

 

Or you can use the REDEFINE command and enter LINE to Redefine the command back.

But you see how things can really get confusing if you start swapping standard commands like LINE with CIRCLE.

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales | Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 12

Kent1Cooper
Consultant
Consultant

I agree with @paullimapa, but just to make it a little clearer, what he describes is not  revising/modifying the source code -- that's all still there, through which you have the option to use the native command, regardless of any Undefining/New-defining you have done, by prefixing the command name with a period.  It's just sort-of "overpowering" the native definition of a command.  I've sometimes done that, but usually using the native version of a command within my new definition of its name  [for example, an Undefining of Offset and a new definition of it that incorporates the option to change the Offset distance within  the command, rather than having to end it and start it again to give a new distance].

Kent Cooper, AIA
0 Likes
Message 4 of 12

ActivistInvestor
Mentor
Mentor

@ynemchev wrote:

Hello all, 

 

Recently, I have been thinking of the built-in commands in AutoCAD and how they are connected to the lisp "commands". I trying to find any coding behind all predefined commands in AutoCAD and would like to kindly ask if there is a way to re-define any built-in command, such as line, polyline, rectangle, etc.?

 

Is it possible, for example, to redefine command named "line" to create instead of a line, a completely different object? In other words, can AutoCAD's "source-code" can be revised/modified?

 


Replacing built-in commands is probably not wise, because any LISP scripting that fails to use a leading period to use the built-in version of the command will fail, because a command that's defined in LISP cannot be scripted using the LISP (command) function. Only built-in commands, commands written in ObjectARX, or LISP commands that are defined using (vlax-add-cmd) can be scripted via the (command) function.

0 Likes
Message 5 of 12

john.uhden
Mentor
Mentor

You have had three of the sagest people in this forum advise you of the problems associated with undefining a native AutoCAD command.  It's sorta like if you were a carpenter with helpers and you decide to define a screwdriver as a hammer.  So when you ask for a hammer, do you want to be handed a hammer or a screwdriver?  Leave their names alone.  If you want a specialized tool, then invent it and give it a unique name, like maybe a "hamdriver."  That way, when you ask for a hammer, you get a hammer, etc.

John F. Uhden

0 Likes
Message 6 of 12

scot-65
Advisor
Advisor
Before reactors were born, I undefined qsave and wrote
a maintenance program which included sections such as
purge, audit, etc... to execute at the first occurrence of
the native command. At the end of the program came
the .QSAVE. This was done primarily for the "mousers"
who preferred to use the UI elements while ignoring the
keyboard.

Your other option is to tinker with the PGP.
Example: command "LIN" will start "CIRCLE".

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 7 of 12

john.uhden
Mentor
Mentor

I remember those ambitiously noble days, or maybe that's nobly ambitious.  Alas, my guys and gals preferred the keyboard.  There was little I could do to trick them.  I think maybe I taught them too much.  They're all gone now.  No, not dead, just retired after my old company was found guilty of "Pay to play."  Luckily my cardiologist wrote a letter to get my old boss out of jail time with a suspended sentence due to cardiac concerns.  He got me out of a 4 month jury duty too.  I love that guy.

John F. Uhden

0 Likes
Message 8 of 12

ynemchev
Contributor
Contributor

Thanks for this clarification. Thank you for all replies. 

 

Really, what I am trying to achieve in the long run is to somehow revise the source code *if possible, modifying variables that became somehow invalid over the years, such as the flatland command.

If it is invalid, cant you redefine it? Back in the days, it did the job and worked quite well... 

 

Quote from *Dillon, Matt:

 

"Flatland is a "sugarpill" system variable that came out in R10, when AutoCAD
became "fully 3D". It was intended for those that didn't want to deal with
3D. Set it to 1 and AutoCAD was 2D (I kind of always figured that if you
just didn't DRAW in 3D, you were working in 2D, but somebody decided there
had to be a sysvar for it).

Why it's even still around is beyond me. It's not listed in the command
reference and, as you noted, 1 is invalid."

 

Do you believe it is possible to use AutoCAD R10 's source code to redefine it in the new version? As of now I ave been using a lisp that can do the job very good, but really, cant you redefine it once again?

 

Thank you again!

 

0 Likes
Message 9 of 12

ActivistInvestor
Mentor
Mentor

@ynemchev wrote:

Thanks for this clarification. Thank you for all replies. 

 

Really, what I am trying to achieve in the long run is to somehow revise the source code *if possible, modifying variables that became somehow invalid over the years, such as the flatland command.

If it is invalid, cant you redefine it? Back in the days, it did the job and worked quite well... 

 

Quote from *Dillon, Matt:

 

"Flatland is a "sugarpill" system variable that came out in R10, when AutoCAD
became "fully 3D". It was intended for those that didn't want to deal with
3D. Set it to 1 and AutoCAD was 2D (I kind of always figured that if you
just didn't DRAW in 3D, you were working in 2D, but somebody decided there
had to be a sysvar for it).

Why it's even still around is beyond me. It's not listed in the command
reference and, as you noted, 1 is invalid."

 

Do you believe it is possible to use AutoCAD R10 's source code to redefine it in the new version? As of now I ave been using a lisp that can do the job very good, but really, cant you redefine it once again?

 

Thank you again!

 


Actually, FLATLAND was pretty-useful even in 3D drawings. It was used to project osnapped points in 3D space into the XY plane.  One of my earliest ARX libraries was specifically designed to restore the functionality in subsequent product releases, and Autodesk soon followed suit with OSNAPZ.

 

The reason variables and commands like FLATLAND are left in the product even after they've been neutered and don't do anything, is to avoid breaking scripting.

 

 

 

0 Likes
Message 10 of 12

roland.r71
Collaborator
Collaborator

You can redefine all you want. BUT you cannot access the original source code.

 

You can replace the existing function with your own, but not modify the existing code with your own.

 

So it's not a matter of simply adjusting the existing code into something new, you need to work it all out, from scratch (or use existing code from somebody else)

0 Likes
Message 11 of 12

ynemchev
Contributor
Contributor

Thank you again. Just as what I thought. Will try to redefine and readjust common commands, such as line, pline and extend and see how it goes. Talking about FLATLAND command, as of now, will probably stick to the lisp that does the job quite well, but would greatly appreciate any help if someone knows how to make the the FLATLAND variable accept a value of 1...

0 Likes
Message 12 of 12

roland.r71
Collaborator
Collaborator

As far as i can tell, there is no way to get FLATLAND to 'work' again. It has been hardcoded to 0 since R11.

 

The only alternative would seem to be to set all Z values to 0.0 by using lisp, or maybe use "Flatten" (Express Tools)

 

- FLATTEN creates a 2D representation of selected objects and projects them onto the current viewing plane. FLATTEN results in 2D objects that retain their original layers, linetypes, colors and object types where possible. You can use FLATTEN to create a 2D drawing from a 3D model, or you can use it to force the thickness and elevations of selected objects to 0.

0 Likes