Author Topic: lisp loop  (Read 2144 times)

0 Members and 1 Guest are viewing this topic.

jermjmm

  • Guest
lisp loop
« 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. :|

Code: [Select]
(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>
« Last Edit: October 03, 2007, 04:24:06 PM by CAB »

ronjonp

  • Needs a day job
  • Posts: 7529
Re: lisp loop
« Reply #1 on: October 03, 2007, 04:19:46 PM »
Perhaps use while:

Code: [Select]
(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)
)
      )
    )
  )
)
« Last Edit: October 03, 2007, 04:50:29 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: lisp loop
« Reply #2 on: October 03, 2007, 04:32:46 PM »
Here is another example of using the while loop.
http://forums.augi.com/showthread.php?p=764031&postcount=24
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: lisp loop
« Reply #3 on: October 03, 2007, 04:42:12 PM »
Give this a whirl....eliminates a few picks for you (if I understand what you are trying to achieve):

Code: [Select]
(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)
)
      )
    )
  )
)
« Last Edit: October 03, 2007, 04:48:05 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jermjmm

  • Guest
Re: lisp loop
« Reply #4 on: October 03, 2007, 04:43:21 PM »
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:

Code: [Select]
(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>
« Last Edit: October 03, 2007, 05:33:37 PM by CAB »

jermjmm

  • Guest
Re: lisp loop
« Reply #5 on: October 03, 2007, 04:45:40 PM »
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):

Code: [Select]
(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)
  )
)
      )
    )
  )
)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: lisp loop
« Reply #6 on: October 03, 2007, 04:48:21 PM »
Sorry about that...try it now.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jermjmm

  • Guest
Re: lisp loop
« Reply #7 on: October 03, 2007, 04:53:33 PM »
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.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: lisp loop
« Reply #8 on: October 03, 2007, 05:04:19 PM »
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.

Code: [Select]
(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)
      )
    )
  )
)
      )
    )
  )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC