Jump to content

Lisp to Change length of part of polyline


zezto

Recommended Posts

Hello everyone,

I have some polylines which consists of two or three segment, one segment is taller than the others. The smaller segments may have different lengths.

image.png.84101501075692e4807823e768bb18c2.png

I want the small segments of the polyline to be changed to specific length (defined by the user). This better to be for all selected polylines at once.

image.png.972a0ed60b8f0d75df8160a991dae087.png

 

Anyone have this lisp please ?

new block.dwg

Link to comment
Share on other sites

This works.

I called it command STAPLE.

 

It both extends and trims

 

(vl-load-com)

;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-the-z-coordinate-of-3d-polyline/td-p/2435197
;;  Poly-Pts
;;; returns a list of the polyline vertices WCS coordinates
;;; Argument: a polyline (ENAME or VLA-OBJECT)
(defun poly-pts (p / n l)
	(setq n (fix (vlax-curve-getEndParam p)))
	(or (vlax-curve-IsClosed p) (setq n (1+ n)))
	(repeat n
	    (setq l (cons (vlax-curve-getPointAtParam p (setq n (1- n))) l))
	)
)


(defun c:staple  ( / i shortSize ss pl newpoints ang1 ang2 dist1 dist2)
	
	(setq shortSize (getdist "\Short size distance: "))
	(setq ss (ssget (list (cons 0 "*POLYLINE"))))
	
	(setq i 0)
	(repeat (sslength ss)
		(setq pl (ssname ss i))

		;; read vertex points
		(setq pts (poly-pts pl))
		;; let's see which is the long side.
			;; for 4 vertices it's the middle line
			;; for 3 vertices it can be any of both lines.
		(if (= (length pts) 4)
			(progn
				 (setq ang1 (angle (nth 1 pts) (nth 0 pts))) 
				 (setq dist1 (distance (nth 1 pts) (nth 0 pts)))
				 (setq ang2 (angle (nth 2 pts) (nth 3 pts)))
				 (setq dist2 (distance (nth 2 pts) (nth 3 pts)))
				
				;; make a new list of coordinates
				(setq newpoints (list
					(nth 0 (polar (nth 1 pts) ang1 shortSize)) (nth 1 (polar (nth 1 pts) ang1 shortSize)) 
					(nth 0 (nth 1 pts)) (nth 1 (nth 1 pts)) 
					(nth 0 (nth 2 pts)) (nth 1 (nth 2 pts)) 
					(nth 0 (polar (nth 2 pts) ang2 shortSize)) (nth 1 (polar (nth 2 pts) ang2 shortSize)) 
				))
				(vlax-put (vlax-ename->vla-object pl) 'coordinates newpoints)
			)
		)
		(if (= (length pts) 3)
			(if (< (distance (nth 1 pts) (nth 0 pts)) (distance (nth 1 pts) (nth 2 pts)) )
				(progn
					;; first line is the short line
					(setq ang1 (angle (nth 1 pts) (nth 0 pts))) 
					(setq dist1 (distance (nth 1 pts) (nth 0 pts)))
					;; make a new list of coordinates
					(setq newpoints (list
						(nth 0 (polar (nth 1 pts) ang1 shortSize)) (nth 1 (polar (nth 1 pts) ang1 shortSize)) 
						(nth 0 (nth 1 pts)) (nth 1 (nth 1 pts)) 
						(nth 0 (nth 2 pts)) (nth 1 (nth 2 pts)) 
					))
					(vlax-put (vlax-ename->vla-object pl) 'coordinates newpoints)
				)
				(progn
					;; second line is the short line
					(setq ang2 (angle (nth 1 pts) (nth 2 pts)))
					(setq dist2 (distance (nth 1 pts) (nth 2 pts)))

					;; make a new list of coordinates
					(setq newpoints (list
						(nth 0 (nth 0 pts)) (nth 1 (nth 0 pts)) 
						(nth 0 (nth 1 pts)) (nth 1 (nth 1 pts)) 
						(nth 0 (polar (nth 1 pts) ang2 shortSize)) (nth 1 (polar (nth 1 pts) ang2 shortSize)) 
					))
					(vlax-put (vlax-ename->vla-object pl) 'coordinates newpoints)
				)
			)
		)
		(setq i (+ i 1))
	)
	(princ)
)

 

  • Funny 1
Link to comment
Share on other sites

On 9/20/2023 at 11:21 AM, zezto said:

Hello everyone,

I have some polylines which consists of two or three segment, one segment is taller than the others. The smaller segments may have different lengths.

image.png.84101501075692e4807823e768bb18c2.png

I want the small segments of the polyline to be changed to specific length (defined by the user). This better to be for all selected polylines at once.

image.png.972a0ed60b8f0d75df8160a991dae087.png

 

Anyone have this lisp please ?

new block.dwg 58.42 kB · 3 downloads

Are not you the same guy as in the following thread which is very identical to this ?

 

Link to comment
Share on other sites

On 9/21/2023 at 10:01 PM, Tharwat said:

Are not you the same guy as in the following thread which is very identical to this ?

 

i don't know about it but it seems that we both work in same industry of structural engineering 😅

Link to comment
Share on other sites

ok i got it guys, i am using a shared laptop duo to license with my colleges and i knew this website from him

may be he posted with similar format because we are working on similar jobs 😅

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