I have 2D/3D error while running this lisp

I have 2D/3D error while running this lisp

keivankarbasian
Observer Observer
532 Views
7 Replies
Message 1 of 8

I have 2D/3D error while running this lisp

keivankarbasian
Observer
Observer


(defun c:plpx (/ ss ssl mylist k ssn ent cord i)
(setq ss (ssget '((0 . "point"))))

(setq ssl (sslength ss))
(setq mylist nil)
(setq k 0)
(while (< k ssl)
(setq ssn (ssname ss k))
(setq ent (entget ssn))
(setq cord (cdr (assoc 10 ent)))
(setq mylist (append (list cord) mylist))
(setq k (1+ k))
) ;while

(setq i 0)
(setq len (length mylist))
(while (<= i len )
(if (/= mylist nil)
(append

(entmake (list
(cons 0 "polyline")
(cons 66 1)
(cons 70 😎
)
) ;entmake
(entmake (list
(cons 0 "VERTEX")
(cons 100 "AcDbEntity")
(cons 100 "AcDbVertex")
(cons 100 "AcDb3dPolylineVertex")
(cons 10 (nth i mylist))
(cons 73 0)
(cons 70 32)
(cons 50 0)
)
)
(entmake (list
(cons 0 "VERTEX")
(cons 100 "AcDbEntity")
(cons 100 "AcDbVertex")
(cons 100 "AcDb3dPolylineVertex")
(cons 10 (nth (+ i 1) mylist))
(cons 73 0)
(cons 70 32)
(cons 50 0)
)
)
(entmake (list
(cons 0 "SEQEND")
)
)
) ;append

 


) ;if
(setq i (1+ i))

) ;while


)

0 Likes
533 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

Try instead of

(setq mylist nil)

Use

(setq mylist ‘())


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 8

Kent1Cooper
Consultant
Consultant

@paullimapa wrote:

Try instead of

(setq mylist nil)

Use

(setq mylist ‘())


That's no different.  A list with nothing in it is not an empty list, but is merely nothing:

(setq mylist '())
nil

!mylist
nil

(type mylist)
nil

(length mylist)

0

might make you think it qualifies as a list, but "having a length" of zero doesn't mean it's a list -- it's true for any nil item:

(length MarilynMonroe)

0

Kent Cooper, AIA
0 Likes
Message 4 of 8

Kent1Cooper
Consultant
Consultant

The smiley-with-sunglasses represents an 8 followed by a right parenthesis.  Anyone who wants to try the code needs to make that correction.  [I have complained multiple times about the fact that the website does that.]

 

How far does it get?  If you temporarily comment out the localizing of variables:

(defun c:plpx ();/ ss ssl mylist k ssn ent cord i)

so that the variables will survive after the routine has run, do all those variables get values set into them?

Kent Cooper, AIA
0 Likes
Message 5 of 8

paullimapa
Mentor
Mentor

try this code...I moved things around and that seems to work

; plpx function creates 3dpline based on points selected
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/i-have-2d-3d-error-while-running-this-lisp/m-p/11668826#M441752
(defun c:plpx (/ ss ssl mylist k ssn ent cord i)
(setq ss (ssget '((0 . "point"))))

(setq ssl (sslength ss))
(setq mylist nil pln nil)
(setq k 0)
(while (< k ssl)
(setq ssn (ssname ss k))
(setq ent (entget ssn))
(setq cord (cdr (assoc 10 ent)))
(setq mylist (append (list cord) mylist))
(setq k (1+ k))
) ;while

(if (/= mylist nil)
  (progn
    (setq i 0)
    (setq len (length mylist))
    
(entmake 
(list
(cons 0 "polyline")
(cons 66 1)
(cons 70 8)
)
)

(while (< i len )
(entmake
(list
(cons 0 "VERTEX")
(cons 100 "AcDbEntity")
(cons 100 "AcDbVertex")
(cons 100 "AcDb3dPolylineVertex")
(cons 10 (nth i mylist))
(cons 73 0)
(cons 70 32)
(cons 50 0)
)
)
(setq i (1+ i))
) ;while
    
(entmake
(list
(cons 0 "SEQEND")
)
)
  ) ; progn
) ;if
) ; defun

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 8

paullimapa
Mentor
Mentor

for some reason I had in mind that before append function can be used the symbol for the list needed to be initialized which apparently is a wrong assumption.

now in this case perhaps (setq mylist nil) line of code can even be removed since mylist has already be declared local at defun?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant

@paullimapa wrote:

.... now in this case perhaps (setq mylist nil) line of code can even be removed since mylist has already be declared local at defun?


Absolutely [and also 'pln' in the code in Message 5, which is not used].

Kent Cooper, AIA
0 Likes
Message 8 of 8

paullimapa
Mentor
Mentor

O yes, pln should be removed...I added that when I was testing & forgot to get rid of it...good catch.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes