TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jermjmm on October 03, 2007, 04:14:49 PM
-
I found a lisp (somewhere on the net don't remember where) and modified it to suit my needs, but I'm pretty new to lisp. the one thing that I don't remember how to do is to make it loop until I want to quit, the only way I can think to do it is to put a (c:bv) line at the end which I know is wrong. :|
(defun c:bv ( / brkdist osmode entpt ename ang pt pt1 pt2 )
(setq brkdist (* (getvar "dimscale") 0.03125))
(setq osmode (getvar "osmode"))
(setvar "osmode" 512)
(setq entpt (getpoint "\nSelect Line "))
(setq ename (ssname (ssget "c" entpt entpt) 0))
(if
(or
(= (cdr (assoc 0 (entget ename))) "LWPOLYLINE")
(= (cdr (assoc 0 (entget ename))) "POLYLINE")
(= (cdr (assoc 0 (entget ename))) "LINE")
)
(progn
(redraw ename 3)
(setvar "osmode" 32)
(setq
pt (getpoint "\nSelect Intersection ")
ang (angle entpt pt)
pt1 (polar pt (+ pi ang) brkdist)
pt2 (polar pt1 ang (* 2 brkdist))
)
(redraw ename 4)
(command "break" ename pt1 pt2)
);end progn
(progn
(alert "Object selected is not a Line or Polyline")
(exit)
);end progn
);end if
(setvar "osmode" osmode)
(princ)
)
<edit: code tags added>
-
Perhaps use while:
(defun c:bv (/ d ent obj pt2 pt3)
(vl-load-com)
(while (and (setq ent (entsel "\n Select intersection to break: "))
(/= (cdr (assoc 0 (entget (car ent)))) "INSERT")
)
(progn
(setq obj (vlax-ename->vla-object (car ent))
d (vlax-curve-getDistAtPoint
obj
(vlax-curve-getClosestPointTo obj (cadr ent))
)
pt2 (vlax-curve-getPointAtDist
obj
(+ d (* (getvar 'dimscale) 0.03125))
)
pt3 (vlax-curve-getPointAtDist
obj
(- d (* (getvar 'dimscale) 0.03125))
)
)
(if (and pt2 pt3)
(if
(member (cdr (assoc 0 (entget (car ent))))
'("LWPOLYLINE" "POLYLINE" "LINE")
)
(command ".break" ent "f" pt2 pt3)
)
)
)
)
)
-
Here is another example of using the while loop.
http://forums.augi.com/showthread.php?p=764031&postcount=24
-
Give this a whirl....eliminates a few picks for you (if I understand what you are trying to achieve):
(defun c:bv (/ d ent obj pt2 pt3)
(while (and (setq ent (entsel "\n Select intersection to break: "))
(/= (cdr (assoc 0 (entget (car ent)))) "INSERT")
)
(progn
(setq obj (vlax-ename->vla-object (car ent))
d (vlax-curve-getDistAtPoint
obj
(vlax-curve-getClosestPointTo obj (cadr ent))
)
pt2 (vlax-curve-getPointAtDist
obj
(+ d (* (getvar 'dimscale) 0.03125))
)
pt3 (vlax-curve-getPointAtDist
obj
(- d (* (getvar 'dimscale) 0.03125))
)
)
(if (and pt2 pt3)
(if
(member (cdr (assoc 0 (entget (car ent))))
'("LWPOLYLINE" "POLYLINE" "LINE")
)
(command ".break" ent "f" pt2 pt3)
)
)
)
)
)
-
HOLLY FREHOLLIES! I actually learned something today! guess that means I can go home now? (I wish). Don't know if it's propper programming but this is what I came up with and it works:
(defun c:bv2 ( / brkdist osmode entpt ename ang pt pt1 pt2 )
(setq brkdist (* (getvar "dimscale") 0.03125))
(setq osmode (getvar "osmode"))
(setvar "osmode" 512)
(WHILE (setq entpt (getpoint "\nSelect Line "))
(setq ename (ssname (ssget "c" entpt entpt) 0))
(if
(or
(= (cdr (assoc 0 (entget ename))) "LWPOLYLINE")
(= (cdr (assoc 0 (entget ename))) "POLYLINE")
(= (cdr (assoc 0 (entget ename))) "LINE")
)
(progn
(redraw ename 3)
(setvar "osmode" 32)
(setq
pt (getpoint "\nSelect Intersection ")
ang (angle entpt pt)
pt1 (polar pt (+ pi ang) brkdist)
pt2 (polar pt1 ang (* 2 brkdist))
)
(redraw ename 4)
(command "break" ename pt1 pt2)
);end progn
(progn
(alert "Object selected is not a Line or Polyline")
(exit)
);end progn
);end if
(setvar "osmode" 512)
)
(setvar "osmode" osmode)
(princ)
)
thanks again!
<edit: code tags added>
-
tryed to use yours and it comes back no function definition: ENT_SEL
Give this a whirl....eliminates a few picks for you (if I understand what you are trying to achieve):
(defun c:bv (/ d ent obj pt pt2 pt3)
(while (and (setq ent (ent_sel "\n Select intersection to break: "))
(/= (cdr (assoc 0 (entget (car ent)))) "INSERT")
)
(progn
(setq obj (vlax-ename->vla-object (car ent))
pt (vlax-curve-getClosestPointTo obj (cadr ent))
d (vlax-curve-getDistAtPoint obj pt)
pt2 (vlax-curve-getPointAtDist
obj
(+ d (* (getvar 'dimscale) 0.03125))
)
pt3 (vlax-curve-getPointAtDist
obj
(- d (* (getvar 'dimscale) 0.03125))
)
)
(if (and pt2 pt3)
(progn
(if
(member (cdr (assoc 0 (entget (car ent))))
'("LWPOLYLINE" "POLYLINE" "LINE")
)
(command "._break" ent "f" pt2 pt3)
)
)
)
)
)
)
-
Sorry about that...try it now.
-
not quite, what I am doing is drawing plumbing piping (2d only) and I use this command to break one of the lines to graphically represent which one is higher and which one is lower. but thanks anyway I did learn from your help earlier.
-
Well glad you got something out of it :) welcome to the swamp. Here is one that inserts a "hop"....maybe you'll find a use for it.
(defun c:bv (/ d ent obj pt2 pt3 e)
(vl-load-com)
(while (and (setq ent (entsel "\n Select intersection to break: "))
(/= (cdr (assoc 0 (entget (car ent)))) "INSERT")
)
(progn
(setq obj (vlax-ename->vla-object (car ent))
e (entget (car ent))
d (vlax-curve-getDistAtPoint
obj
(vlax-curve-getClosestPointTo obj (cadr ent))
)
pt2 (vlax-curve-getPointAtDist
obj
(+ d (* (getvar 'dimscale) 0.03125))
)
pt3 (vlax-curve-getPointAtDist
obj
(- d (* (getvar 'dimscale) 0.03125))
)
)
(if (and pt2 pt3)
(if (member (cdr (assoc 0 e))
'("LWPOLYLINE" "POLYLINE" "LINE")
)
(progn
(command "_.break" ent "f" pt2 pt3)
(entmake
(list '(0 . "LWPOLYLINE")
(cons 100 "AcDbEntity")
(cons 8 (cdr (assoc 8 e)))
(cons 100 "AcDbPolyline")
(cons 90 2)
(cons 43
(if (assoc 43 e)
(cdr (assoc 43 e))
0.0
)
)
(cons 10 pt2)
(cons 42 1.0)
(cons 10 pt3)
)
)
)
)
)
)
)
)