Engineer_Yasser Posted October 21, 2023 Posted October 21, 2023 How to determine if the selected text is outside the selected arc or at the inner side Quote
Lee Mac Posted October 21, 2023 Posted October 21, 2023 Check whether the distance from the text to the arc center is greater than the arc radius. 1 1 Quote
hosneyalaa Posted October 22, 2023 Posted October 22, 2023 @Engineer_Yasser look at this ;; https://www.cadtutor.net/forum/topic/66203-numbering-along-path/#comment-543810 (if (minusp (sin (- (angle '(0 0 0) vec_pt) (angle '(0 0 0) vec_path)))) (setq tmp_3 (distance tmp_1 %)) (setq tmp_3 (* -1 (distance tmp_1 %))) ) 1 Quote
Engineer_Yasser Posted October 22, 2023 Author Posted October 22, 2023 7 hours ago, Lee Mac said: Check whether the distance from the text to the arc center is greater than the arc radius. Text "5" is supposed to be "Inner side" even it's distance bigger than the Radius , Text "3" is supposed to be "Outer side" even it's distance smaller than the Radius Quote
BIGAL Posted October 22, 2023 Posted October 22, 2023 (edited) A maybe method is to draw a temp line in a direction form the center of the arc changing a few degrees per try, you have a start and end angle in an ARC its built in, so just add a repeat count and a limit on how far to look. If your picking the arc and text even easier as the text to center point angle must fall within the start and end angles. Arc can do some things like save the arc in the opposite direction to what you have drawn. So need a dwg to check. Confirm auto or pick. Edited October 22, 2023 by BIGAL 1 Quote
Engineer_Yasser Posted October 22, 2023 Author Posted October 22, 2023 1 hour ago, hosneyalaa said: @Engineer_Yasser look at this ;; https://www.cadtutor.net/forum/topic/66203-numbering-along-path/#comment-543810 (if (minusp (sin (- (angle '(0 0 0) vec_pt) (angle '(0 0 0) vec_path)))) (setq tmp_3 (distance tmp_1 %)) (setq tmp_3 (* -1 (distance tmp_1 %))) ) Thanks For Reply I think this is a very good solution .. can you make this code more simple (defun c:foo ( / num_path i e c lst) (setq num_path (ssname (ssget (list (cons 0 "ARC"))) 0)) (setq e (ssname (ssget (list (cons 0 "TEXT"))) 0)) (setq c (trans (cdr (assoc 10 (entget e))) e 0)) (setq lst (cons c lst)) (setq lst (mapcar '(lambda (% / tmp_1 tmp_2 vec_pt vec_path tmp_3 ) (setq tmp_1 (vlax-curve-getClosestPointTo num_path %)) (setq tmp_2 (vlax-curve-getParamAtPoint num_path tmp_1)) (setq vec_pt (mapcar '- % tmp_1)) (setq vec_path (vlax-curve-getfirstderiv num_path tmp_2)) (if (minusp (sin (- (angle '(0 0 0) vec_pt) (angle '(0 0 0) vec_path)))) (alert "Outside Arc") (alert "Inside Arc") ) ) lst ) ) ) Quote
Lee Mac Posted October 22, 2023 Posted October 22, 2023 17 hours ago, Engineer_Yasser said: Text "5" is supposed to be "Inner side" even it's distance bigger than the Radius , Text "3" is supposed to be "Outer side" even it's distance smaller than the Radius How can the distance from the arc center to 'Outside' be smaller than the radius? 1 Quote
BIGAL Posted October 22, 2023 Posted October 22, 2023 (edited) A couple of comments, it looks like you are picking an arc and a text then checking, so why not use the text insertion point and arc center point get the angle between these two points and check. If you know the sequence is pick an arc and pick a text then use Enstel, the entsel will give you a point to use in the angle check. Edited October 22, 2023 by BIGAL Quote
Engineer_Yasser Posted October 23, 2023 Author Posted October 23, 2023 8 hours ago, Lee Mac said: How can the distance from the arc center to 'Outside' be smaller than the radius? As i understand same as attached pic .. the text "5" distance is smaller Quote
Engineer_Yasser Posted October 23, 2023 Author Posted October 23, 2023 8 hours ago, BIGAL said: A couple of comments, it looks like you are picking an arc and a text then checking, so why not use the text insertion point and arc center point get the angle between these two points and check. If you know the sequence is pick an arc and pick a text then use Enstel, the entsel will give you a point to use in the angle check. Sorry I'm still a noob in Autolisp... if you have a code I can test it and tell you the result Quote
exceed Posted October 23, 2023 Posted October 23, 2023 (edited) To be sure, it seems necessary to draw extension lines on both sides of the arc as a reference, whether to extend in a 'diagonal line' or 'rocket' or 'circle' shape... and to what extent the boundary line is drawn. I can't imagine a "3" being outside by a distance smaller than the radius of the arc. Edited October 23, 2023 by exceed Quote
Engineer_Yasser Posted October 23, 2023 Author Posted October 23, 2023 (defun c:foo ( / num_path i e c lst) (setq num_path (ssname (ssget (list (cons 0 "ARC"))) 0)) (setq e (ssname (ssget (list (cons 0 "TEXT"))) 0)) (setq c (trans (cdr (assoc 10 (entget e))) e 0)) (setq lst (cons c lst)) (setq lst (mapcar '(lambda (% / tmp_1 tmp_2 vec_pt vec_path tmp_3 ) (setq tmp_1 (vlax-curve-getClosestPointTo num_path %)) (setq tmp_2 (vlax-curve-getParamAtPoint num_path tmp_1)) (setq vec_pt (mapcar '- % tmp_1)) (setq vec_path (vlax-curve-getfirstderiv num_path tmp_2)) (if (minusp (sin (- (angle '(0 0 0) vec_pt) (angle '(0 0 0) vec_path)))) (alert "Outside Arc") (alert "Inside Arc") ) ) lst ) ) ) This Code is working perfectly.. If you can modify it be as simple as possible this will be perfect .. Thanks Sorry I'm still a noob Quote
Lee Mac Posted October 23, 2023 Posted October 23, 2023 3 hours ago, Engineer_Yasser said: As i understand same as attached pic .. the text "5" distance is smaller If the distance from the text to the arc center is less than the arc radius it must be within the arc, by definition. Quote
Steven P Posted October 23, 2023 Posted October 23, 2023 Ahhh, centre of arc (the origin) or the centre of the arc line.... Quote
Steven P Posted October 23, 2023 Posted October 23, 2023 (edited) An alternative method, create a temporary arc line and work out which line the text is closest to.. and so whether the text is inside or outside. Note that 'outside' is if the text would be outside of a circle that the arc is taken from (so a long way inside 2x radius away becomes outside) No error checking on the selection of arc or text (From BigAls suggestion) (defun c:inout ( / MyPoint ent1 vaobj1 dist1 ArcLen1 ent2 vlaobj2 dist2 ArcLen2 InnerDist OuterDist) (setq MyPoint (cdr (assoc 10 (entget (car (entsel "\nSelect Text")))))) ; Selected text insert point (setq vlaobj1 (vlax-ename->vla-object (car (entsel "\nSelect Arc")))) ; Select arc as VLA-Object (setq dist1 (distance MyPoint (vlax-curve-getClosestPointTo vlaobj1 MyPoint T)) ) ;Distance text to arc (setq ArcLen1 (vlax-curve-getDistAtParam vlaobj1 (vlax-curve-getEndParam vlaobj1)) ) ; arc length (vla-Offset vlaobj1 (* ArcLen1 0.001)) ; Create temp line, offset small amount (setq ent2 (entlast)) ; new arc temporary line (setq vlaobj2 (vlax-ename->vla-object ent2)) ; get Arc as VLA-object (setq dist2 (distance MyPoint (vlax-curve-getClosestPointTo vlaobj2 MyPoint T)) ) ;Distance arc 2 to text (setq ArcLen2 (vlax-curve-getDistAtParam vlaobj2 (vlax-curve-getEndParam vlaobj2)) ) ; arc length (entdel ent2) ; delete temporary line ASAP (if (< ArcLen2 ArcLen1) ; Work out inner and outer arcs (setq InnerDist Dist1 OuterDist Dist2) (setq InnerDist Dist2 OuterDist Dist1) ) (if (< InnerDist OuterDist) ; Work out inside / outside (princ "\nOutside") (princ "\nInside") ) (princ) ; End quietly ) Edited October 23, 2023 by Steven P 1 Quote
Steven P Posted October 23, 2023 Posted October 23, 2023 (edited) And this one works is out distance to the arc is greater or less than the distance to the origin of the arc. Noting taken the 'T' away from the vla- get closest line so only looks at the drawn arc (above looked at the circle that the arc was formed from). Works well with arcs up to 180 degree angle (semi-circle), afterwards not always (From Lee Macs suggestion) (defun c:inout ( / MyPoint ent1 vaobj1 dist1 ArcLen1 ent2 vlaobj2 dist2 ArcLen2 InnerDist OuterDist) (setq MyPoint (cdr (assoc 10 (entget (car (entsel "\nSelect Text")))))) ; Selected text insert point (setq ent1 (car (entsel "\nSelect Arc"))) ; Select arc (setq vlaobj1 (vlax-ename->vla-object ent1)) ; Selected arc as VLA-Object (setq dist1 (distance MyPoint (vlax-curve-getClosestPointTo vlaobj1 MyPoint)) ) (setq dist2 (distance (cdr (assoc 10 (entget ent1))) MyPoint )) (setq dist3 (cdr (assoc 40 (entget ent1))) ) ;;Dist 1: Txt to arc ;;Dist 2: Txt to origin ;;Dist 3: Radius (if (and (< Dist1 Dist2) (> Dist2 Dist3) ) ; Work out inside / outside (princ "\nOutside") (princ "\nInside") ) (princ) ; End quietly ) Edited October 23, 2023 by Steven P 1 Quote
hosneyalaa Posted October 23, 2023 Posted October 23, 2023 3 hours ago, Engineer_Yasser said: (defun c:foo ( / num_path i e c lst) (setq num_path (ssname (ssget (list (cons 0 "ARC"))) 0)) (setq e (ssname (ssget (list (cons 0 "TEXT"))) 0)) (setq c (trans (cdr (assoc 10 (entget e))) e 0)) (setq lst (cons c lst)) (setq lst (mapcar '(lambda (% / tmp_1 tmp_2 vec_pt vec_path tmp_3 ) (setq tmp_1 (vlax-curve-getClosestPointTo num_path %)) (setq tmp_2 (vlax-curve-getParamAtPoint num_path tmp_1)) (setq vec_pt (mapcar '- % tmp_1)) (setq vec_path (vlax-curve-getfirstderiv num_path tmp_2)) (if (minusp (sin (- (angle '(0 0 0) vec_pt) (angle '(0 0 0) vec_path)))) (alert "Outside Arc") (alert "Inside Arc") ) ) lst ) ) ) This Code is working perfectly.. If you can modify it be as simple as possible this will be perfect .. Thanks Sorry I'm still a noob (defun c:foo ( / num_path i e c lst) (setq num_path (ssname (ssget (list (cons 0 "ARC"))) 0)) (setq e (ssname (ssget (list (cons 0 "TEXT"))) 0)) (setq c (trans (cdr (assoc 10 (entget e))) e 0)) (setq tmp_1 (vlax-curve-getClosestPointTo num_path c)) (setq tmp_2 (vlax-curve-getParamAtPoint num_path tmp_1)) (setq vec_pt (mapcar '- c tmp_1)) (setq vec_path (vlax-curve-getfirstderiv num_path tmp_2)) (if (minusp (sin (- (angle '(0 0 0) vec_pt) (angle '(0 0 0) vec_path)))) (alert "Outside Arc") (alert "Inside Arc") ) ) 1 Quote
Engineer_Yasser Posted October 23, 2023 Author Posted October 23, 2023 2 hours ago, Steven P said: An alternative method, create a temporary arc line and work out which line the text is closest to.. and so whether the text is inside or outside. Note that 'outside' is if the text would be outside of a circle that the arc is taken from (so a long way inside 2x radius away becomes outside) No error checking on the selection of arc or text (From BigAls suggestion) (defun c:inout ( / MyPoint ent1 vaobj1 dist1 ArcLen1 ent2 vlaobj2 dist2 ArcLen2 InnerDist OuterDist) (setq MyPoint (cdr (assoc 10 (entget (car (entsel "\nSelect Text")))))) ; Selected text insert point (setq vlaobj1 (vlax-ename->vla-object (car (entsel "\nSelect Arc")))) ; Select arc as VLA-Object (setq dist1 (distance MyPoint (vlax-curve-getClosestPointTo vlaobj1 MyPoint T)) ) ;Distance text to arc (setq ArcLen1 (vlax-curve-getDistAtParam vlaobj1 (vlax-curve-getEndParam vlaobj1)) ) ; arc length (vla-Offset vlaobj1 (* ArcLen1 0.001)) ; Create temp line, offset small amount (setq ent2 (entlast)) ; new arc temporary line (setq vlaobj2 (vlax-ename->vla-object ent2)) ; get Arc as VLA-object (setq dist2 (distance MyPoint (vlax-curve-getClosestPointTo vlaobj2 MyPoint T)) ) ;Distance arc 2 to text (setq ArcLen2 (vlax-curve-getDistAtParam vlaobj2 (vlax-curve-getEndParam vlaobj2)) ) ; arc length (entdel ent2) ; delete temporary line ASAP (if (< ArcLen2 ArcLen1) ; Work out inner and outer arcs (setq InnerDist Dist1 OuterDist Dist2) (setq InnerDist Dist2 OuterDist Dist1) ) (if (< InnerDist OuterDist) ; Work out inside / outside (princ "\nOutside") (princ "\nInside") ) (princ) ; End quietly ) Both of your two codes working well ... but in the case of the text inside the red circle the result was outside but it was supposed to be at the arc inside ( side ) Quote
Engineer_Yasser Posted October 23, 2023 Author Posted October 23, 2023 1 hour ago, hosneyalaa said: (defun c:foo ( / num_path i e c lst) (setq num_path (ssname (ssget (list (cons 0 "ARC"))) 0)) (setq e (ssname (ssget (list (cons 0 "TEXT"))) 0)) (setq c (trans (cdr (assoc 10 (entget e))) e 0)) (setq tmp_1 (vlax-curve-getClosestPointTo num_path c)) (setq tmp_2 (vlax-curve-getParamAtPoint num_path tmp_1)) (setq vec_pt (mapcar '- c tmp_1)) (setq vec_path (vlax-curve-getfirstderiv num_path tmp_2)) (if (minusp (sin (- (angle '(0 0 0) vec_pt) (angle '(0 0 0) vec_path)))) (alert "Outside Arc") (alert "Inside Arc") ) ) This gave me the perfect result in all conditions .... Thanks Quote
Steven P Posted October 23, 2023 Posted October 23, 2023 32 minutes ago, Engineer_Yasser said: Both of your two codes working well ... but in the case of the text inside the red circle the result was outside but it was supposed to be at the arc inside ( side ) Yes, that's what it is meant to do - where the text is of to the sides the extension of the arc follows the curve of its circle rather than a straight line extension passing the 2 end points of the arc. In which case the simpler code will be using trigonometry from hosneyalaa rather then geometry from my example. (to modify mine I'd need 2 stages, first to determine the inside-outside from the straight line and then for the special case of the 'bump' created by the arc) I assume this red line is what you want? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.