Change default command behaviour, eg always Rotate Reference instead of just Rot

Change default command behaviour, eg always Rotate Reference instead of just Rot

Haider_of_Sweden
Collaborator Collaborator
2,911 Views
12 Replies
Message 1 of 13

Change default command behaviour, eg always Rotate Reference instead of just Rot

Haider_of_Sweden
Collaborator
Collaborator

How can I change default behaviours of commands, for example

 

Rotate command: I mostly use rotate reference instead of just rotate. Therefore I would like to have reference as default.


Scale command: Same as above, mostly scale reference.

 

Mirror command: I mostly use pick erase source object 'Y'. Therefore I would like to have the default set as 'Y' instead of 'N'.

 

 

I thought editing the Program Parameters (PGP) file might be the solution, but it wasn't. How can this be solved?

0 Likes
Accepted solutions (3)
2,912 Views
12 Replies
Replies (12)
Message 2 of 13

David_W_Koch
Mentor
Mentor
Accepted solution

You could create an AutoLISP function for a given AutoCAD command that has the same name as the AutoCAD command, duplicates the AutoCAD prompts and feeds the results to the AutoCAD command, tweaking any prompts/defaults to suit your needs.  You can UNDEFINE the AutoCAD command and load the AutoLISP function to replace it.  If you put the UNDEFINE and loading statements in the first acaddoc.lsp file found on your search path, the altered version of the command will be swapped in every time you open a file.

 

If you use the AutoLISP Command function to feed the prompt results, be certain to precede the name of the AutoCAD command with a period (".") so that AutoCAD uses the actual command definition, and does not try to use the redefined AutoLISP version.


David Koch
AutoCAD Architecture and Revit User
Blog | LinkedIn
EESignature

Message 3 of 13

dbroad
Mentor
Mentor
Accepted solution

As David has said, put something like this in an acaddoc.lsp file or have it loaded as part of your startup suite.  The file will need to be in a trusted folder.

 

;;--Rotate relative command substitution

(COMMAND "_.undefine" "_rotate")
(defun c:rotate
(/ ss)
(AND (SETQ ss
(IF
(NOT (AND (= 1 (GETVAR "pickfirst")) (SETQ ss (SSGET "i"))))
(PROGN (SSSETFIRST) (SSGET))
ss
)
)
(SETQ bp (GETPOINT "\nSpecify base point: "))
(COMMAND "_.rotate" ss "" bp "r")
)
(PRINC)
)

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 4 of 13

scot-65
Advisor
Advisor
Accepted solution
I will slightly disagree about redefining a built-in command.
Instead, create a utility that suits your needs and assign it a unique keystroke
(meaning cross-reference to the PGP and cancel out the declaration in the PGP).
Once the keystroke is defined as a LSP, one can populate the UI areas in the CUIX.

For Rotate Reference, I have the keystroke "RTR".
As part of this utility, ORTHOMODE is checked for and turned off.

"SCR" ?

"MRR" ?

One should consider custom utilities to have at least a 3-character name.
The 1- and 2-character keystrokes should be reserved for the PGP.

???

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

0 Likes
Message 5 of 13

Haider_of_Sweden
Collaborator
Collaborator

Thank you very much @David_W_Koch , @dbroad and @scot-65 

 

It totally makes sense to create new custom commands that do what I need them to do.

 

@scot-65 , I think I agree with you to keep the original commands non-UNDEFINE:ed so that I can access the original ones by typing their full names any time I need.

In your opinion, should I name the lisp-commands something short, or should I use short aliases to point them to the lisp-command?

0 Likes
Message 6 of 13

Haider_of_Sweden
Collaborator
Collaborator

@dbroad wrote:

;;--Rotate relative command substitution

(COMMAND "_.undefine" "_rotate")
(defun c:rotate
(/ ss)
(AND (SETQ ss
(IF
(NOT (AND (= 1 (GETVAR "pickfirst")) (SETQ ss (SSGET "i"))))
(PROGN (SSSETFIRST) (SSGET))
ss
)
)
(SETQ bp (GETPOINT "\nSpecify base point: "))
(COMMAND "_.rotate" ss "" bp "r")
)
(PRINC)
)


Thank you for your script. Could you please help me develop it further?

Currently it works like this:

  1. run command
  2. pick object (if its picked already, we encounter a problem which I will mention below)
  3. pick basepoint
  4. Since the LISP picked R for me already, it now expects me to pick a basepoint again.
  5. pick endpoint and destination

At 4, I would like the basepoint to be the same as the point picked at 3.

 

Also, we had this problem when the object is already selected has vertices. Often, you want to pick where the edges are and hence, there is a vertex.

Can we disable/hide vertices during the command?

0 Likes
Message 7 of 13

ВeekeeCZ
Consultant
Consultant

@Haider_of_Sweden wrote:

..., should I name the lisp-commands something short, or should I use short aliases to point them to the lisp-command?


I use a lot of shortcuts, inc. reference rotate, see below. For these simple LISPs I prefer to use just short names directly.

 

But for more complex LISPs I prefer to use long more descriptive names with short aliases. With searchable command-line it's easier to find it even if you don't know the exact name. 

 

My version is: /really old and simple/

(defun c:O () ; Rotate with 3 points
  (command "_select" pause)
  (command "_rotate" "_p" "" pause "_r" "@" pause pause)
  (princ)
)

 

