Jump to content

How to create circle in every corner of polyline and trim circles inside


ALBANEXTDOOR

Recommended Posts

How far have you got with this yourself?

 

Obviously we don't know your abilities with LISP so it might be useful to show if you have done anything or if you have no idea where to start and need guidance the whole way - both are OK, you're here to learn. The actual LISP should be fairly easy.

 

 

For your question, 'trim circles inside' how do we know which side of the line is 'inside' and 'outside. You might want to post a sample drawing showing perhaps a before and after so we know for sure what you want

Link to comment
Share on other sites

image.png.a04954a46063bd94de29a4df03f532b2.png

 

 

Thanks for replying my queries. Here's the item I want to automate, the circle on each edge of vertex and at the same time trim the line inside the circle. Does it possible.? I'm gladly appreciate your help. :)

Link to comment
Share on other sites

Hello initially, I coded this :

 

(defun C:CC (/  coords ent rad)
 (setq rad (getreal"\nEnter radius: "))
           (while (setq ent (entsel "\nSelect polyline (or press Enter to Exit) >> "))
           (setq ent (car ent))
      (setq coords (vl-remove-if 'not
      (mapcar
        (function (lambda(p)
      (if (= 10 (car p))(cdr p))))
        (entget ent))))
      
      (foreach pt coords
 (command "_circle" "_non" pt rad)   
   )
         )
           (princ)
 )

 

This will convert polyline vertices to circle. What I want is to automate trim the vertices inside the circle. Hope someone help me to include extrim or any code on this. Thank you sir.

  • Like 1
Link to comment
Share on other sites

54 minutes ago, ALBANEXTDOOR said:

Hello initially, I coded this :

"code erased"

 

This will convert polyline vertices to circle. What I want is to automate trim the vertices inside the circle. Hope someone help me to include extrim or any code on this. Thank you sir.

Ok , how do you need or want to trim the circles at both end and start points. 

Please upload you sample.dwg with a BEFORE and an AFTER

Link to comment
Share on other sites

And why not apply a donut of white color and the circle of the color of the current layer?
So in paper space or when printing it will look the same as if the polyline was adjusted.
In addition you keep your polyline in one piece...

