One thing I noticed is it gave me a wrong angle when I clicked on a block that had been rotated.The SNAPANG is expressed relative to the current UCS. So this can occur if you are not working in the WCS.
(angle '(0.0 0.0 0.0) (getvar 'ucsxdir))
One thing I noticed is it gave me a wrong angle when I clicked on a block that had been rotated.The SNAPANG is expressed relative to the current UCS. So this can occur if you are not working in the WCS.
To get the rotation angle of the current UCS:Code: [Select](angle '(0.0 0.0 0.0) (getvar 'ucsxdir))
I assume that this is a 2D only utility.
Maybe post an example drawing. I can't replicate the circle & block issue you're seeing.
Maybe this will resolve the issues?Code - Auto/Visual Lisp: [Select]
(cond nil ) ) ) ) ) ( (vl-catch-all-error-p (setq p (vl-catch-all-apply 'vlax-curve-getclosestpointto (list e (trans p 1 0))))) ) ( (not (setvar 'snapang (- (angle '(0 0) (trans (vlax-curve-getfirstderiv e (vlax-curve-getparamatpoint e p)) 0 z)) a)))) ) ) ) )
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.
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.
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.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?
@ Lee:
I find it strange that you use (trans) for the UCSXDIR but not for the block rotation. Or am I missing something?
No, but I did not make that assumption.@ 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.@ 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?
Try the following code instead:Code - Auto/Visual Lisp: [Select]
) (cond nil ) ) ) ) (and (not (vl-catch-all-error-p (setq p (vl-catch-all-apply 'vlax-curve-getclosestpointto (list e (trans p 1 0)))))) ) ) ) ) ) ) ) )
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.
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.
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.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?
Perfect Lee... but then what code of yours isn't.
Excellent, excellent coding.
Is there a way to snap to dimension lines as well...
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.
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.
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?
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...
Is there a method to set current ucs (x,y) also according to the setvar snapangle with it?
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. :-)
(not (command "ucs" "z" (- a x)))
(not (setvar 'snapang (- a x)))
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:
(http://lee-mac.com/swamp/snapangdemo.gif)
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.
Try the following code instead:Code - Auto/Visual Lisp: [Select]
) (cond nil ) ) ) ) (and (not (vl-catch-all-error-p (setq p (vl-catch-all-apply 'vlax-curve-getclosestpointto (list e (trans p 1 0)))))) ) ) ) ) ) ) ) ) )
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]
) (cond ( (= "Cancel" a) nil) ) t ) ) ( (= "Cancel" p) nil) ) ) ) (and (not (vl-catch-all-error-p (setq p (vl-catch-all-apply 'vlax-curve-getclosestpointto (list e (trans p 1 0)))))) ) ) ) ) ) ) ) )
I'm not sure why you would want to set OSMODE to 0 however?
Like it !
(snapang or ucs wise..)
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
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.
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
I didn't realize this sort of program would prove so useful to so many members...
;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
)
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]
) (cond (cond ) ) ) (and (not (vl-catch-all-error-p (setq u (vl-catch-all-apply 'vlax-curve-getclosestpointto (list e (trans u 1 0)))))) ) ) ) ) ) ) ) ( (= "Angle" u) t ) ) ( (= "Grade" u) t ) ) ( (= "Cancel" u) nil) ) ) )