Jump to content

Lisp to draw 2 lines on a line


Recommended Posts

Posted

Need a lisp to draw a line (2mm length and yellow colored) from the end point of the selected line towards the other end point.

Capture.JPG

Posted
(defun c:pp()
  (setq line (entget (car (entsel "select line to be extended ")))
    dist 2.0
    pa (cdr (assoc 10 line))
    pb (cdr (assoc 11 line))
    lay (assoc 8 line)
    len (distance pa pb)
    rl (/ dist len)
    pc (mapcar '(lambda(a b)(+ b (* rl (- b a)))) pa pb)
    pd (mapcar '(lambda(a b)(- a (* rl (- b a)))) pa pb)
    )
  (entmake (list '(0 . "LINE")(cons 10 pb)(cons 11 pc)'(62 . 2) lay ))
  (entmake (list '(0 . "LINE")(cons 10 pa)(cons 11 pd)'(62 . 2) lay ))
  )

 

  • Thanks 1
Posted
21 minutes ago, fuccaro said:
(defun c:pp()
  (setq line (entget (car (entsel "select line to be extended ")))
    dist 2.0
    pa (cdr (assoc 10 line))
    pb (cdr (assoc 11 line))
    lay (assoc 8 line)
    len (distance pa pb)
    rl (/ dist len)
    pc (mapcar '(lambda(a b)(+ b (* rl (- b a)))) pa pb)
    pd (mapcar '(lambda(a b)(- a (* rl (- b a)))) pa pb)
    )
  (entmake (list '(0 . "LINE")(cons 10 pb)(cons 11 pc)'(62 . 2) lay ))
  (entmake (list '(0 . "LINE")(cons 10 pa)(cons 11 pd)'(62 . 2) lay ))
  )

 

Thank you, bro.

but if I finally want to delete the original line (the white line).

It will be better if the multi selection is enabled, so that we can select many lines and apply this lisp.

Posted
(defun c:pp()
  (setq oldLine (car (entsel "select line to be extended "))
	line (entget oldLine)
	dist 2.0
	pa (cdr (assoc 10 line))
	pb (cdr (assoc 11 line))
	lay (assoc 8 line)
	len (distance pa pb)
	rl (/ dist len)
	pc (mapcar '(lambda(a b)(+ b (* rl (- b a)))) pa pb)
	pd (mapcar '(lambda(a b)(- a (* rl (- b a)))) pa pb)
	)
  (entmake (list '(0 . "LINE")(cons 10 pb)(cons 11 pc)'(62 . 2) lay ))
  (entmake (list '(0 . "LINE")(cons 10 pa)(cons 11 pd)'(62 . 2) lay ))
  (entdel oldLine)
  )

This will delete the original line.

  • Thanks 1
Posted (edited)
12 minutes ago, fuccaro said:
(defun c:pp()
  (setq oldLine (car (entsel "select line to be extended "))
	line (entget oldLine)
	dist 2.0
	pa (cdr (assoc 10 line))
	pb (cdr (assoc 11 line))
	lay (assoc 8 line)
	len (distance pa pb)
	rl (/ dist len)
	pc (mapcar '(lambda(a b)(+ b (* rl (- b a)))) pa pb)
	pd (mapcar '(lambda(a b)(- a (* rl (- b a)))) pa pb)
	)
  (entmake (list '(0 . "LINE")(cons 10 pb)(cons 11 pc)'(62 . 2) lay ))
  (entmake (list '(0 . "LINE")(cons 10 pa)(cons 11 pd)'(62 . 2) lay ))
  (entdel oldLine)
  )

This will delete the original line.

But the total length will not be extended.

the total length is required to be constant.

I mean, the yellow line will start from the end-point of the oldline towards the other end-point.

Edited by Mohamed_Essam_2000
Posted

Yes, in the original request I missed that "towards the other end point".

Posted

So... this can process more lines at a time.

(defun c:pp()
  (setq dist 2.0 lines (ssget '((0 . "LINE"))) n (sslength lines))
  (repeat n
    (setq l1 (ssname lines (setq n (1- n)))
	  line (entget l1)
	  pa (cdr (assoc 10 line))
	  pb (cdr (assoc 11 line))
	  lay (assoc 8 line)
	  len (distance pa pb)
	  rl (/ dist len)
	  pc (mapcar '(lambda(a b)(+ b (* rl (- a b)))) pa pb)
	  pd (mapcar '(lambda(a b)(- a (* rl (- a b)))) pa pb)
	  )
    (entmake (list '(0 . "LINE")(cons 10 pb)(cons 11 pc)'(62 . 2) lay ))
    (entmake (list '(0 . "LINE")(cons 10 pa)(cons 11 pd)'(62 . 2) lay ))
    (entdel l1)
    )
  )

 

  • Thanks 1
Posted
2 minutes ago, fuccaro said:

So... this can process more lines at a time.

(defun c:pp()
  (setq dist 2.0 lines (ssget '((0 . "LINE"))) n (sslength lines))
  (repeat n
    (setq l1 (ssname lines (setq n (1- n)))
	  line (entget l1)
	  pa (cdr (assoc 10 line))
	  pb (cdr (assoc 11 line))
	  lay (assoc 8 line)
	  len (distance pa pb)
	  rl (/ dist len)
	  pc (mapcar '(lambda(a b)(+ b (* rl (- a b)))) pa pb)
	  pd (mapcar '(lambda(a b)(- a (* rl (- a b)))) pa pb)
	  )
    (entmake (list '(0 . "LINE")(cons 10 pb)(cons 11 pc)'(62 . 2) lay ))
    (entmake (list '(0 . "LINE")(cons 10 pa)(cons 11 pd)'(62 . 2) lay ))
    (entdel l1)
    )
  )

 

Thank you very much, bro.

  • Like 1
Posted (edited)

@Mohamed_Essam_2000 just a comment in future for similar request it would be more helpful if you refer to the task as "from start point towards end point", this makes it clear which end to draw from, the reason I say this is often use select an end to determine the direction you want to draw in, this allows for swapping of line direction if needed.

 

As shown by @fuccaro the start point for a line  is dxf (cdr (assoc 10 line))  or VL (vlax-curve-getstartPoint obj) or (getpropertyvalue (car (entsel)) "startpoint")

Edited by BIGAL
  • Agree 1
Posted
17 hours ago, BIGAL said:

@Mohamed_Essam_2000 just a comment in future for similar request it would be more helpful if you refer to the task as "from start point towards end point", this makes it clear which end to draw from, the reason I say this is often use select an end to determine the direction you want to draw in, this allows for swapping of line direction if needed.

 

As shown by @fuccaro the start point for a line  is dxf (cdr (assoc 10 line))  or VL (vlax-curve-getstartPoint obj) or (getpropertyvalue (car (entsel)) "startpoint")

I agree with you.

Ok, I will.

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