zezto Posted September 20, 2023 Posted September 20, 2023 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. 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. Anyone have this lisp please ? new block.dwg Quote
Emmanuel Delay Posted September 21, 2023 Posted September 21, 2023 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) ) 1 Quote
Tharwat Posted September 21, 2023 Posted September 21, 2023 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. 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. 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 ? Quote
zezto Posted September 24, 2023 Author Posted September 24, 2023 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 Quote
CADTutor Posted September 24, 2023 Posted September 24, 2023 Also, you are both logging in from the same IP address and using the same browser. Wow, what a coincidence! Please use your main account when posting on this forum. Quote
zezto Posted September 24, 2023 Author Posted September 24, 2023 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 Quote
Recommended Posts
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.