0 Likes
Message 8 of 13

dbroad
Mentor
Mentor

The reason that I didn't assume that your base point would be the first point of the reference angle is that quite often in my work, the reference angle pick points do not include the base point.  Entering the @ symbol will pick the point if that helps or you could just add "@" after the "r" in my command.

(COMMAND "_.undefine" "_rotate")
(DEFUN c:rotate	(/ ss)
  (AND (SETQ ss
	      (IF
		(NOT (AND (= 1 (GETVAR "pickfirst")) (SETQ ss (SSGET "i"))))
		 (PROGN (SSSETFIRST) (SSGET))
		 (PROGN (SSSETFIRST) ss)
		 )
	     )
       (SETQ bp (GETPOINT "\nSpecify base point: "))
       (COMMAND "_.rotate" ss "" bp "r" "@")
       )
  (PRINC)
  )
Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 9 of 13

scot-65
Advisor
Advisor
@Haider_of_Sweden

One method to consider:

The custom lisp commands shall be 3 or more characters - (defun c:ABC (/)...
Why?
Reserve 1- and 2-character commands for the PGP -or- AutoCAD commands
with one option selected (I call this "enhanced PGP"). For your situation,
you wish to use the one option method, but logically Rotate Reference would
lend itself to be command "RTR" or possibly "RR".

The file name should be long-descriptive and contain the command name.
Why?
If one compresses into a FAS, the command name may not be apparent on load.

Example:
LLISP is the command I use to load a lisp located in the current directory.
The file name is "LoadLisp_LLISP.fas
One can also do "LLISP_LoadLisp.fas
In acaddoc.lsp [or eq.], declare the load (I do not use autoload, but look into it)

(defun c:LLISP () (if (load "LoadLisp_LLISP" nil) (c:LLISP)) (princ)) ;load a LSP/FAS file

If one wishes to shorten the keystroke, consider this:
(defun c:LL () (c:LLISP)) ;alias for LLISP

Once keystroke declarations are added, it is easy to populate the UI areas
inside the CUIX for those who struggle typing with their thumbs on the
sacred desktop keyboard.

🙂

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

0 Likes
Message 10 of 13

hughecchapman
Enthusiast
Enthusiast

I feel the same way about the rotate command. The way it's set up as default really isn't conducive to fluid & efficient workflow imo. I find having to redefine the centre of rotation after specifying r for rotate reference particularly annoying/ unnecessary. So thanks for the various scripts all.

 

With mirror, ideally I'd like to lose the "delete source object yes/no" prompt after executing the command. I'd like to be able to customise "delete source object yes/no" in the command line before executing the mirror command, with the default set to "delete source object>no". I'd like autocad to hold my preference from last use of the command so if for some reason I need to execute a run of mirror commands deleting source objects this will be enabled with optimal efficiency and minimum clicks.  Is this possible in autocad? It is in Rhino...

 

TIA

0 Likes
Message 11 of 13

ВeekeeCZ
Consultant
Consultant

@hughecchapman wrote:

With mirror, ideally I'd like to lose the "delete source object yes/no" prompt after executing the command. I'd like to be able to customise "delete source object yes/no" in the command line before executing the mirror command, with the default set to "delete source object>no". I'd like autocad to hold my preference from last use of the command so if for some reason I need to execute a run of mirror commands deleting source objects this will be enabled with optimal efficiency and minimum clicks.  Is this possible in autocad? It is in Rhino...

 

TIA


 

Thanks God it's possible in Rhino... 

 

(defun c:Mirror+ ( / s p)
  
  (princ "\nMIRROR: ")
  (if (and (setq s (ssget "_:L"))
	   (progn
	     (while (progn
		      (princ (strcat "\nCurrent setting of 'Erase source objects?': " (if *mr-del* "Yes" "No")))
		      (initget "Erase")
		      (setq p (getpoint (strcat "\nSpecify first point of mirror line [Erase toggle]: ")))
		      (if (= 'STR (type p))
			(progn (setq *mr-del* (not *mr-del*)) t))))
	     p)
	   )
    (command "_.mirror" s "" "_non" p pause (if *mr-del* "Yes" "No")))
  (princ)
  )

 

0 Likes
Message 12 of 13

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

....
(or *mr-del* (setq *mr-del* nil)) ....

That seems extraneous to me.  If the variable exists, (or) is satisifed, so do nothing.  If it doesn't exist, set it to nil, that is, if it doesn't exist, make it not exist.  But if it doesn't exist [if the first argument to the (or) function returns nil], then it's already nil, so there's no need to set it that way.  [EDIT:  The above has now been removed from the code in Message 11.]

Kent Cooper, AIA
Message 13 of 13

Kent1Cooper
Consultant
Consultant

@Haider_of_Sweden wrote:

....

@scot-65 , I think I agree with you to keep the original commands non-UNDEFINE:ed so that I can access the original ones by typing their full names any time I need.

....


I know this topic has "moved on," but just for people's information:  You can still use the original command definitions, even if they have been UNDEFINEd, so it's not important to avoid doing that.  Type in the command name or even just its command alias preceded by a period/decimal, which forces the use of the native command definition, getting around any undefinition/redefinition you may have defined.

Kent Cooper, AIA
0 Likes