### Author Topic: Cursor Rotate  (Read 7662 times)

0 Members and 1 Guest are viewing this topic.

#### Dave M ##### Re: Cursor Rotate
« Reply #45 on: September 24, 2015, 07:11:04 PM »
Lee,
I am a Civil 3D user, and when doing road design sometimes I will use vanilla line work when laying out road profiles, vertical curves and the like.
So, if I want to draw a line at a 2% grade, I set the snapang variable by getting the arctangent of 0.02.
Here is an example:
Command: SNAPANG
Enter new value for SNAPANG <0.0000>: 'cal
>>>> Expression: atan(.02)
Resuming SETVAR command.
Enter new value for SNAPANG <0.0000>: 1.1457628381751
Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox ##### Re: Cursor Rotate
« Reply #46 on: September 25, 2015, 05:41:49 AM »
Shoot, doesn't work on a mirrored block - a block where the lines which are members of the block are at an angle and the block is inserted without any rotation, but the block has been mirrored.

In the attached drawing, the diagonal member on the right is a nested block, inserted without rotation. The diagonal member on the left is a mirrored copy of the other. So the Lisp routine works as expected when clicking on the diagonal member on the right, but not for the diagonal member on the left.

Lee,
I am a Civil 3D user, and when doing road design sometimes I will use vanilla line work when laying out road profiles, vertical curves and the like.
So, if I want to draw a line at a 2% grade, I set the snapang variable by getting the arctangent of 0.02.
Here is an example:
Command: SNAPANG
Enter new value for SNAPANG <0.0000>: 'cal
>>>> Expression: atan(.02)
Resuming SETVAR command.
Enter new value for SNAPANG <0.0000>: 1.1457628381751

Thank you both for the feedback - please try the following code instead:

