Author Topic: Cursor Rotate  (Read 17781 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Cursor Rotate
« Reply #15 on: September 17, 2015, 01:27:37 PM »
@ Lee:
I find it strange that you use (trans) for the UCSXDIR but not for the block rotation. Or am I missing something?

I transform the UCSXDIR to be relative to the active UCS plane, and the code makes the assumption that the block resides in a plane parallel to the UCS plane - or have I missed your point?
No, but I did not make that assumption.

I think the code must make such an assumption since rotation is a planar operation, and so a compound rotation of the UCS and a block residing in another plane would either be meaningless or would need to be projected to the UCS plane.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Cursor Rotate
« Reply #16 on: September 17, 2015, 01:52:25 PM »
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. )
« Last Edit: September 20, 2015, 03:44:34 PM by Lee Mac »

novice

  • Guest
Re: Cursor Rotate
« Reply #17 on: September 17, 2015, 02:10:48 PM »
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.                         (setq a (+ a (cdr (assoc 50 (entget b)))))
  26.                     )
  27.                     (not (setvar 'snapang (- a x)))
  28.                 )
  29.                 (   (princ "\nIncompatible object selected."))
  30.             )
  31.         )
  32.     )
  33.     (princ)
  34. )

Solves the block issue perfectly, and the circle/arc issue. In a perfect world this would combine with ronjonp's code, which neatly handled mtext.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Cursor Rotate
« Reply #18 on: September 17, 2015, 05:29:33 PM »
Solves the block issue perfectly, and the circle/arc issue. In a perfect world this would combine with ronjonp's code, which neatly handled mtext.

My code should also work with MText (and nested MText), just pick a point on the MText to select it.

RGUS

  • Newt
  • Posts: 106
Re: Cursor Rotate
« Reply #19 on: September 17, 2015, 11:51:15 PM »
Solves the block issue perfectly, and the circle/arc issue. In a perfect world this would combine with ronjonp's code, which neatly handled mtext.

My code should also work with MText (and nested MText), just pick a point on the MText to select it.

Perfect Lee... but then what code of yours isn't.
Is there a way to snap to dimension lines as well...

Excellent, excellent coding.

novice

  • Guest
Re: Cursor Rotate
« Reply #20 on: September 18, 2015, 12:09:17 PM »
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.

novice

  • Guest
Re: Cursor Rotate
« Reply #21 on: September 18, 2015, 12:15:29 PM »
DWG file attached. The block this routine doesn't seem to work on is labeled "BLOCK1 (UNROTATED)".
As you say: the block is not rotated (rotation=0.0) therefore the function should set the SNAPANG to 0.0, which it does. The fact that the block represents a rotated element is not relevant to the function.

I hope it's clear that I'm a novice! I'm not sure how to integrate your code into the main code. I mean, I assume what you're saying is that the code you offered should fix this problem?
No my suggestion won't fix the problem. Lee's code has incorporated this already. You are confused by the rotation of the content of the block as opposed to the rotation of the block itself.

Just now realized what you were saying here. Yes, I misspoke. I meant that the code didn't work as I desired when a block wasn't rotated, but the selected nested object was. Anyway, this is all fixed up now.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Cursor Rotate
« Reply #22 on: September 19, 2015, 09:37:13 AM »
Perfect Lee... but then what code of yours isn't.

Excellent, excellent coding.

Thank you RGUS - that's very kind of you to say  :-)

Is there a way to snap to dimension lines as well...

The current code should already allow you to snap to dimension lines (please see the demonstration below).

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:


RGUS

  • Newt
  • Posts: 106
Re: Cursor Rotate
« Reply #23 on: September 20, 2015, 08:21:29 AM »
Hmmmm... I see by your example Lee it does work for dimensions, I must have some system variable or such set to stop this from happening for me. It's almost as if the cursor snaps but to a radian angle not a degree angle. I'll have a little play and see what happens.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Cursor Rotate
« Reply #24 on: September 20, 2015, 08:48:33 AM »
Hmmmm... I see by your example Lee it does work for dimensions, I must have some system variable or such set to stop this from happening for me. It's almost as if the cursor snaps but to a radian angle not a degree angle. I'll have a little play and see what happens.

Could you upload a sample drawing?

RGUS

  • Newt
  • Posts: 106
Re: Cursor Rotate
« Reply #25 on: September 20, 2015, 02:34:21 PM »
Hmmmm... I see by your example Lee it does work for dimensions, I must have some system variable or such set to stop this from happening for me. It's almost as if the cursor snaps but to a radian angle not a degree angle. I'll have a little play and see what happens.

Could you upload a sample drawing?

Sample drawing attached...

lamarn

  • Swamp Rat
  • Posts: 636
Re: Cursor Rotate
« Reply #26 on: September 20, 2015, 03:33:08 PM »
Is there a method to set current ucs (x,y) also according to the setvar snapangle with it?
Design is something you should do with both hands. My 2d hand , my 3d hand ..

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Cursor Rotate
« Reply #27 on: September 20, 2015, 03:44:54 PM »
Hmmmm... I see by your example Lee it does work for dimensions, I must have some system variable or such set to stop this from happening for me. It's almost as if the cursor snaps but to a radian angle not a degree angle. I'll have a little play and see what happens.

Could you upload a sample drawing?

Sample drawing attached...

Thanks RGUS - please try the updated code above.  :-)

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Cursor Rotate
« Reply #28 on: September 20, 2015, 03:52:20 PM »
Is there a method to set current ucs (x,y) also according to the setvar snapangle with it?

If the UCS is rotated to match the angle, SNAPANG will be set to 0.0 (since this is defined relative to the active UCS).
« Last Edit: September 20, 2015, 04:21:10 PM by Lee Mac »

RGUS

  • Newt
  • Posts: 106
Re: Cursor Rotate
« Reply #29 on: September 20, 2015, 04:18:16 PM »
Hmmmm... I see by your example Lee it does work for dimensions, I must have some system variable or such set to stop this from happening for me. It's almost as if the cursor snaps but to a radian angle not a degree angle. I'll have a little play and see what happens.

Could you upload a sample drawing?

Sample drawing attached...

Thanks RGUS - please try the updated code above.  :-)

Brilliant Lee... perfect! Thanks man.