abra-CAD-abra 发表于 2022-7-5 15:57:11

Error: bad argument type: outp

All,
 
I am battling with this error and I cannot find much documentation on it:
Error: bad argument type: output-streamp: "C:\\Coords\\test.csv"
 
I cannot see any problems with my code although I suspect it may be something to do with getfiled?
 
Anybody have any suggestions?
 
Please refer attached LISP.
 
Thanks in advance
C2Ex.lsp

rlx 发表于 2022-7-5 16:18:04

You try to write to the file-name (fnm) when you should write to the file-pointer (opn)
 
 
 
 
gr.Rlx

Tharwat 发表于 2022-7-5 16:28:27

Hi,
 
The error you have been receiving is due to writing to file name and not to file-pointer as Rlx mentioned above, so I rewrote 'your' codes in another way and hope you don't mind since the following code and is more than enough and faster than converting safearray to list and so on.
 

(defun c:test (/ *error* opn s fnm i e ip) (defun *error* (msg)   (if opn (close opn))   (and msg (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))   (princ (strcat "\nError: " msg))   )   (princ) ) (if (and (setq s (ssget "_:L" '((0 . "INSERT") (66 . 1))))          (setq fnm (getfiled "Save Coordinates to Text or CSV File" "" "csv;txt" 1))          (setq opn (open fnm "w"))          )   (repeat (setq i (sslength s))       (setq e (vlax-ename->vla-object (ssname s (setq i (1- i))))             ip (vlax-get e 'insertionpoint))      (write-line (strcat (vla-get-textstring (car (vlax-invoke e 'getattributes)))                        "," (rtos (car ip) 2 4)                        "," (rtos (cadr ip) 2 4)) opn)   )   ) (*error* nil) (princ)) (vl-load-com)

abra-CAD-abra 发表于 2022-7-5 16:55:08

Thank you for your help guys.
 
 
Tharwat, I like your alternative solution using vlax-invoke and 'getattributes.
 
 
Always learning..
 
 
Thanks again.

Tharwat 发表于 2022-7-5 17:00:44

You're welcome.
页: [1]
查看完整版本: Error: bad argument type: outp