Author Topic: Cursor Rotate  (Read 3864 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 11793
  • AutoCAD 2015 Windows 7 London, England
Re: Cursor Rotate
« Reply #30 on: September 20, 2015, 04:20:55 pm »
No worries!  :-)

lamarn

  • Swamp Rat
  • Posts: 527
Re: Cursor Rotate
« Reply #31 on: September 20, 2015, 04:50:53 pm »
Not a wonderboy in coding. Apparently will not work..

Code: [Select]
(not (command "ucs" "z" (- a x)))

Code: [Select]
(not (setvar 'snapang (- a x)))


               
Design is something you should do with both hands. My 2d hand , my 3d hand ..

Lee Mac

  • Seagull
  • Posts: 11793
  • AutoCAD 2015 Windows 7 London, England
Re: Cursor Rotate
« Reply #32 on: September 20, 2015, 05:12:45 pm »
Try:
Code - Auto/Visual Lisp: [Select]
  1. (command "_.ucs" "_z" (angtos (- a x)))

novice

  • Guest
Re: Cursor Rotate
« Reply #33 on: September 21, 2015, 09:31:02 am »

Hmm, not sure why it doesn't work for me on mtext. Not at work today, Monday I'll retry and also see if it works on dimension strings.

The code seems to perform well for me with the MText in your sample drawing, and also with dimension text and extension lines:



Ok, this probably sounds ridiculous, but I had to get the hang of how to pick mtext using your code. It works fine. It's just that there's no pickbox so it doesn't feel like I'm picking anything. So I always clicked on the "insert" or "node" object snap marker. But clicking on these markers does nothing - it does not pick the mtext.

That said, I forgot until now to try it with a rotated dimension. Doesn't seem to work. When I pick my rotated dimension, the snap angle changes but it changes to something unexpected.

Same sample drawing as before attached, but with a rotated dimension in it this time.

ronjonp

  • Needs a day job
  • Posts: 6326
Re: Cursor Rotate
« Reply #34 on: September 21, 2015, 09:36:05 am »
I just tested with your drawing & it worked fine for me  :?

Windows 10 x64 - AutoCAD /C3D 2018

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 11793
  • AutoCAD 2015 Windows 7 London, England
Re: Cursor Rotate
« Reply #35 on: September 21, 2015, 09:36:50 am »
Ok, this probably sounds ridiculous, but I had to get the hang of how to pick mtext using your code. It works fine. It's just that there's no pickbox so it doesn't feel like I'm picking anything. So I always clicked on the "insert" or "node" object snap marker. But clicking on these markers does nothing - it does not pick the mtext.

You can't have the best of both options without a separate prompt: you requested an accurate point specification, therefore the crosshairs must be used to allow Object Snap; if you want to use a pickbox as per the previous code, you will need to forgo the accurate point specification and rely on the nearest point to the center of the pickbox.

That said, I forgot until now to try it with a rotated dimension. Doesn't seem to work. When I pick my rotated dimension, the snap angle changes but it changes to something unexpected.

Have you tried the updated code?
(following the comments from RGUS above?)

novice

  • Guest
Re: Cursor Rotate
« Reply #36 on: September 23, 2015, 09:20:22 am »
Ok, I finally found the updated code and it works great. Everything works great. Thank you everyone, Lee especially of course, for working on this code.

Here it is:

Try the following code instead:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:rsa ( / a e l o p 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.    (while
  6.        (progn
  7.            (cond
  8.                (   (null (setq p (getpoint "\nPick point on object <exit>: ")))
  9.                    nil
  10.                )
  11.                (   (null (setq l (nentselp p)))
  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 p (vl-catch-all-apply 'vlax-curve-getclosestpointto (list e (trans p 1 0))))))
  21.                             (setq a (angle '(0 0) (trans (vlax-curve-getfirstderiv e (vlax-curve-getparamatpoint e p)) 0 z)))
  22.                        )
  23.                    )
  24.                    (foreach b (cadddr l)
  25.                        (if (= "INSERT" (cdr (assoc 0 (setq b (entget b)))))
  26.                            (setq a (+ a (cdr (assoc 50 b))))
  27.                        )
  28.                    )
  29.                    (not (setvar 'snapang (- a x)))
  30.                )
  31.                (   (princ "\nIncompatible object selected."))
  32.            )
  33.        )
  34.    )
  35.    (princ)
  36. )

Lee Mac

  • Seagull
  • Posts: 11793
  • AutoCAD 2015 Windows 7 London, England
Re: Cursor Rotate
« Reply #37 on: September 23, 2015, 09:29:56 am »
Excellent to hear novice - I'm glad the code is working well for you.

Thank you for your gratitude  :-)

RGUS

  • Newt
  • Posts: 81
Re: Cursor Rotate
« Reply #38 on: September 23, 2015, 08:31:44 pm »
So handy this routine... just occasionally I pick the wrong segment of a polyline in an XREF and the cursor snaps to the angle of the first segment of the polyline...  a small problem that certainly does not detract me from using this great routine Lee. Again thanks very, very much.

I have added a few line to your routine that allow me to pick points or enter directly a desired angle rather than look for an entity that matches the snap_angle I need.

(defun rtd (A) (* 180.0 (/ A pi)))

and then when I exit your code, I've placed this at the end of it.

(setvar "osmode" 512)
(setq pick_snap (getangle "\nAngle: "))
(command "snapang" (rtd pick_snap))
(setvar "osmode" 0)

Not pretty but allows me to pick any other angle.

I hope you don't mind.


Lee Mac

  • Seagull
  • Posts: 11793
  • AutoCAD 2015 Windows 7 London, England
Re: Cursor Rotate
« Reply #39 on: September 24, 2015, 07:29:14 am »
Not at all, I'm delighted you find the code so useful - perhaps the option could be incorporated in the following way:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:rsa ( / a e l o p 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.    (while
  6.        (cond
  7.            (   (= "Cancel" a) nil)
  8.            (   (progn
  9.                    (initget "Angle Cancel")
  10.                    (or (null (setq p (getpoint "\nPick point on object [Angle/Cancel] <Angle>: "))) (= "Angle" p))
  11.                )
  12.                (initget "Object Cancel")
  13.                (if (numberp (setq a (getangle "Specify angle [Object/Cancel] <Object>: ")))
  14.                    (not (setvar 'snapang a))
  15.                    t
  16.                )
  17.            )
  18.            (   (= "Cancel" p) nil)
  19.            (   (null (setq l (nentselp p)))
  20.                (princ "\nPoint does not lie on an object.")
  21.            )
  22.            (   (or (and (setq e (car l)
  23.                               o (vlax-ename->vla-object e)
  24.                         )
  25.                         (vlax-property-available-p o 'rotation)
  26.                         (setq a (vla-get-rotation o))
  27.                    )
  28.                    (and (not (vl-catch-all-error-p (setq p (vl-catch-all-apply 'vlax-curve-getclosestpointto (list e (trans p 1 0))))))
  29.                         (setq a (angle '(0 0) (trans (vlax-curve-getfirstderiv e (vlax-curve-getparamatpoint e p)) 0 z)))
  30.                    )
  31.                )
  32.                (foreach b (cadddr l)
  33.                    (if (= "INSERT" (cdr (assoc 0 (setq b (entget b)))))
  34.                        (setq a (+ a (cdr (assoc 50 b))))
  35.                    )
  36.                )
  37.                (not (setvar 'snapang (- a x)))
  38.            )
  39.            (   (princ "\nIncompatible object selected."))
  40.        )
  41.    )
  42.    (princ)
  43. )

I'm not sure why you would want to set OSMODE to 0 however?

lamarn

  • Swamp Rat
  • Posts: 527
Re: Cursor Rotate
« Reply #40 on: September 24, 2015, 09:06:59 am »
Like it !
(snapang or ucs wise..)

Design is something you should do with both hands. My 2d hand , my 3d hand ..

Dave M

  • Newt
  • Posts: 145
Re: Cursor Rotate
« Reply #41 on: September 24, 2015, 02:41:05 pm »
Great routine!  Would it be difficult to add the ability to set the angle to a specific grade in decimal format?  I usually just calculate the angle and set the snapang variable manually
Civil 3D 2016 - Microstation SS4 - Windows 7 - Dropbox

RGUS

  • Newt
  • Posts: 81
Re: Cursor Rotate
« Reply #42 on: September 24, 2015, 04:08:48 pm »
Not at all, I'm delighted you find the code so useful - perhaps the option could be incorporated in the following way:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:rsa ( / a e l o p 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.    (while
  6.        (cond
  7.            (   (= "Cancel" a) nil)
  8.            (   (progn
  9.                    (initget "Angle Cancel")
  10.                    (or (null (setq p (getpoint "\nPick point on object [Angle/Cancel] <Angle>: "))) (= "Angle" p))
  11.                )
  12.                (initget "Object Cancel")
  13.                (if (numberp (setq a (getangle "Specify angle [Object/Cancel] <Object>: ")))
  14.                    (not (setvar 'snapang a))
  15.                    t
  16.                )
  17.            )
  18.            (   (= "Cancel" p) nil)
  19.            (   (null (setq l (nentselp p)))
  20.                (princ "\nPoint does not lie on an object.")
  21.            )
  22.            (   (or (and (setq e (car l)
  23.                               o (vlax-ename->vla-object e)
  24.                         )
  25.                         (vlax-property-available-p o 'rotation)
  26.                         (setq a (vla-get-rotation o))
  27.                    )
  28.                    (and (not (vl-catch-all-error-p (setq p (vl-catch-all-apply 'vlax-curve-getclosestpointto (list e (trans p 1 0))))))
  29.                         (setq a (angle '(0 0) (trans (vlax-curve-getfirstderiv e (vlax-curve-getparamatpoint e p)) 0 z)))
  30.                    )
  31.                )
  32.                (foreach b (cadddr l)
  33.                    (if (= "INSERT" (cdr (assoc 0 (setq b (entget b)))))
  34.                        (setq a (+ a (cdr (assoc 50 b))))
  35.                    )
  36.                )
  37.                (not (setvar 'snapang (- a x)))
  38.            )
  39.            (   (princ "\nIncompatible object selected."))
  40.        )
  41.    )
  42.    (princ)
  43. )

I'm not sure why you would want to set OSMODE to 0 however?

Clever bugger ain't ya... cheers for this little mod Lee.

I normally work with no snaps on, just an old fart from way back that never had snaps in version 1.0 of ACAD... old habits.

Lee Mac

  • Seagull
  • Posts: 11793
  • AutoCAD 2015 Windows 7 London, England
Re: Cursor Rotate
« Reply #43 on: September 24, 2015, 06:07:04 pm »
Like it !
(snapang or ucs wise..)

Thanks!  :-)

Great routine!  Would it be difficult to add the ability to set the angle to a specific grade in decimal format?  I usually just calculate the angle and set the snapang variable manually

Thanks Dave - I didn't realise this sort of program would prove so useful to so many members, personally I've never altered SNAPANG and usually opt to rotate the UCS. As for setting the angle using decimal format, the getangle prompt in the latest modification to the code (accessible by typing 'A' at the first prompt) should accept any form of angular input, returning the equivalent angle in radians to which the SNAPANG system variable is set.

Could you possibly give an example of the typical input you wish to supply to the program?

Clever bugger ain't ya... cheers for this little mod Lee.

No worries RGUS!  :-)

I normally work with no snaps on, just an old fart from way back that never had snaps in version 1.0 of ACAD... old habits.

Personally, I couldn't imagine drafting anything without snaps (unless perhaps considering the grid snap), but each to their own I suppose.

novice

  • Guest
Re: Cursor Rotate
« Reply #44 on: September 24, 2015, 07:04:09 pm »
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.