Hello all. I am a newbie at AutoLisp, so please forgive inefficient and poorly formatted code with non-existent error trapping.
I am trying to write a code that will allow a user to select a polyline and apply a smooth uniform taper to a desired number of vertices. Similar to something like this from briscad:
The problem is when I apply the start and end width to any assoc 40 or 41, it applies it to all of them when I use entmod, sort of like a global taper for each segment. Am I doing something wrong, or is this not possible with autolisp?
Thanks in advance for any help. See commented code below.
(defun c:stp (/ ent elist n nn at vtx stwid endwid curwid factor)
(setq ent (car (entsel)))
(setq vtx (getint "\nNumber of vertexs: "));number of vertexes to apply smooth taper
(setq stwid (getreal "\nStart Width: "));start width of taper
(setq endwid (getreal "\nEnd Width: "));end width of taper
(setq curwid stwid);curwid will be the width applied to each end during while loop,
(setq factor (/ (- stwid endwid) vtx));subtract the factor from the width after each pass to ensure a smooth and even taper
(setq elist (entget ent))
(setq n 0);counter to iterate through all objects in list
(setq nn 0);seperate counter that counts start and end widths (40's and 41's)
(while (< nn vtx);while vertex counter is less than the number of vertexes supplied by user
(setq at (car (nth n elist)));get the nth item in list
(cond
((= at 40);if item is 40...
(setq elist (subst (cons 40 curwid) (nth n elist) elist));...set it to current width
(setq curwid (- curwid factor)));reduce current width by factor
((= at 41);if item is 41...
(setq elist (subst (cons 41 curwid) (nth n elist) elist));...set it to current width that has been reduced by factor
(setq nn (1+ nn)));increment vertex counter
);endcond
(setq n (1+ n));increment overall item counter
);end while
(setq elist (vl-remove (assoc 43 elist) elist));remove 43 (global width) or else segement widths will not update
(entmod elist);update ent
(entupd ent)
(princ)
);end of function