error: bad argument type: lselsetp nil

error: bad argument type: lselsetp nil

Anonymous
Not applicable
1,539 Views
5 Replies
Message 1 of 6

error: bad argument type: lselsetp nil

Anonymous
Not applicable

;;ple.lsp
(vl-load-com)
(defun c:ple (/ elist en i layer layer_list
leng pline row ss sumlen total
x xlApp xlBook xlBooks xlCells xlSheet
xlSheets
)

(setq xlApp (vlax-get-or-create-object "Excel.Application")
xlBooks (vlax-get-property xlApp "Workbooks")
xlBook (vlax-invoke-method xlBooks "Add")
xlSheets (vlax-get-property xlBook "Sheets")
xlSheet (vlax-get-property xlSheets "Item" 1)
xlCells (vlax-get-property xlSheet "Cells")
)
(vla-put-visible xlApp :vlax-true)
;headers
(vlax-put-property xlCells "Item" 1 1 "NO")
(vlax-put-property xlCells "Item" 1 2 "LAYER")
(vlax-put-property xlCells "Item" 1 3 "PANJANG (MTR)")

(setq row 2
total 0)

(setq ss (ssget "_X" (list (cons 0 "LWPOLYLINE"))) i -1)
(repeat (sslength ss)
(setq en (ssname ss (setq i (1+ i)))
elist (entget en)
layer (cdr (assoc 8 elist)))
(if (not (member layer layer_list))
(setq layer_list (cons layer layer_list)))
)

(repeat (length layer_list)
(setq layer (car layer_list))
(setq ss (ssget "_X" (list (cons 0 "LWPOLYLINE")(cons 8 layer))) i -1 sumlen 0)
(repeat (sslength ss)
(setq pline (vlax-ename->vla-object (ssname ss (setq i (1+ i)))))
(setq leng (vlax-curve-getdistatparam pline
(vlax-curve-getendparam pline)))
(setq sumlen (+ sumlen leng)))
(vlax-put-property xlCells "Item" row 1 (1- row))
(vlax-put-property xlCells "Item" row 2 layer)
(vlax-put-property xlCells "Item" row 3 (rtos (/ sumlen 1000) 2 2))
(setq total (+ total sumlen))
;;; (vlax-put-property xlCells "Item" row 2 (rtos (/ sumlen 1000) 2 2)); for metric units
(setq layer_list (cdr layer_list))
(setq row (+ row 1))
)
(setq row (+ row 1))
; footers:
(vlax-put-property xlCells "Item" row 2 "TOTAL:")
(vlax-put-property xlCells "Item" row 3 (rtos (/ total 1000) 2 2))
(vlax-put-property xlCells "Item" row 4 "MTR")
;;;(vlax-put-property xlCells "Item" row 3 (rtos (/ total 1000) 2 2)); for metric units

(mapcar (function (lambda(x)
(vl-catch-all-apply
(function (lambda()
(progn
(vlax-release-object x)
(setq x nil)))))))
(list xlCells xlSheet xlSheets xlBook xlBooks xlApp)
)
(alert "Simpan dan tutup file nya manual")
(alert "Bud's Colletion.......")
(gc)(gc)
(princ)
)
(princ "\t\t***\t Type PLE untuk disimpan di Excel\t***")
(princ "\t\t***\t Bud's Colletion......\t***")
(princ)

0 Likes
Accepted solutions (1)
1,540 Views
5 Replies
Replies (5)
Message 2 of 6

cadffm
Consultant
Consultant
Accepted solution

change

 

(setq ss (ssget "_X" (list (cons 0 "LWPOLYLINE"))) i -1)
(repeat (sslength ss)

xxxx

)

 

 

to

 

(if (setq  i -1 ss (ssget "_X" (list (cons 0 "LWPOLYLINE"))))
(repeat (sslength ss)

xxxx

)

)

 

And the same with your other ssget line:

 

(if (setq  i -1 sumlen 0 ss (ssget "_X" (list (cons 0 "LWPOLYLINE")(cons 8 layer))))

     (repeat

       xxx

     )

)

 

 

Perhaps your drawing contains only "2D-POLYLINE" or no polyline objects..

SSNAME want a selectionset, nothing else, otherwise it crash by the message "error: bad argument type: lselsetp"

If the parameter is nil, "the error function returns error: bad argument type: lselsetp nil"