Code - Auto/Visual Lisp: [Select]
1. (defun c:rsa ( / a e f l o u v x z )
2.     (setq z (trans '(0 0 1) 1 0 t)
3.           x (angle '(0 0) (trans (getvar 'ucsxdir) 0 z t))
4.     )
5.         (cond
6.             (   (or (null u) (= "Object" u))
8.                 (setq u (cond ((getpoint "\nPick point on object [Angle/Grade/Cancel] <Angle>: ")) ("Angle")))
9.                 (cond
10.                     (   (= 'str (type u)))
11.                     (   (null (setq l (nentselp u)))
12.                         (princ "\nPoint does not lie on an object.")
13.                     )
14.                     (   (or (and (setq e (car l)
15.                                        o (vlax-ename->vla-object e)
16.                                  )
17.                                  (vlax-property-available-p o 'rotation)
18.                                  (setq a (vla-get-rotation o))
19.                             )
20.                             (and (not (vl-catch-all-error-p (setq u (vl-catch-all-apply 'vlax-curve-getclosestpointto (list e (trans u 1 0))))))
21.                                  (setq a (angle '(0 0) (trans (vlax-curve-getfirstderiv e (vlax-curve-getparamatpoint e u)) 0 z)))
22.                             )
23.                         )
25.                             (setq f (lambda ( x ) (reverse (cdr (reverse x))))
26.                                   v (list (cos a) (sin a) 0.0)
27.                                   v (mapcar '(lambda ( x ) (apply '+ (mapcar '* (f x) v))) (f (caddr l)))
28.                                   a (angle '(0 0) (trans v 0 z))
29.                             )
30.                         )
31.                         (not (setvar 'snapang (- a x)))
32.                     )
33.                     (   (princ "\nIncompatible object selected."))
34.                 )
35.             )
36.             (   (= "Angle" u)
38.                 (if (numberp (setq u (getangle "\nSpecify angle [Object/Grade/Cancel] <Object>: ")))
39.                     (not (setvar 'snapang u))
40.                     t
41.                 )
42.             )
44.                 (initget "Object Angle Cancel")
45.                 (if (numberp (setq u (getreal "\nSpecify grade (%) [Object/Angle/Cancel] <Object>: ")))
46.                     (not (setvar 'snapang (atan (/ u 100.0))))
47.                     t
48.                 )
49.             )
50.             (   (= "Cancel" u) nil)
51.         )
52.     )
53.     (princ)
54. )

#### novice

• Guest ##### Re: Cursor Rotate
« Reply #47 on: September 25, 2015, 07:03:05 AM »
Unbelievable, Lee. What a great Lisp routine! You make it look so easy.

Quote from: Lee Mac
I didn't realize this sort of program would prove so useful to so many members...

It's the cat's meow. ##### Re: Cursor Rotate
« Reply #48 on: September 25, 2015, 08:58:10 AM »
Thank you novice, I'm glad you like the final code #### Dave M ##### Re: Cursor Rotate
« Reply #49 on: September 25, 2015, 11:10:35 AM »
Lee,
Stellar job as usual.  I envy your abilities!  I'll be adding this to my quiver.  Here's a routine I wrote a long time ago.  I use it all the time.  Maybe it can be a benefit to others.

Thanks again,

Dave
Code: [Select]
`;ROTATES CROSSHAIRS TO BE ORTHOGRAPHIC WITH CURRENT VIEW;FUNCTION TO CHANGE RADIANS TO DEGREES(DEFUN RTD (A) (/ (* A 180.0) pi));MAIN PROGRAM(DEFUN C:RXH (/ A B C)  (SETQ A (GETVAR "VIEWTWIST")) ;GET VIEWTWIST  (SETQ B (RTD A))  ;CONVERT VIEWTWIST FROM RADIANS TO DEGREES  (SETQ C (- 360 B))  ;SUBTRACT VIEWTWIST FROM 360  (COMMAND "SNAPANG" C)  ;SET SNAP ANGLE TO BE ORTHOGRAPHIC TO VIEW)`
Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox

#### RGUS

• Newt
• Posts: 97 ##### Re: Cursor Rotate
« Reply #50 on: October 04, 2017, 12:19:39 AM »
Shoot, doesn't work on a mirrored block - a block where the lines which are members of the block are at an angle and the block is inserted without any rotation, but the block has been mirrored.

In the attached drawing, the diagonal member on the right is a nested block, inserted without rotation. The diagonal member on the left is a mirrored copy of the other. So the Lisp routine works as expected when clicking on the diagonal member on the right, but not for the diagonal member on the left.

Lee,
I am a Civil 3D user, and when doing road design sometimes I will use vanilla line work when laying out road profiles, vertical curves and the like.
So, if I want to draw a line at a 2% grade, I set the snapang variable by getting the arctangent of 0.02.
Here is an example:
Command: SNAPANG
Enter new value for SNAPANG <0.0000>: 'cal
>>>> Expression: atan(.02)
Resuming SETVAR command.
Enter new value for SNAPANG <0.0000>: 1.1457628381751

Thank you both for the feedback - please try the following code instead:

Code - Auto/Visual Lisp: [Select]
1. (defun c:rsa ( / a e f l o u v x z )
2.     (setq z (trans '(0 0 1) 1 0 t)
3.           x (angle '(0 0) (trans (getvar 'ucsxdir) 0 z t))
4.     )
5.         (cond
6.             (   (or (null u) (= "Object" u))
8.                 (setq u (cond ((getpoint "\nPick point on object [Angle/Grade/Cancel] <Angle>: ")) ("Angle")))
9.                 (cond
10.                     (   (= 'str (type u)))
11.                     (   (null (setq l (nentselp u)))
12.                         (princ "\nPoint does not lie on an object.")
13.                     )
14.                     (   (or (and (setq e (car l)
15.                                        o (vlax-ename->vla-object e)
16.                                  )
17.                                  (vlax-property-available-p o 'rotation)
18.                                  (setq a (vla-get-rotation o))
19.                             )
20.                             (and (not (vl-catch-all-error-p (setq u (vl-catch-all-apply 'vlax-curve-getclosestpointto (list e (trans u 1 0))))))
21.                                  (setq a (angle '(0 0) (trans (vlax-curve-getfirstderiv e (vlax-curve-getparamatpoint e u)) 0 z)))
22.                             )
23.                         )
25.                             (setq f (lambda ( x ) (reverse (cdr (reverse x))))
26.                                   v (list (cos a) (sin a) 0.0)
27.                                   v (mapcar '(lambda ( x ) (apply '+ (mapcar '* (f x) v))) (f (caddr l)))
28.                                   a (angle '(0 0) (trans v 0 z))
29.                             )
30.                         )
31.                         (not (setvar 'snapang (- a x)))
32.                     )
33.                     (   (princ "\nIncompatible object selected."))
34.                 )
35.             )
36.             (   (= "Angle" u)
38.                 (if (numberp (setq u (getangle "\nSpecify angle [Object/Grade/Cancel] <Object>: ")))
39.                     (not (setvar 'snapang u))
40.                     t
41.                 )
42.             )
44.                 (initget "Object Angle Cancel")
45.                 (if (numberp (setq u (getreal "\nSpecify grade (%) [Object/Angle/Cancel] <Object>: ")))
46.                     (not (setvar 'snapang (atan (/ u 100.0))))
47.                     t
48.                 )
49.             )
50.             (   (= "Cancel" u) nil)
51.         )
52.     )
53.     (princ)
54. )

Is there a way we can use entsel or something similar to select the entity rather than the crosshairs being visible at the time of selection. It sort of feels funny having them on screen when being ask to select something.

But... nonetheless, you are the master.
Thanks for great code.

Oh just found it by changing the line:

(setq u (cond ((getpoint "\nPick point on object [Angle/Grade/Cancel] <Angle>: ")) ("Angle")))

to:

(setq u (cond ((cadr (entsel "\nPick point on object [Angle/Grade/Cancel] <Angle>: "))) ("Angle")))

That did it.

« Last Edit: October 04, 2017, 12:57:16 AM by RGUS »

#### fools

• Newt
• Posts: 72
• China ##### Re: Cursor Rotate
« Reply #51 on: October 04, 2017, 09:26:53 AM »
Can't work correctly when selecting a polyline in a block.
Good good study , day day up . Sorry about my Chinglish .