I am trying to create a small program where you draw a polyline, and then it uses (entget (entlast)) to get the DXF info from that polyline.
What should happen is that the DXF info should contain an x,y coordinate for each vertex in the polyline with the DXF code 10. But when I run my code, it only gives one line where the DXF code is 10. The weird thing is that when I run each line individually, it works exactly as expected. Or when I use (entget (car (entsel))) and select the polyline, it works fine.
Here is the code:
(defun c:ra ()
(setq outlist nil) ; initiate empty list of vertex coordinates
(command "pline" pause); draw polyline
(setq object (entget (entlast))) ; get DXF data
(setq count 0)
(repeat (length object)
(setq item (nth count object))
(if (= (car item) 10) ; is the item in the DXF list a vertex?
(setq outlist (cons (cdr item) outlist)) ; add vertex to list
)
(setq count (+ 1 count))
)
(setq outlist (reverse outlist)) ; properly order list
(setq count 0)
(repeat (length outlist)
(prompt "\n")(princ (nth count outlist))(princ)
(setq count (+ 1 count))
)
)
This code is searching through the DXF info line by line and adding each instance of a code 10 to a list, so it gets a list of vertices. But the list is only being generated with a length of 1.
Does anyone know how to fix this? Or why it's behaving differently when I run the whole code vs. running it one line at a time?