nil, nothing in list = no selectionset created = no "LWPOLYLINE" in your drawing on this layer

Sebastian

0 Likes
Message 3 of 6

ronjonp
Mentor
Mentor

You should use a function that checks for a valid selection set. Also .. I think something is weird here:

  ;; This should be 'foreach' ??
  (repeat (length layer_list)
    ;; This line always returns the same result ??
    (setq layer (car layer_list))
;;ple.lsp
(vl-load-com)
(defun c:ple (/	       elist	en	 i	  layer	   layer_list	     leng     pline
	      row      ss	sumlen	 total	  x	   xlapp    xlbook   xlbooks  xlcells
	      xlsheet  xlsheets
	     )
  ;; Make a function that checks if the selection is valid
  (defun _ss2list (ss)
    (if	(= 'pickset (type ss))
      (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
    )
  )
  (setq	xlapp	 (vlax-get-or-create-object "Excel.Application")
	xlbooks	 (vlax-get-property xlapp "Workbooks")
	xlbook	 (vlax-invoke-method xlbooks "Add")
	xlsheets (vlax-get-property xlbook "Sheets")
	xlsheet	 (vlax-get-property xlsheets "Item" 1)
	xlcells	 (vlax-get-property xlsheet "Cells")
  )
  (vla-put-visible xlapp :vlax-true)	;headers
  (vlax-put-property xlcells "Item" 1 1 "NO")
  (vlax-put-property xlcells "Item" 1 2 "LAYER")
  (vlax-put-property xlcells "Item" 1 3 "PANJANG (MTR)")
  (setq	row 2
	total 0
  )
  (foreach en (_ss2list (ssget "_X" (list (cons 0 "LWPOLYLINE"))))
    (setq elist	(entget en)
	  layer	(cdr (assoc 8 elist))
    )
    (if	(not (member layer layer_list))
      (setq layer_list (cons layer layer_list))
    )
  )
  ;; This should be 'foreach' ??
  (repeat (length layer_list)
    ;; This line always returns the same result ??
    (setq layer (car layer_list))
    (setq sumlen 0)
    (foreach e (_ss2list (ssget "_X" (list (cons 0 "LWPOLYLINE") (cons 8 layer))))
      (setq pline (vlax-ename->vla-object e))
      (setq leng (vlax-curve-getdistatparam pline (vlax-curve-getendparam pline)))
      (setq sumlen (+ sumlen leng))
    )
    (vlax-put-property xlcells "Item" row 1 (1- row))
    (vlax-put-property xlcells "Item" row 2 layer)
    (vlax-put-property xlcells "Item" row 3 (rtos (/ sumlen 1000) 2 2))
    (setq total (+ total sumlen))
;;; (vlax-put-property xlCells "Item" row 2 (rtos (/ sumlen 1000) 2 2)); for metric units
    (setq layer_list (cdr layer_list))
    (setq row (+ row 1))
  )
  (setq row (+ row 1))			; footers:
  (vlax-put-property xlcells "Item" row 2 "TOTAL:")
  (vlax-put-property xlcells "Item" row 3 (rtos (/ total 1000) 2 2))
  (vlax-put-property xlcells "Item" row 4 "MTR")
;;;(vlax-put-property xlCells "Item" row 3 (rtos (/ total 1000) 2 2)); for metric units
  (mapcar
    (function
      (lambda (x)
	(vl-catch-all-apply (function (lambda () (progn (vlax-release-object x) (setq x nil)))))
      )
    )
    (list xlcells xlsheet xlsheets xlbook xlbooks xlapp)
  )
  (alert "Simpan dan tutup file nya manual")
  (alert "Bud's Colletion.......")
  (gc)
  (gc)
  (princ)
)
(princ "\t\t***\t Type PLE untuk disimpan di Excel\t***")
(princ "\t\t***\t Bud's Colletion......\t***")
(princ)
0 Likes
Message 4 of 6

Anonymous
Not applicable

thank you very much....It's works....

0 Likes
Message 5 of 6

Anonymous
Not applicable

More question please......

when i compile to be vlx file, why to be come Unknown command ? anyone can help?. tq

0 Likes
Message 6 of 6

cadffm
Consultant
Consultant

Which source code (complete file content), which command call?
Make sure you have sent the correct call (see [F2] after the call)

Sebastian

0 Likes