RepCad Posted March 19, 2020 Share Posted March 19, 2020 (edited) Hi all, I have several circles on the polyline and I need to move them into the polyline by get distance from user, is it possible to do this via autolisp? Edited December 7, 2020 by amir0914 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 20, 2020 Share Posted March 20, 2020 (edited) Changed my mind about idea. Edited March 20, 2020 by BIGAL 1 Quote Link to comment Share on other sites More sharing options...
RepCad Posted March 20, 2020 Author Share Posted March 20, 2020 8 hours ago, BIGAL said: Changed my mind about idea. Hi bigal,sorry my English is not good, I have many closed polyline and several circle on them, and I need to move the circles into the closed polyline with a specified distance. I made a dwg, please take a look at that. Move.dwg Quote Link to comment Share on other sites More sharing options...
Jonathan Handojo Posted March 20, 2020 Share Posted March 20, 2020 Yes, it's very possible. One query, do the polylines have any bulges on them? Or any curves? If not, then I might just do ssget F on each vertex to select the circles. 1 Quote Link to comment Share on other sites More sharing options...
RepCad Posted March 20, 2020 Author Share Posted March 20, 2020 (edited) 15 minutes ago, Jonathan Handojo said: Yes, it's very possible. One query, do the polylines have any bulges on them? Or any curves? If not, then I might just do ssget F on each vertex to select the circles. Thanks for replying, I don't understand what you mean about bulges but all the polylines don't have any arc or curve. Edited March 20, 2020 by amir0914 Quote Link to comment Share on other sites More sharing options...
fuccaro Posted March 20, 2020 Share Posted March 20, 2020 (defun c:pp() (setq p (car (entsel "Polyline?"))) (setq ssC (ssget "X" (list (cons 0 "Circle")))) (setq dist (getdist " distance?")) (setq pl(entget p) pl (member (assoc 10 pl) pl) points nil) (while pl (setq points (cons (cdar pl) points) pl (cdr pl) pl (member (assoc 10 pl) pl)) ) (setq i 0) (repeat (1- (length points)) (setq A (nth i points) B (nth (setq i (1+ i)) points)) (repeat (setq j (sslength ssC)) (setq C (cdr (assoc 10 (entget (setq M (ssname ssC (setq j (1- j)))))))) (if (= (distan A B) (+ (distan A C) (distan C B))) (move M A C dist)) ) ) ) (defun distan (a b / c d) (setq c (- (car a) (car b)) d (- (cadr a) (cadr b))) (sqrt (+ (* c c) (* d d))) ) (defun move (e a b dist) (setq p (polar (cdr (assoc 10 (entget e))) (+ (/ PI 2.0) (angle a b)) dist)) (setq el (entget M) el (subst (cons 10 p) (assoc 10 el) el) el (entmod el)) ) Wrote it in a hurry... it can be improved, but first give me a feed-back to be sure it's what you need. 1 Quote Link to comment Share on other sites More sharing options...
RepCad Posted March 20, 2020 Author Share Posted March 20, 2020 (edited) 28 minutes ago, fuccaro said: (defun c:pp() (setq p (car (entsel "Polyline?"))) (setq ssC (ssget "X" (list (cons 0 "Circle")))) (setq dist (getdist " distance?")) (setq pl(entget p) pl (member (assoc 10 pl) pl) points nil) (while pl (setq points (cons (cdar pl) points) pl (cdr pl) pl (member (assoc 10 pl) pl)) ) (setq i 0) (repeat (1- (length points)) (setq A (nth i points) B (nth (setq i (1+ i)) points)) (repeat (setq j (sslength ssC)) (setq C (cdr (assoc 10 (entget (setq M (ssname ssC (setq j (1- j)))))))) (if (= (distan A B) (+ (distan A C) (distan C B))) (move M A C dist)) ) ) ) (defun distan (a b / c d) (setq c (- (car a) (car b)) d (- (cadr a) (cadr b))) (sqrt (+ (* c c) (* d d))) ) (defun move (e a b dist) (setq p (polar (cdr (assoc 10 (entget e))) (+ (/ PI 2.0) (angle a b)) dist)) (setq el (entget M) el (subst (cons 10 p) (assoc 10 el) el) el (entmod el)) ) Wrote it in a hurry... it can be improved, but first give me a feed-back to be sure it's what you need. Thanks but it's not working right, I need to move the circles into the polyline Edited March 20, 2020 by amir0914 Quote Link to comment Share on other sites More sharing options...
fuccaro Posted March 20, 2020 Share Posted March 20, 2020 Try to enter negative distance Also I see not all the circles are moved. Are you sure all the center points lay *exactly* on the polyline? 1 Quote Link to comment Share on other sites More sharing options...
Jonathan Handojo Posted March 20, 2020 Share Posted March 20, 2020 What if the circle is located at the vertex of the polyline? Offset it at half the angle formed between the two lines? 1 Quote Link to comment Share on other sites More sharing options...
RepCad Posted March 20, 2020 Author Share Posted March 20, 2020 6 hours ago, fuccaro said: Try to enter negative distance Also I see not all the circles are moved. Are you sure all the center points lay *exactly* on the polyline? Thank you fuccaro, I wonder that the distance with 20 move all circles into the polyline and also the distance with 20 move all the circle out of the polyline on same polyline. For next query, yes all circle are exactly on the polyline. Quote Link to comment Share on other sites More sharing options...
RepCad Posted March 20, 2020 Author Share Posted March 20, 2020 (edited) 6 hours ago, Jonathan Handojo said: What if the circle is located at the vertex of the polyline? Offset it at half the angle formed between the two lines? All polylines don't have any circle at the vertex. Edited March 20, 2020 by amir0914 Quote Link to comment Share on other sites More sharing options...
dlanorh Posted March 20, 2020 Share Posted March 20, 2020 (edited) a bit rough and ready, but try this (defun c:movec ( / dst ent obj tmp ss cnt elst i_pt c_pt) (initget 7) (setq dst (getreal "\nEnter Distance to Move : ") ent (car (entsel "\nSelect Polyline : ")) obj (vlax-ename->vla-object ent) tmp (car (vlax-invoke obj 'offset dst)) );end_setq (cond ( (> (vlax-get tmp 'area) (vlax-get obj 'area)) (setq dst (* dst -1.0)))) (vla-delete tmp) (prompt "\nSelect Circles : ") (setq ss (ssget ":L" '((0 . "CIRCLE")))) (cond (ss (setq tmp (car (vlax-invoke obj 'offset dst))) (repeat (setq cnt (sslength ss)) (setq ent (ssname ss (setq cnt (1- cnt))) elst (entget ent) i_pt (reverse (cdr (reverse (cdr (assoc 10 elst))))) c_pt (vlax-curve-getclosestpointto tmp i_pt) );end_setq (entmod (subst (cons 10 c_pt) (assoc 10 elst) elst)) );end_repeat (vla-delete tmp) ) );end_cond );end_defun Edited March 20, 2020 by dlanorh updated bug in code 1 Quote Link to comment Share on other sites More sharing options...
RepCad Posted March 20, 2020 Author Share Posted March 20, 2020 38 minutes ago, dlanorh said: a bit rough and ready, but try this (defun c:movec ( / dst ent obj tmp ss cnt elst i_pt c_pt) (initget 7) (setq dst (getreal "\nEnter Distance to Move : ") ent (car (entsel "\nSelect Polyline : ")) obj (vlax-ename->vla-object ent) tmp (car (vlax-invoke obj 'offset dst)) );end_setq (cond ( (> (vlax-get tmp 'area) (vlax-get obj 'area)) (vla-delete tmp) (setq dst (* dst -1.0)) ) );end_cond (prompt "\nSelect Circles : ") (setq ss (ssget ":L" '((0 . "CIRCLE")))) (cond (ss (setq tmp (car (vlax-invoke obj 'offset dst))) (repeat (setq cnt (sslength ss)) (setq ent (ssname ss (setq cnt (1- cnt))) elst (entget ent) i_pt (reverse (cdr (reverse (cdr (assoc 10 elst))))) c_pt (vlax-curve-getclosestpointto tmp i_pt) );end_setq (entmod (subst (cons 10 c_pt) (assoc 10 elst) elst)) );end_repeat (vla-delete tmp) ) );end_cond );end_defun Thank you so much dlanorh, That was great, also that was very brief and useful. Quote Link to comment Share on other sites More sharing options...
dlanorh Posted March 20, 2020 Share Posted March 20, 2020 53 minutes ago, amir0914 said: Thank you so much dlanorh, That was great, also that was very brief and useful. @amir0914 Just noticed a bug. Have updated above code 1 Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted March 20, 2020 Share Posted March 20, 2020 Yes it's concise, but how I understood first picture : you want circles moved othogonal and not perpendicular to offset (look top edge of polyline)... Sorry to disappoint you but I think you'll need other method... 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 21, 2020 Share Posted March 21, 2020 Like Marco not sure perp or at a parallel offset, any way why not use ssget "F" circle gets center points straight away and pline. SSget circle will find any others not on pline if not carefully selected. 1 perp get 1st deriv at pt then polar +90 move circle. May need +- clockwise. 2 do offset internal and use closest point to for move. 1 Quote Link to comment Share on other sites More sharing options...
RepCad Posted March 21, 2020 Author Share Posted March 21, 2020 (edited) 15 hours ago, marko_ribar said: Yes it's concise, but how I understood first picture : you want circles moved othogonal and not perpendicular to offset (look top edge of polyline)... Sorry to disappoint you but I think you'll need other method... You are right marko_ribar, I Checked it carefully, as you said I need another way, the code doesn't move right on this polyline : (because I need to move othogonal) Thanks for your attention. Edited March 21, 2020 by amir0914 Quote Link to comment Share on other sites More sharing options...
dlanorh Posted March 21, 2020 Share Posted March 21, 2020 Easily solved. Try this version. (defun c:moveco ( / dst ent obj tmp ss cnt elst i_pt c_pt ang o_ang) (initget 7) (setq dst (getreal "\nEnter Distance to Move : ") ent (car (entsel "\nSelect Polyline : ")) obj (vlax-ename->vla-object ent) tmp (car (vlax-invoke obj 'offset dst)) );end_setq (cond ( (> (vlax-get tmp 'area) (vlax-get obj 'area)) (setq dst (* dst -1.0)))) (vla-delete tmp) (prompt "\nSelect Circles : ") (setq ss (ssget ":L" '((0 . "CIRCLE")))) (cond (ss (setq tmp (car (vlax-invoke obj 'offset dst))) (repeat (setq cnt (sslength ss)) (setq ent (ssname ss (setq cnt (1- cnt))) elst (entget ent) i_pt (reverse (cdr (reverse (cdr (assoc 10 elst))))) c_pt (vlax-curve-getclosestpointto tmp i_pt) ang (angle i_pt c_pt) );end_setq (setq o_ang (fix (/ ang (* pi 0.5)))) (if (> (rem ang (* pi 0.5)) (* pi 0.25)) (setq o_ang (* (1+ o_ang) (* pi 0.5))) (setq o_ang (* o_ang (* pi 0.5)))) (if (minusp dst) (setq c_pt (polar i_pt (+ o_ang pi) dst)) (setq c_pt (polar i_pt o_ang dst))) (entmod (subst (cons 10 c_pt) (assoc 10 elst) elst)) );end_repeat (vla-delete tmp) ) );end_cond );end_defun 1 Quote Link to comment Share on other sites More sharing options...
RepCad Posted March 21, 2020 Author Share Posted March 21, 2020 (edited) 7 hours ago, dlanorh said: Easily solved. Try this version. (defun c:moveco ( / dst ent obj tmp ss cnt elst i_pt c_pt ang o_ang) (initget 7) (setq dst (getreal "\nEnter Distance to Move : ") ent (car (entsel "\nSelect Polyline : ")) obj (vlax-ename->vla-object ent) tmp (car (vlax-invoke obj 'offset dst)) );end_setq (cond ( (> (vlax-get tmp 'area) (vlax-get obj 'area)) (setq dst (* dst -1.0)))) (vla-delete tmp) (prompt "\nSelect Circles : ") (setq ss (ssget ":L" '((0 . "CIRCLE")))) (cond (ss (setq tmp (car (vlax-invoke obj 'offset dst))) (repeat (setq cnt (sslength ss)) (setq ent (ssname ss (setq cnt (1- cnt))) elst (entget ent) i_pt (reverse (cdr (reverse (cdr (assoc 10 elst))))) c_pt (vlax-curve-getclosestpointto tmp i_pt) ang (angle i_pt c_pt) );end_setq (setq o_ang (fix (/ ang (* pi 0.5)))) (if (> (rem ang (* pi 0.5)) (* pi 0.25)) (setq o_ang (* (1+ o_ang) (* pi 0.5))) (setq o_ang (* o_ang (* pi 0.5)))) (if (minusp dst) (setq c_pt (polar i_pt (+ o_ang pi) dst)) (setq c_pt (polar i_pt o_ang dst))) (entmod (subst (cons 10 c_pt) (assoc 10 elst) elst)) );end_repeat (vla-delete tmp) ) );end_cond );end_defun dlanorh, Thanks for the spent your time for my project, it works well on orthogonal lines, but it still has a problem on diagonal polyline. and also circles is not exact on the offsetted polyline. Circle.dwg Edited March 21, 2020 by amir0914 Quote Link to comment Share on other sites More sharing options...
dlanorh Posted March 21, 2020 Share Posted March 21, 2020 OK That should be easy to solve. The circles are not on the offset polyline as I only moved them orthogonally by the supplied distance. Quote Link to comment Share on other sites More sharing options...
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.