Jump to content

HOW CAN I GET THIS LISP TO WORK ON MULTIPLE POLYLINES AT THE SAME TIME?


Recommended Posts

Posted

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

Posted

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

 

  • Like 1
Posted

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

 

  • Like 1
Posted

@Emmanuel Delay 

 

THANK YOU MAN. THIS IS NOW WORKING THE WAY I WANTED. TOPIC SOLVED.

 

  • Like 1

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