View Full Version : Routine to trim a Line with half a Circle
cadd4la
2006-11-13, 09:30 PM
Hi everyone,
I am in need of a little help to get this code working right.
Everything works but the match properties part.
Background:
The code is designed to draw a circle on a existing line, have the circle match the lines properties, then trim part of the circle and the line to make what looks like an upside down "U"
Thanks
Kyle C.
(DEFUN C:LJ()
(SETVAR "CMDECHO" 0)
(princ "MACRO: MAKES A JUMPLINE FOR IRRIGATION LATERALSnPICK FIRST POINT")(COMMAND "CIRCLE" "INT" PAUSE "NEA" PAUSE "" "MATCHPROP" "" "TRIM")
(SETVAR "CMDECHO" 1)
(princ)
)
Terry Cadd
2006-11-13, 10:11 PM
I'm trying to understand your code. Look at the attached image and let me know if the example on the left or right is closer to what you are trying to achieve.
cadd4la
2006-11-13, 10:23 PM
Terry,
The one on the left is what I need.
Thanks,
Kyle C
P.S. the jump (the "U") will be either above or below the line.
CAB2k
2006-11-13, 10:58 PM
Take a look at this one
http://forums.augi.com/showthread.php?p=252575#post252575
you may need to add (vl-load-com)
Terry Cadd
2006-11-13, 11:43 PM
See if this works like you want it to.
(defun c:LJ2 (/ EntLast^ EntLayer$ EntList@ EntPick@ EntName^ EntType$ Osmode# Pt)
(setq Osmode# (getvar "OSMODE"))(setvar "OSMODE" 0)
(if (setq EntPick@ (entsel "\nSelect location on line for jumpline: "))
(progn
(setq EntName^ (car EntPick@)
EntList@ (entget EntName^)
EntType$ (cdr (assoc 0 EntList@))
EntLayer$ (cdr (assoc 8 EntList@))
);setq
(if (= EntType$ "LINE")
(progn
(setq Pt (getpoint "\nSpecify radius of circle: " (cadr EntPick@)))
(command "CIRCLE" (cadr EntPick@) (distance (cadr EntPick@) Pt))
(command "CHPROP" (entlast) "" "LA" EntLayer$ "")
(command "TRIM" (entlast) "" (cadr EntPick@) "")
(setq EntLast^ (entlast))
(setq Pt (getpoint "\nSelect side of circle to trim: "))
(command "TRIM" EntName^ EntLast^ "" Pt "")
);progn
(princ "\nNo line selected.")
);if
);progn
);if
(setvar "OSMODE" Osmode#)
(princ)
);defun c:LJ2
cadd4la
2006-11-14, 05:38 PM
Terry,
Thanks for the code but it is not working.
This is what I get:
Command: (LOAD "S:/EDGCustomFiles/LJ2.lsp") C:LJ2
Command: LJ2
Select location on line for jumpline:
No line selected.
I tried it on both lines & plines.
(defun c:LJ2 (/ EntLast^ EntLayer$ EntList@ EntPick@ EntName^ EntType$ Osmode# Pt)
(setq Osmode# (getvar "OSMODE"))(setvar "OSMODE" 0)
(if (setq EntPick@ (entsel "\nSelect location on line for jumpline: ")) <- I need to have the osmode 64 on (intersection).
(progn
(setq EntName^ (car EntPick@)
EntList@ (entget EntName^)
EntType$ (cdr (assoc 0 EntList@))
EntLayer$ (cdr (assoc 8 EntList@))
);setq
(if (= EntType$ "LINE" "PLINE") <- I added this, I use mostly plines.
(progn
(setq Pt (getpoint "\nSpecify radius of circle: " (cadr EntPick@)))<- I need to have the osmode 512 on (near) for the outside of the circle.
(command "CIRCLE" (cadr EntPick@) (distance (cadr EntPick@) Pt))
(command "CHPROP" (entlast) "" "LA" EntLayer$ "")
(command "TRIM" (entlast) "" (cadr EntPick@) "")
(setq EntLast^ (entlast))
(setq Pt (getpoint "\nSelect side of circle to trim: "))
(command "TRIM" EntName^ EntLast^ "" Pt "")
);progn
(princ "\nNo line selected.")
);if
);progn
);if
(setvar "OSMODE" Osmode#)
(princ)
);defun c:LJ2
Thanks again for the help.
Kyle
Try this. Not sure if it will work, because I haven't tested it.
(defun c:LJ2 (/ EntLast^ EntLayer$ EntList@ EntPick@ EntName^ EntType$ Osmode# Pt)
(setq Osmode# (getvar "OSMODE"))(setvar "OSMODE" 64)
(if (setq EntPick@ (entsel "\nSelect location on line for jumpline: "))
(progn
(setq EntName^ (car EntPick@)
EntList@ (entget EntName^)
EntType$ (cdr (assoc 0 EntList@))
EntLayer$ (cdr (assoc 8 EntList@))
);setq
(if (or (= EntType$ "LINE") (= EntType$ "PLINE"))
(progn
(setvar "OSMODE" 512)
(setq Pt (getpoint "\nSpecify radius of circle: " (cadr EntPick@)))
(setvar "OSMODE" 0)
(command "CIRCLE" (cadr EntPick@) (distance (cadr EntPick@) Pt))
(command "CHPROP" (entlast) "" "LA" EntLayer$ "")
(command "TRIM" (entlast) "" (cadr EntPick@) "")
(setq EntLast^ (entlast))
(setq Pt (getpoint "\nSelect side of circle to trim: "))
(command "TRIM" EntName^ EntLast^ "" Pt "")
);progn
(princ "\nNo line selected.")
);if
);progn
);if
(setvar "OSMODE" Osmode#)
(princ)
);defun c:LJ2
cadd4la
2006-11-14, 06:41 PM
Opie,
Sorry it's not working 100%
Still will not work on PLINES, will not select the intersection when it asks for you to Select location on line for jumpline and I need the line that I select with setq Pt to be always be the cut line for the trim.
Thanks,
Kyle C.
Try this. Not sure if it will work, because I haven't tested it.
(defun c:LJ2 (/ EntLast^ EntLayer$ EntList@ EntPick@ EntName^ EntType$ Osmode# Pt)
(setq Osmode# (getvar "OSMODE"))(setvar "OSMODE" 32)<- I stated the wrong osmode setting earlier.
(if (setq EntPick@ (entsel "nSelect location on line for jumpline: "))
(progn
(setq EntName^ (car EntPick@)
EntList@ (entget EntName^)
EntType$ (cdr (assoc 0 EntList@))
EntLayer$ (cdr (assoc 8 EntList@))
);setq
(if (or (= EntType$ "LINE") (= EntType$ "PLINE"))
(progn
(setvar "OSMODE" 512)
(setq Pt (getpoint "nSpecify radius of circle: " (cadr EntPick@)))
(setvar "OSMODE" 0)
(command "CIRCLE" (cadr EntPick@) (distance (cadr EntPick@) Pt))
(command "CHPROP" (entlast) "" "LA" EntLayer$ "")
(command "TRIM" (entlast) "" (cadr EntPick@) "")
(setq EntLast^ (entlast))
(setq Pt (getpoint "nSelect side of circle to trim: "))
(command "TRIM" EntName^ EntLast^ "" Pt "")
);progn
(princ "nNo line selected.")
);if
);progn
);if
(setvar "OSMODE" Osmode#)
(princ)
);defun c:LJ2
Kyle,
I had the type wrong for PLINE. It should be POLYLINE or LWPOLYLINE. There is no PLINE object type. Still, not sure about the rest of it.
Terry Cadd
2006-11-14, 06:55 PM
Replace "PLINE" with "LWPOLYLINE" and I'll take a look at the rest after lunch.
I'm starving...
Terry Cadd
2006-11-14, 08:37 PM
Ok! Here's LJ6 now at [Rev 6]. I'm going to be very busy on a project this afternoon, so if this one bombs, somebody please fix it.
(defun c:LJ6 (/ EntLast^ EntLayer$ EntList@ EntPick@ EntName^ EntType$ Osmode# Pt)
(setq Osmode# (getvar "OSMODE"))(setvar "OSMODE" 32);intersection
(if (setq EntPick@ (entsel "\nSelect location on line for jumpline: "))
(progn
(setq EntName^ (car EntPick@)
EntList@ (entget EntName^)
EntType$ (cdr (assoc 0 EntList@))
EntLayer$ (cdr (assoc 8 EntList@))
);setq
(if (or (= EntType$ "LINE") (= EntType$ "LWPOLYLINE"))
(progn
(setvar "OSMODE" 512);nearest
(setq Pt (getpoint "\nSpecify radius of circle or enter a value: " (cadr EntPick@)))
(setvar "OSMODE" 0);none
(command "CIRCLE" (cadr EntPick@) (distance (cadr EntPick@) Pt))
(command "CHPROP" (entlast) "" "LA" EntLayer$ "")
(command "TRIM" (entlast) "" (cadr EntPick@) "")
(setq EntLast^ (entlast))
(setq Pt (getpoint "\nSelect side of circle to trim: "))
(command "TRIM" EntName^ EntLast^ "" Pt "")
);progn
(princ "\nNo line or polyline selected.")
);if
);progn
);if
(setvar "OSMODE" Osmode#)
(princ)
);defun c:LJ6
cadd4la
2006-11-14, 09:07 PM
Terry,
Thanks, but it still will not pick the intersection and will not make the line that I select with "Pt" the cutting edge.
Kyle C.
Terry Cadd
2006-11-15, 12:03 AM
7's a lucky number. Right! Here the latest and greatest Rev 7.
Kyle, we should sell this one if we can ever get it working.
This one first prompts for which line for the jumpline, then prompts for the intersection.
(defun c:LJ7 (/ Cnt# EntCircle^ EntLast^ EntLayer$ EntList@ EntPick1@ EntPick2@
EntName^ EntType$ Osmode# Pt1 Pt2 Pt3 SS&)
(command "UNDO" "BEGIN")
(setq Osmode# (getvar "OSMODE"))(setvar "OSMODE" 0);none
(if (setq EntPick1@ (entsel "\nSelect a line or polyline for jumpline: "))
(progn
(setq EntName1^ (car EntPick1@)
EntList@ (entget EntName1^)
EntType$ (cdr (assoc 0 EntList@))
EntLayer$ (cdr (assoc 8 EntList@))
);setq
(setvar "OSMODE" 32);intersection
(if (setq EntPick2@ (entsel "\nSelect intersection for jumpline: "))
(progn
(setq Pt1 (osnap (cadr EntPick2@) "INT,NEA"))
(setq SS& (ssget "C" Pt1 Pt1))
(if (> (sslength SS&) 1)
(progn
(setq Cnt# 0)
(repeat (sslength SS&)
(if (not (equal (ssname SS& Cnt#) EntName1^))
(setq EntName2^ (ssname SS& Cnt#))
);if
(setq Cnt# (1+ Cnt#))
);repeat
);progn
(setq EntName2^ EntName1^)
);if
(if (or (= EntType$ "LINE") (= EntType$ "LWPOLYLINE"))
(progn
(setvar "OSMODE" 512);nearest
(setq Pt2 (getpoint "\nSpecify radius of circle or enter a value: " Pt1))
(setvar "OSMODE" 0);none
(command "CIRCLE" Pt1 (distance Pt1 Pt2))
(setq EntCircle^ (entlast))
(command "CHPROP" EntCircle^ "" "LA" EntLayer$ "")
(if (not (equal EntName1^ EntName2^))
(entdel EntName2^)
);if
(command "TRIM" EntCircle^ "" Pt1 "")
(setq EntLast^ (entlast))
(setq Pt3 (getpoint "\nSelect side of circle to trim: "))
(command "TRIM" EntName1^ EntLast^ "" Pt3 "")
(if (not (equal EntName1^ EntName2^))
(entdel EntName2^)
);if
);progn
(princ "\nNo line or polyline selected.")
);if
);progn
);if
);progn
);if
(setvar "OSMODE" Osmode#)
(command "UNDO" "END")
(princ)
);defun c:LJ7
cadd4la
2006-11-15, 01:38 AM
Terry,
Looks to be working but I was a little scared when the line I was jumping disappeared when I was trimming, then I hit enter and it came back.
Thanks for all your help.
Kyle C.
Terry Cadd
2006-11-15, 07:17 AM
Ok, this is the one! No hiding lines in a selection set, and it defaults the radius to the previous radius. Drafting has been doing these steps manually for years at my job. I can see how it can apply to other applications such as electronic schematics. Thank you for your request that may help others.
(defun c:LJ (/ EntLayer$ EntList@ EntName^ EntPick@ EntType$ Osmode# Pt1 Pt2 Pt3 Pt4 Pt5)
(princ "\nLine Jump")
(command "UNDO" "BEGIN")
(setq Osmode# (getvar "OSMODE"))(setvar "OSMODE" 0);none
(if (setq EntPick@ (entsel "\nSelect a line or polyline for Line Jump: "))
(progn
(setq Pt1 (osnap (cadr EntPick@) "NEA")
EntName^ (car EntPick@)
EntList@ (entget EntName^)
EntType$ (cdr (assoc 0 EntList@))
EntLayer$ (cdr (assoc 8 EntList@))
);setq
(setvar "OSMODE" 544);intersection,nearest
(if (setq Pt2 (getpoint "\nSelect intersection for Line Jump: "))
(progn
(if (or (= EntType$ "LINE") (= EntType$ "LWPOLYLINE"))
(progn
(if (not *LJRadius~)
(setq *LJRadius~ (distance Pt1 Pt2))
);if
(setvar "OSMODE" 512);nearest
(if (setq Pt3 (getpoint (strcat "\nSpecify radius of circle <" (rtos *LJRadius~ 2 3) ">: ") Pt2))
(setq *LJRadius~ (distance Pt2 Pt3))
);if
(setq Pt4 (polar Pt2 (angle Pt2 Pt1) (/ *LJRadius~ 2.0)))
(setvar "OSMODE" 0);none
(command "CIRCLE" Pt2 *LJRadius~)
(command "CHPROP" (entlast) "" "LA" EntLayer$ "")
(command "TRIM" (entlast) "" Pt4 "")
(setvar "OSMODE" 512);nearest
(setq Pt5 (getpoint "\nSelect side of circle to trim: "))
(command "TRIM" EntName^ (entlast) "" Pt5 "")
);progn
(princ "\nNo line or polyline selected.")
);if
);progn
);if
);progn
(princ "\nNo line or polyline selected.")
);if
(setvar "OSMODE" Osmode#)
(command "UNDO" "END")
(princ)
);defun c:LJ
cadd4la
2006-11-19, 06:14 AM
Terry,
The code works 100%, just the way I need it to run and them some.
Thank you
Kyle C.:)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.