PDA

View Full Version : RT - Rotate crosshairs Lisp routine.



JimWebster
2nd Feb 2005, 08:14 pm
The below is a Lisp routine that I have used since I started using AutoCAD some 5 years ago
with AutoCAD v14. I am now up to using AutoCAD 2005 and the routine still works fine.
I do not know who the author is, but I want to thank them for a great routine!

What I like most about this one, is that by selecting "Entity" one can simply mouse click
on an object line that is at the desired angle in order to select the angle of the crosshairs.

Executing the routine and entering a value of "0" will return the crosshairs to normal.


;;*********************************************
;;
;; Created: Author Unknown.
;;
;;
;**************NEW ROTATE**********************
;
;;; Command Line Syntax: RT
;;; Use this routine to change the angle of the crosshairs,
;;; by clicking on an object that is at the desired angle or
;;; by entering an angle of degrees at the command line.
;;; A positive number turns the crosshairs counter-clockwise.
;;; A negative number turns the crosshairs clockwise.
;
(defun c:rt ( / r e p1 p2)
(graphscr)
(initget "Entity")
(setq r
&#40;getangle "\nSnap rotation angle/<Entity>&#58; "&#41;&#41;
&#40;cond
&#40; &#40;numberp r&#41;
&#40;setvar "snapang" r&#41;&#41;
&#40; &#40;and &#40;or &#40;not r&#41; &#40;eq r "Entity"&#41;&#41;
&#40;setq e &#40;entsel&#41;&#41;
&#40;setq p1 &#40;osnap &#40;cadr e&#41; "qui,end"&#41;&#41;
&#40;setq p2 &#40;osnap &#40;cadr e&#41; "qui,mid"&#41;&#41;&#41;
&#40;setvar "snapang" &#40;angle p1 p2&#41;&#41;&#41;
&#40;t &#40;princ "\nInvalid selection."&#41;&#41;&#41;
&#40;princ&#41;
&#41;
;;;
;;;

Mark Thomas
2nd Feb 2005, 09:54 pm
Just by looking at the way it's formatted, I'd say Michael Puckett wrote that. Could be way off though. 8)

JimWebster
3rd Feb 2005, 05:23 pm
Everything above and below the actual code is my input. It is an old habit from when I used
to program in PC assembly language. I did this as a hobby, but for quite a few years.

No matter how clear everything seems at the moment, go back and look over code a few days
later and you will have forgetten most everything. And in gleaming over many web sites lately
in trying to learn Lisp programming, I am finding that most Lisp files are devoid of even the
most basic description. Specifically the "Syntax", which is what you enter at the command line
to run the routine or program, as well as any switches (additional command line
parameters allowed).

Mark Thomas
3rd Feb 2005, 05:45 pm
Yes, I was speaking in terms of the actual code.

Wozza
17th Feb 2005, 05:44 am
Jim,

Nice routine. I spent some time myself trying to get one to work when selecting entities within an xref. A couple of hours and dozens of lines of code later, I was still struggling with it when someone in the office, who knew diddly squat about lisp, suggested the following:

'SNAP R 0,0;PER;

JimWebster
1st Mar 2005, 09:59 pm
Wozza,

Well, jiminy crickets!

With a SNAP;OFF; at the end it produces the same results, but I cannot get this to work in a key macro.
It seems that a macro will not wait for the user input after PER. Do you know how to remedy this?

Sorry to be so late responding, but I have been out of town for over 2 weeks.

Mr T
1st Mar 2005, 10:01 pm
I know little of LISP :oops: but......

Keymacros are easier with VBA ?

I have done a few in CORELdraw but you don't
do any code at all. 8)

Nick

JimWebster
1st Mar 2005, 10:10 pm
Mr T,

I may be using the wrong terminology, as well. I think that AutoCAD refers to these as "Accelerator Keys". The below is a template of sorts that I added to my PERSONAL.MNS file that is read by AutoCAD each time that it is loaded. I was using the F11 function key to test what Wozza was telling us about.



***ACCELERATORS
// F1 default = AutoCAD help. &#40;Do not change.&#41;
// F2 default = Text window. &#40;Do not change.&#41;
// F3 default = Osnap ON/OFF. &#40;Do not change.&#41;
// F4 default = Tablet ON/OFF.
// &#91;"F4"&#93;rt
// F5 default = ISOPLANE command.
// &#91;"F5"&#93;mid
// F6 default = Coords ON/OFF.
// &#91;"F6"&#93;cen
// F7 default = Grid ON/OFF.
// &#91;"F7"&#93;per
// F8 default = Ortho ON/OFF. &#40;Do not change.&#41;
// F9 default = Snap ON/OFF.
// &#91;"F9"&#93;duh
// F10 default = Polar ON/OFF.
// &#91;"F10"&#93;nea
// F11 default = Object Snap Tracking ON/OFF.
// &#91;"F11"&#93;ins
&#91;"F11"&#93;SNAP R 0,0;PER;
// F12 default = Nothing.
&#91;"F12"&#93;rt
// Other allowable key combinations are&#58; &#91;CONTROL+"F?"&#93;
//
// NOTE&#58; If a CONTROL+"letter" combo is not listed below,
// then it is advisable not to use it.
// CONTROL+"D" default = Coords ON/OFF.
// &#91;CONTROL+"D"&#93;_erase
// CONTROL+"E" default = ISOPLANE command.
// &#91;CONTROL+"E"&#93;_erase
// CONTROL+"G" default = Grid ON/OFF.
// &#91;CONTROL+"G"&#93;rt
// CONTROL+"I" default = Nothing.
// &#91;CONTROL+"I"&#93;rt
// CONTROL+"R" default = Nothing.
// &#91;CONTROL+"R"&#93;rc
// CONTROL+"T" default = Tablet ON/OFF.
// &#91;CONTROL+"T"&#93;_trim
// CONTROL+"U" default = Polar ON/OFF.
// &#91;CONTROL+"U"&#93;_undo
// CONTROL+"W" default = Object Snap Tracking ON/OFF.
// &#91;CONTROL+"W"&#93;rt
// Other allowable key combinations are&#58; &#91;CONTROL+SHIFT+"letter"&#93;
//
// The below are all CONTROL+DIRECTIONAL_ARROW.
// &#91;CONTROL+UP&#93;rt
// &#91;CONTROL+DOWN&#93;rt
// &#91;CONTROL+LEFT&#93;rt
// &#91;CONTROL+RIGHT&#93;rt
//
// &#91;NUMPAD0&#93; thru &#91;NAMPAD9&#93; are 0 thru 9 of the mumeric keypad.
// &#91;NUMPAD0&#93;_REDRAW
//
[/code]

CarlB
1st Mar 2005, 10:29 pm
Jim,
Regarding not waiting for user input after the "per" or "off", try removing the last semicolon. AutoCAD automatically inserts a space after the macro code. If this fails, I saw this in help regarding special characters:

^Z
Null character that suppresses the automatic addition of SPACEBAR at the end of a menu item

Mr T
1st Mar 2005, 10:31 pm
I may be using the wrong terminology, as well. I think that AutoCAD refers to these as "Accelerator Keys". The below is a template of sorts that I added to my PERSONAL.MNS file that is read by AutoCAD each time that it is loaded. I was using the F11 function key to test what Wozza was telling us about.

Ah.... eh.....right.... I'm lost......

Any good links or sites with some VBA for autocad ???

Nick

Wozza
16th Mar 2005, 06:44 am
Jim,

Likewise sorry for the late reply, but I think CarlB has solved the problem.

If your macro ends with a space after the last semi colon, which obviously isn't immediately apparent, then it's the equivalent of a double 'Enter' which will exit the macro before you get to select anything.

Check to see if you've left a space at the end and delete it if you have. It should then work OK.

To check the validity of the macro, you could run it item by item at the command line:

SNAP - Enter
R - Enter
0,0 - Enter
PER - Enter

The macro will then pause for user input.

JimWebster
16th Mar 2005, 03:01 pm
Wozza,

The problem I encountered was attempting to add SNAP;OFF; to the end.
What happens is that AutoCAD attempts to use SNAP as the user input for PER.