Jump to content

lisp to draw circles on ends of selected line


Recommended Posts

Posted

I need a lisp to draw circles (1.5mm Dia ) on the ends of one selected line after that trim inside the circles then delete the line.

Posted
Quote

[...] after that trim inside the circles then delete the line.

I think you meant "then delete the circles"

AutoCAD already has a built-in command for that. Search the help file for LENGTHEN. Use the Delta option and enter -0.75 (negative number!) to get the line shortened.

Also to make a line shorter, the Lisp I posted as answer to your other request (to extend a line) can be rewritten to suit your need.

To rewrite it - that will be your pleasure! :)

Posted
16 hours ago, fuccaro said:

@Mohamed_Essam_2000

I think you should learn to code. AutoLisp is not hard to learn...

When I first started learning, I could barely get any functions running... with which I didn't know any way to debug. Like, I didn't understand what the heck the DXF codes are (why 8? why 40?), or what the heck assoc and cdr are. It wasn't easy for me, at least.

Posted (edited)

@Mohamed_Essam_2000

Here's a quick one to draw the line and add circles at the end:

(defun c:foo (/ _circle d p1 p2 r)
  ;; RJP » 2024-11-26
  (defun _circle (p r) (entmakex (list '(0 . "CIRCLE") (cons 10 p) (cons 40 r))))
  (cond	((and (setq p1 (getpoint "\nSpecify first point: "))
	      (setq p2 (getpoint p1 "\nSpecify next point: "))
	 )
	 (_circle p1 (setq r 0.75))
	 (_circle p2 r)
	 (entmakex (list '(0 . "LINE")
			 (cons 10 (polar p1 (angle p1 p2) (setq d (- (distance p1 p2) r))))
			 (cons 11 (polar p2 (angle p2 p1) d))
		   )
	 )
	)
  )
  (princ)
)

 

2024-11-26_10-56-35.gif.c316ac40c72110933cad15ded1b9adb5.gif

 

And one to select lines:

(defun c:foo (/ _circle d el p1 p2 r s)
  ;; RJP » 2024-11-26
  (defun _circle (p r) (entmakex (list '(0 . "CIRCLE") (cons 10 p) (cons 40 r))))
  (cond	((setq s (ssget ":L" '((0 . "LINE"))))
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (_circle (setq p1 (cdr (assoc 10 (setq el (entget e))))) (setq r 0.75))
	   (_circle (setq p2 (cdr (assoc 11 (entget e)))) r)
	   (setq el (entmod (subst (cons 10 (polar p1 (angle p1 p2) r)) (assoc 10 el) el)))
	   (entmod (subst (cons 11 (polar p2 (angle p2 p1) r)) (assoc 11 el) el))
	 )
	)
  )
  (princ)
)

 

2024-11-26_11-14-39.gif.bc1ca932ed03a23506d7120c67cdcc71.gif

Edited by ronjonp
  • Thanks 1
Posted
3 hours ago, ronjonp said:

@Mohamed_Essam_2000

Here's a quick one to draw the line and add circles at the end:

(defun c:foo (/ _circle d p1 p2 r)
  ;; RJP » 2024-11-26
  (defun _circle (p r) (entmakex (list '(0 . "CIRCLE") (cons 10 p) (cons 40 r))))
  (cond	((and (setq p1 (getpoint "\nSpecify first point: "))
	      (setq p2 (getpoint p1 "\nSpecify next point: "))
	 )
	 (_circle p1 (setq r 0.75))
	 (_circle p2 r)
	 (entmakex (list '(0 . "LINE")
			 (cons 10 (polar p1 (angle p1 p2) (setq d (- (distance p1 p2) r))))
			 (cons 11 (polar p2 (angle p2 p1) d))
		   )
	 )
	)
  )
  (princ)
)

 

2024-11-26_10-56-35.gif.c316ac40c72110933cad15ded1b9adb5.gif

 

And one to select lines:

(defun c:foo (/ _circle d el p1 p2 r s)
  ;; RJP » 2024-11-26
  (defun _circle (p r) (entmakex (list '(0 . "CIRCLE") (cons 10 p) (cons 40 r))))
  (cond	((setq s (ssget ":L" '((0 . "LINE"))))
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (_circle (setq p1 (cdr (assoc 10 (setq el (entget e))))) (setq r 0.75))
	   (_circle (setq p2 (cdr (assoc 11 (entget e)))) r)
	   (setq el (entmod (subst (cons 10 (polar p1 (angle p1 p2) r)) (assoc 10 el) el)))
	   (entmod (subst (cons 11 (polar p2 (angle p2 p1) r)) (assoc 11 el) el))
	 )
	)
  )
  (princ)
)

 

2024-11-26_11-14-39.gif.bc1ca932ed03a23506d7120c67cdcc71.gif

That's very nice.

Thank you, bro.

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