Autolisp - Drawing pline using coords list and storing distances as list

Autolisp - Drawing pline using coords list and storing distances as list

Anonymous
Not applicable
946 Views
3 Replies
Message 1 of 4

Autolisp - Drawing pline using coords list and storing distances as list

Anonymous
Not applicable

Hi,

I am trying to create a lisp routine that will get co-ordinates from a user's input. These will be stored as a list and a Polyline will be drawn through the list co-ordinates. also, I want to obtain the individual lengths of the Polyline.

 

I have started a basic routine but understand that the coding is probably really amateurish. Any help would be greatly appreciated, thanks in advanced.

 

(defun c:X ()
(while
 (setq pt (getpoint))
 (setq ptlist (append ptlist (list pt)))
)
(while
 (setq dist (distance (car ptlist) (cadr ptlist))
 (setq distlist (append distlist (list dist)))
 (setq ptlist (vl-remove (nth 0 ptlist) ptlist))
)
(princ)
)

0 Likes
Accepted solutions (1)
947 Views
3 Replies
Replies (3)
Message 2 of 4

Ranjit_Singh
Advisor
Advisor
Accepted solution

Welcome to the forums! Just fyi, there is a dedicated forum for LISP customization here. Try below code as an example. Note that lst variable has not been localized, in case you want to access the co-ordinates list. Also searching through the LISP forums, you may find plenty of such routines.

(defun c:somefunc  (/ i n vlaobj)
 (command "._pline")
 (while (/= 0 (getvar 'cmdactive)) (command pause))
 (print
  (setq lst (reverse (cdr (reverse (vl-remove-if-not 'listp (mapcar 'cdr (entget (entlast)))))))))
 (setq vlaobj (vlax-ename->vla-object (entlast))
       i      1
       n      (vlax-curve-getendparam vlaobj))
 (while (<= i n) (print (vlax-curve-getdistatparam vlaobj i)) (setq i (1+ i))))
0 Likes
Message 3 of 4

Kent1Cooper
Consultant
Consultant

Welcome to these Forums!

 

@Ranjit_Singh's suggestion looks to me [on quick perusal] as though it will report the total cumulative length so far along the Polyline at each vertex.  Is that what you need, or do you need the length of each segment?

 

[And by the way, that 'vlaobj' variable is not needed.  The (vlax-curve-....) functions will work with just an entity name, and don't require conversion to a VLA object, so you can either save (entlast) into a variable directly and use that, or just use (entlast) itself in each case.]

Kent Cooper, AIA
0 Likes
Message 4 of 4

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:


... (vl-remove (nth 0 ptlist) ptlist)

 


This massive expression is the same as simple  

 

(cdr ptlist)

0 Likes