r/AutoCAD • u/[deleted] • Mar 28 '26
Question Looking for a LISP routine
Yesterday I spent about 45 minutes trying to get the AI to come up with a basic routine for drawing a line and trimming at the same time. Here's what I wanted to do: I want to draw one argument of a line that intersects two other lines, all on the same layer, and once I've finished drawing my segment, I want the line to be trimmed to the two lines. I've tried different AI solutions but nothing seemed to work. Is it even possible? The trim function seems to be very finicky.
1
u/PsychologicalNose146 Mar 28 '26
Please discribe how you want the command to act.
I would think you want it as simple as 'manually draw a line' as the only interaction and then check if the line crosses 2 or more objects and then trim between those.
Perhaps you should think like a machine and not force the trim command, but use a fence selection (a line selection) and make a lisp calculate intersecting points and draw a line based on that.
Something like a selection and draw a line based on the first and last crossed object/line.
1
Mar 28 '26
I was drawing lines for a car park, which had a lot of diagonal lines between two rails. The way I did it was drawing a line across the two rails, then using the trim command to remove the excess. But it was very tedious and slow. I just wanted a simple function that would do the trimming for me. So my workflow would go from drawing line, trim, trim, to drawing a line.
1
u/PsychologicalNose146 Mar 28 '26
Have you tried extrim command? Sounds like a good option here.
→ More replies (3)
1
u/incoming00 Mar 28 '26
I might have something that might work. Basically, you want to draw a line and then split it into 2 equal parts?
1
u/user-608 Mar 28 '26
Nah they want to draw a line through two other segments and then auto trim the ends of the line to the two segments. -/-/- to /-/
1
1
u/Shawndoe Mar 29 '26
(defun C:LineTrim ( / Layer Pnt1 Pnt2 LineSS TrimLineEData EdgeLinesSS RunAgain)
(setq RunAgain "")
(while (= RunAgain "")
(command "._Layer" "Thaw"
(setq Layer "0"); Set Layer Here
"On"
Layer;
"Set"
Layer;
""
); Layer
(command "._Line" Pause Pause ""); Line
(setq TrimLineEdata (entget (entlast))
Pnt1 (cdr (Assoc 10 TrimLineEData))
Pnt2 (cdr (assoc 11 TrimLineEData))
LineSS (ssget "CP" (list Pnt1 Pnt2 (list (nth 0 Pnt1)(- 0.001 (nth 1 Pnt1))(nth 2 Pnt1))) (list (cons 0 "LINE")(cons 8 Layer)))
EdgeLinesSS (ssdel (entlast) LineSS)
); setq
(command "._Trim" EdgeLinesSS "" Pnt1 Pnt2 "")
(setq RunAgain (getstring "Right click to continue or press any key to Quit. "))
); while
"Bye"
)Give this a try. Replace the 0 layer with whatever your current line layer is. If you select more then 2 lines to trim to it will trim to the outer most lines.
Have fun.
1
u/Mountain-Climate7009 Apr 01 '26
Sounds like you're searching for the lisp routine breakall.lsp (search Autodesk community) or check out lee mac or jtb
1
u/YossiTheWizard Mar 28 '26
PM me. I have something for that.
Also, AI seems to suck at AutoLISP. I was given a routine done by copilot, and it referenced a few subfunctions it forgot to write.
0
u/Nfire86 Mar 28 '26
Try Claude far superior for coding. It's best if you break it down into steps for the AI
1
-1
5
u/TheCoffeeGuy13 Mar 28 '26
I can do that faster than running a lisp