Sandeep RC Posted July 19, 2022 Share Posted July 19, 2022 ALL I WANT IS BOTH THE COMMAND SHOULD PROMPT ME TO SELECT MULTIPLE POLYLINES. AND SHOULD EXECUTE COMMANDS ON ALL MY POLYLINES AT ONCE. DIVCUT_MESCUT.lsp Quote Link to comment Share on other sites More sharing options...
dexus Posted July 19, 2022 Share Posted July 19, 2022 The function one object by using entsel. If you use ssget and a loop, you can make it do the commands on multiple polylines. Below is an example of how to make such a loop. The (princ x) should be replaced with the commands from the function you posted. Good luck! ; http://www.lee-mac.com/selsetprocessing.html#repeat (defun c:test2 ( / e i s x ) (if (setq s (ssget)) (progn (setq i 0) (repeat (sslength s) (setq e (ssname s i) x (cdr (assoc 0 (entget e))) i (1+ i) ) (print x) ) ) ) (princ) ) 1 Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted July 19, 2022 Share Posted July 19, 2022 As dexus says... replace entsel by ssget, and iterate ... I worked it out for for you. Nice, code; I can use this myself. (defun c:divcut (/ ss i ent end div len elst) (vl-load-com) ;; user selects polylines (princ "\nSelect polylines") (setq ss (ssget (list (cons 0 "LINE,POLYLINE,LWPOLYLINE")))) ;; user sets number of cuts (setq div (getint "\nNumber of divisions: ")) (setq i 0) (while (and (setq ent (ssname ss i)) ;; (setq ent (car (entsel))) (not (vl-catch-all-error-p (setq end (vl-catch-all-apply 'vlax-curve-getEndParam (list ent)) ) ) ) (princ (strcat "\nLongueur de l'objet : " (rtos (setq len (vlax-curve-getDistAtParam ent end))) ) ) (< 0 div) (setq len (/ len div)) ) (progn (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object))) (repeat (1- div) (setq ent (cadr (CutCurveAtPoint ent (vlax-curve-getPointAtDist ent len)) ) ) ) (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object))) (setq i (+ i 1)) ) ;;(princ "\nEntité non valide") ) (princ) ) ;;;;;;;;; ;; MESCUT ;; Coupe l'objet sélectionné en tronçons de la longueur spécifiée ;;;;;;;;; (defun c:mescut (/ ss i ent end tot len div elst) (vl-load-com) ;; user selects polylines (princ "\nSelect polylines") (setq ss (ssget (list (cons 0 "LINE,POLYLINE,LWPOLYLINE")))) ;; user sets measure length (setq len (getdist "\nLength of segment: ")) (setq i 0) (while (and (setq ent (ssname ss i)) ;; (setq ent (car (entsel))) (not (vl-catch-all-error-p (setq end (vl-catch-all-apply 'vlax-curve-getEndParam (list ent)) ) ) ) (princ (strcat "\nLongueur de l'objet : " (rtos (setq tot (vlax-curve-getDistAtParam ent end))) ) ) (< 0 len) (setq div (fix (/ tot len))) ) (progn (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object))) (repeat div (setq ent (cadr (CutCurveAtPoint ent (vlax-curve-getPointAtDist ent len)) ) ) ) (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object))) (setq i (+ i 1)) ) ;;(princ "\nEntité non valide") ) (princ) ) ;; Coupe un objet curviligne au point spécifié ;; ;; Arguments ;; ent : l'objet à couper (ename ou vla-object) ;; pt : le point de coupure (coordonnées WCS) ;; ;; Retour ;; une liste des deux objets créés (ename ou vla-object) (defun CutCurveAtPoint (ent pt / vl lst cl start end ec os) (vl-load-com) (and (= (type ent) 'VLA-OBJECT) (setq ent (vlax-vla-object->ename ent) vl T ) ) (cond ((equal pt (vlax-curve-getEndPoint ent) 1e-9) (setq lst (list ent nil)) ) ((equal pt (vlax-curve-getStartPoint ent) 1e-9) (setq lst (list nil ent)) ) ((null (vlax-curve-getParamAtPoint ent pt)) (setq lst (list ent nil)) ) (T (setq start (trans (vlax-curve-getStartPoint ent) 0 1) end (trans (vlax-curve-getEndPoint ent) 0 1) ec (getvar "cmdecho") os (getvar "osmode") ) (setvar "cmdecho" 0) (setvar "osmode" 0) (if (and (wcmatch (cdr (assoc 0 (entget ent))) "*POLYLINE") (= 1 (logand 1 (cdr (assoc 70 (entget ent))))) ) (progn (command "_.break" ent (trans pt 0 1) "@") (setq cl (entlast)) ) (progn (if (= "POLYLINE" (cdr (assoc 0 (entget ent)))) (progn (entmake (entget ent)) (setq vx (entnext ent)) (while (= "VERTEX" (cdr (assoc 0 (entget vx)))) (entmake (entget vx)) (setq vx (entnext vx)) ) (entmake '((0 . "SEQEND"))) (setq cl (entlast) po T ) ) (setq cl (entmakex (entget ent))) ) (command "_.break" ent (trans pt 0 1) end) (and po (setq ent (entlast))) (command "_.break" cl start (trans pt 0 1)) (and po (setq cl (entlast))) ) ) (setvar "cmdecho" ec) (setvar "osmode" os) (setq lst (list ent cl)) ) ) (if vl (mapcar '(lambda (x) (if x (vlax-ename->vla-object x) ) ) lst ) lst ) ) 1 Quote Link to comment Share on other sites More sharing options...
Sandeep RC Posted July 19, 2022 Author Share Posted July 19, 2022 @Emmanuel Delay THANK YOU MAN. THIS IS NOW WORKING THE WAY I WANTED. TOPIC SOLVED. 1 Quote Link to comment Share on other sites More sharing options...
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.