- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good day all,
I've been sharpening my ax and I've almost created a functioning program, so close but so far.
I'm struggling to create a loop that goes through a vertices list and converts them to angles.
What I'm trying to do (visualized, I'm just trying to make a list that is usable in lisp):
This is what I've done so far:
(defun rtd (a)
(/ (* a 180.0) pi)
)
(while
(and
(setq pt1 (car ptlist) pt2 (cadr ptlist))
);and
(setq ang1 (angle pt1 pt2))
(setq AngLst (abs rtd ang1))
(setq ptlist (cdr ptlist))
);while
And this is where the code will be placed, right below
;------------------------------
;Angle list
In the place of - (setq AngLst '(180 175 170 163 170 90 63))
(defun C:CoordList (/ plent plobj coords num pt Ang1 Ang2 Ang3 AngLst pt1 pt2 pt3 ptlist Dif1 Dif2)
(setq
plent (car (entsel "\nSelect Polyline: "))
plobj (vlax-ename->vla-object plent)
coords (vlax-get plobj 'Coordinates); un-differentiated list of X Y [& Z if applicable] coordinate values
); setq
(setq num (if (= (cdr (assoc 0 (entget plent))) "LWPOLYLINE") 2 3))
; LW Polylines have only X & Y; "heavy" 2D & 3D have X Y & Z
(repeat (/ (length coords) num)
(repeat num ; number of coordinates to separate into a point list
(setq
pt (append pt (list (car coords)))
coords (cdr coords)
)
); repeat
(setq
ptlist (cons pt ptlist); put that point into list of points
pt nil ; reset for next point
); setq
); repeat
(setq ptlist (reverse ptlist)); list of coordinates divided up into point lists
;; The above was originally made by Kent1Cooper https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pick-a-polyline-and-create-a-list-of-its-coordinates/td-p/4934230
;; PS he is a legend
;------------------------------
;Angle list
;It depends on your "Angle" of approach
(setq AngLst '(180 175 170 163 170 90 63))
;------------------------------
;Insert the first pole
(command "insert" "5m 150-175" (car ptlist) "" "")
;------------------------------
;Insert the last pole
(command "insert" "5m 150-175" (last ptlist) "" "")
;------------------------------
;Insert the poles in between
;That's what she said....anyway code is below....the belt
(while
(and
(setq
Ang1 (car AngLst)
Ang2 (cadr AngLst)
Ang3 (caddr AngLst)
);setq
(setq
pt1 (car ptlist)
pt2 (cadr ptlist)
pt3 (caddr ptlist))
(setq
Dif1 (- Ang1 Ang2);This is to determine angle difference between ponit 1&2
Dif2 (- Ang2 Ang3);This is to determine angle difference between ponit 2&3
);setq
);and
; "IF" there is a better way to do the below script please let me know, sorry "IF" it looks a bit "IF"fy
(if (>= Dif1 -15);1st angle constriction
(progn
(if (<= Dif1 15);2nd angle constriction
(progn
(if (<= Dif2 15);3rd angle constriction
(progn
(if (>= Dif2 -15);4th angle constriction
(progn
(command "insert" "5m 100-125" pt2 "" "")
);progn
(progn
(command "insert" "5m 150-175" pt2 "" "")
);progn
);4th layer of IF function
);progn
(progn
(command "insert" "5m 150-175" pt2 "" "")
);progn
);3rd layer IF function
);progn
(progn
(command "insert" "5m 150-175" pt2 "" "")
);progn
);2nd layer IF function
);progn
(progn
(command "insert" "5m 150-175" pt2 "" "")
);progn
);1st layer IF function
(setq ptlist (cdr ptlist));This will set the next point in the list for the loop
(setq AngLst (cdr AngLst));This will set the next angle in the list for the loop
);while
(princ);Everytime I see this I think of princles, maybe I was born to be fat.
);defun
So in short what this routine does, you select a polyline and a block will be on each vertices, the type of block will be determined by the angle of each vertices.
So far the whole experience feels like I'm giving birth, long and painful, but in the end it will be worth it! Though I do believe the code can be optimized especially at the "if" functions.
I would really appreciate any input! This is my first lisp, though I did use one of @Kent1Cooper routines to determine the polyline vertices
Solved! Go to Solution.