(defun C:CC (/  coords ent rad)
  (initget 7)
  (setq rad (getdist "\nEnter radius: "))
  (while (setq ent (entsel "\nSelect polyline (or press Enter to Exit) >> "))
    (setq
      ent (car ent)
      coords
      (vl-remove-if 'not
        (mapcar
          (function
            (lambda (p)
              (if (= 10 (car p)) (cdr p))
            )
          )
          (entget ent)
        )
      )
    )
    (foreach pt coords
      (entmake
        (list
          '(0 . "LWPOLYLINE")
          '(100 . "AcDbEntity")
          (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
          (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
          (cons 8 (getvar "CLAYER"))
          '(62 . 7)
          '(420 . 16777215)
          '(100 . "AcDbPolyline")
          '(90 . 2)
          '(70 . 1)
          (cons 43 rad)
          (cons 38 (getvar "ELEVATION"))
          (cons 39 (getvar "THICKNESS"))
          '(39 . 0.0)
          (cons 10 (trans (list (+ (car pt) (* 0.5 rad)) (cadr pt)) 1 0))
          (cons 40 rad)
          (cons 41 rad)
          '(42 . 1.0)
          '(91 . 0)
          (cons 10 (trans (list (- (car pt) (* 0.5 rad)) (cadr pt)) 1 0))
          (cons 40 rad)
          (cons 41 rad)
          '(42 . 1.0)
          '(91 . 0)
          '(210 0.0 0.0 1.0)
        )
      )
      (entmake
        (list
          '(0 . "CIRCLE")
          '(100 . "AcDbEntity")
          (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
          (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
          (cons 8 (getvar "CLAYER"))
          (cons 10 (trans pt 1 0))
          (cons 40 rad)
          '(210 0.0 0.0 1.0)
        )
      )
    )
  )
  (princ)
)

 

  • Like 2
Link to comment
Share on other sites

Anyway, this might be as good starting point for you?

 

https://autocadtips1.com/2012/03/08/autolisp-trim-objects-on-one-side/

 

I haven't tried this yet but if you make a selection set of the circles as you create them, to be variable t1 in this code, the polyline to be a selection set, e, and then you can use something like

 

(setq p (osnap (vlax-curve-getStartPoint (entlast)) "gcen"))

 

as the point p, side to trim on.

 

However... I think this will only work if the polyline is a closed polyline - which should be OK to do, copy the existing polyline and call this new line a name (setq Polyinename (entlast)) - something like that. Something like this from Lee Mac (http://lee-mac.com/polylineprograms.html) will close a polyline. So with a closed polyline I think this should work. Trim the circles, delete this temporary polyline (which you can do since you were bullying calling it names).

 

Errors might do strange things such as leaving the temporary polyline in place.

 

 

For Devtigs question, what to do with the end circles, this will trim them as if the missing link in the polyline is there. If you want to do something else then don't add them to the polyline..

 

 

 

Right, kind of hoping you follow all of that?

  • Like 1
Link to comment
Share on other sites

 

4 hours ago, ALBANEXTDOOR said:

 What I want is to automate trim the vertices inside the circle. 

 

Ahh, have I got my answer the wrong way round by the way? I am trimming the circles and leaving the polyline as it was.

 

Are you wanting to leave the circles and trimming the polyline

 

image.thumb.png.fc0b91ef8715de366e4eeae4d886a981.png

Which the link will do just needs to think the other way round

 

 

 

-EDIT-

This will cut a polyline out of the circles as above picture, 

 

(defun C:CC (/ coords ent rad e t1)
  (defun MTR (e t1 p / l c)
    (command "TRIM" e "")
    (command (list t1 p))
    (command "")
  )
  (setq rad (getreal"\nEnter radius: "))
  (while (setq ent (car (entsel "\nSelect polyline (or press Enter to Exit) >> ")))
    (setq t1 ent)
    (setq coords (vl-remove-if 'not
      (mapcar
        (function (lambda(p)
           (if (= 10 (car p))(cdr p))
        ))
        (entget ent)
      ) ; end mapcar
    )) ; end setq, vl-remove-if
    (setq coords (reverse coords))
    (foreach pt coords
      (command "_circle" "_non" pt rad)
      (setq e nil)
      (setq e (entlast))
      (setq p (assoc 10 (entget e)))
      (setq p (list (cadr p) (caddr p) (cadddr p)))
      (command "TRIM" e "")
      (command (list t1 p))
      (command "")
    ) ; end foreach
  ) ; end while
  (princ)
)

 

Edited by Steven P
  • Like 1
Link to comment
Share on other sites

Maybe this would work

;;; By Isaac A.
;;; https://www.cadtutor.net/forum/topic/76618-how-to-create-circle-in-every-corner-of-polyline-and-trim-circles-inside/
;;; Draws circles in every vertex of plines and trims them
(defun c:ctri (/ b foo ss)
 (if (not etrim) (load "extrim.lsp"))
 (defun foo (p) ;; Alan J. Thompson, 09.09.10
                ;; https://www.cadtutor.net/forum/topic/25037-drawing-circles-to-all-vertices-of-polyline/
   (if (vl-consp p)
     (or (vl-member-if
           (function (lambda (a) (equal (list (car a) (cadr a)) (list (car p) (cadr p)))))
           plst
         )
         (setq plst (cons (cdr (assoc 10 (entmake (list '(0 . "CIRCLE") (cons 10 p) (cons 40 b)))
                            )
                          )
                          pLst
                    )
         )
     )
   )
 )

 (if (and (setq ss (ssget '((0 . "*POLYLINE")))) (not (initget 6))  ;;; (setq i -1)
          (setq b (getdist "\nSpecify circle radius :"))
     )
   ((lambda (i / e eLst p pLst)
      (while (setq e (ssname ss (setq i (1+ i))))
          (vl-position (cdr (assoc 0 (entget e))) '("LWPOLYLINE" "POLYLINE"))
          (repeat (setq p (1+ (fix (vlax-curve-getEndParam e))))
             (foo (vlax-curve-getPointAtParam e (setq p (1- p))))
          )
          (etrim e (ia:midp (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e)))
       ;;; (osnap (vlax-curve-getStartPoint e) "gcen")
      )
    )
    -1 
   )
 )
 (princ)
)

;;; ia:midp
;;; Returns the midpoint of 2 given points
(defun ia:midp (a b)
  (mapcar '* (mapcar '+ a b) '(0.5 0.5 0.5))
)

Although most of the code is from Alan J. T., thanks for sharing your codes.

This will work with open polylines but as has been said it will not work on the start and end point because it needs 2 points on the polyline to trim the circles.

HTH.

  • Like 1
Link to comment
Share on other sites

7 hours ago, Steven P said:

 

 

Ahh, have I got my answer the wrong way round by the way? I am trimming the circles and leaving the polyline as it was.

 

Are you wanting to leave the circles and trimming the polyline

 

image.thumb.png.fc0b91ef8715de366e4eeae4d886a981.png

Which the link will do just needs to think the other way round

 

 

 

-EDIT-

This will cut a polyline out of the circles as above picture, 

 

(defun C:CC (/ coords ent rad e t1)
  (defun MTR (e t1 p / l c)
    (command "TRIM" e "")
    (command (list t1 p))
    (command "")
  )
  (setq rad (getreal"\nEnter radius: "))
  (while (setq ent (car (entsel "\nSelect polyline (or press Enter to Exit) >> ")))
    (setq t1 ent)
    (setq coords (vl-remove-if 'not
      (mapcar
        (function (lambda(p)
           (if (= 10 (car p))(cdr p))
        ))
        (entget ent)
      ) ; end mapcar
    )) ; end setq, vl-remove-if
    (setq coords (reverse coords))
    (foreach pt coords
      (command "_circle" "_non" pt rad)
      (setq e nil)
      (setq e (entlast))
      (setq p (assoc 10 (entget e)))
      (setq p (list (cadr p) (caddr p) (cadddr p)))
      (command "TRIM" e "")
      (command (list t1 p))
      (command "")
    ) ; end foreach
  ) ; end while
  (princ)
)

 

 

This one really works for me. Thanks for the help. Very much appreciated :)

Link to comment
Share on other sites

I would look at using a wipeout rather than a trim then your pline still exists but will look like its broken just make a polygon rather than a circle if you have a reasonable number of sides it will look like a circle.

20 sides

image.png.a561e0bbc1138a7f09ff64d91417b84b.png

  • Like 2
Link to comment
Share on other sites

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