Jump to content

Recommended Posts

Posted (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?

 

 

Screenshot (1444).png

Edited by amir0914
Posted (edited)

Changed my mind about idea.

Edited by BIGAL
  • Like 1
Posted
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

Posted

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.

  • Like 1
Posted (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 by amir0914
Posted
(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.

  • Like 1
Posted (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

Screenshot (1445).png

Edited by amir0914
Posted

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?

  • Like 1
Posted

What if the circle is located at the vertex of the polyline? Offset it at half the angle formed between the two lines?

  • Like 1
Posted
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.

Posted (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 by amir0914
Posted (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 by dlanorh
updated bug in code
  • Like 1
Posted
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.

Posted
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

  • Like 1
Posted

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...

  • Like 1
Posted

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.

  • Like 1
Posted (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.

 

Screenshot (1448).png

Edited by amir0914
Posted

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

 

  • Like 1
Posted (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

 

dlanorhThanks  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.

Screenshot (1450).png

Circle.dwg

Edited by amir0914
Posted

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...