- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I've never used LISP before. Know a bit of programmation. Recently got the courage to try some AutoLisp thanks to ChatGPT. Sadly there are some limitation to it (most of his suggestion gets me into errors).
Basically I've tried to create a multiple-lines-div tool, because the div command is great but only for one line at the time, and I usually need to perform it on about 200 lines at the time. I've came up with this code below. The function was working well on VLIDE for a couple of days. Than I restarted AutoCAD and used Appload to showcase the function to a collegue, and as predictable, it was not working anymore.
Better explained, the function actually runs, I select the lines, I select the amount of divisions I want to do, the function runs, I can actually track the points being correctly calculated on VLIDE watch. But the function always ends with 3 points (startpoint, midpoint, endpoint) no matter what I entered and I get a error message of this kind:
- Unknown command "MULT-DIV". Press F1 for help.
- Command: <Selection set: 17>
Feel free to share with me a solution that someone already did 20 years ago. It seems to me that this function should be integrated to ACAD. Anyway, here is the code:
(defun c:mult-div ()
(setq ss (ssget '((0 . "LINE")))) ; Select all lines
(if (zerop (sslength ss))
(princ "\nNo lines selected.") ; No lines found
(progn
(setq numlines (sslength ss)) ; Get the number of selected lines
(setq div-count (getint "\nEnter the number of divisions: ")) ; Prompt user for division count
(repeat numlines
(setq line (vlax-ename->vla-object (ssname ss 0))) ; Get the first line from the selection set
(setq startpt (vlax-curve-getstartpoint line)) ; Get the start point of the line
(setq endpt (vlax-curve-getendpoint line)) ; Get the end point of the line
; Calculate the x-distance and y-distance for dividing the line into divisions
(setq x-dist (/ (- (car endpt) (car startpt)) div-count))
(setq y-dist (/ (- (cadr endpt) (cadr startpt)) div-count))
; Create points at the intermediate positions based on the division count
(setq count 0)
(repeat (1- div-count)
(setq pt (list (+ (car startpt) (* x-dist (1+ count))) (+ (cadr startpt) (* y-dist (1+ count)))))
(command "_.point" pt "")
(setq count (1+ count)) ; Increament the inner iteration count
)
(setq ss (ssdel (ssname ss 0) ss)) ; Remove the processed line from the selection set
)
)
)
)
Solved! Go to Solution.