DLV Posted December 19 Posted December 19 (edited) I'm trying to get autoCAD to read data from a spreadsheet to create a one-line diagram. I created the csv file and then the .lsp, when loading it in autoCAD I get the error too many arguments. I already searched for the error even with ai and it tells me that possibly the error is from the command line, I have already tried a thousand ways and the error persists, could someone help me? This is my csv code: Circuito,Origen,Destino,Potencia C1,Nodo1,Nodo2,5000 C2,Nodo2,Nodo3,3000 C3,Nodo3,Nodo4,2500 And this is my .lsp code: ;; Función principal para cargar datos desde un archivo CSV (defun cargar-datos () ;; Ruta al archivo CSV (setq ruta "C:/du_intento1.csv") (setq datos (open ruta "r")) ; Intenta abrir el archivo ;; Verifica si el archivo se abrió correctamente (if datos (progn (setq linea (read-line datos)) ; Lee la primera línea (encabezados) (princ (strcat "\\nEncabezados: " linea)) ; Imprime los encabezados para depuración (while (setq linea (read-line datos)) ; Lee línea por línea ;; Imprimir cada línea para depuración (princ (strcat "\\nLeyendo línea: " linea)) ;; Procesa cada línea (let ((elementos (split linea ","))) ; Divide la línea en elementos ;; Imprimir elementos para depuración (princ (strcat "\\nElementos: " (vl-prin1-to-string elementos))) (procesar-linea elementos))) (close datos) ; Cierra el archivo después de procesarlo (princ "\\nArchivo CSV procesado correctamente.")) (princ "\\nError: No se pudo abrir el archivo CSV. Verifique la ruta."))) ;; Función para dividir una cadena en una lista (defun split (string delimiter) (vl-remove-if (function (lambda (x) (eq x ""))) (mapcar 'vl-string-trim (vl-string->list string delimiter)))) ;; Procesar cada línea del CSV (defun procesar-linea (elementos) ;; Extrae los datos del CSV (let* ((circuito (nth 0 elementos)) ; Nombre del circuito (origen (nth 1 elementos)) ; Nodo origen (destino (nth 2 elementos)) ; Nodo destino (potencia (nth 3 elementos)) ; Potencia del circuito (coor-origen (obtener-coordenadas origen)) ; Coordenadas del nodo origen (coor-destino (obtener-coordenadas destino))) ; Coordenadas del nodo destino ;; Depuración: Imprimir valores de coordenadas (princ (strcat "\\nProcesando circuito: " circuito)) (princ (strcat "\\nCoordenadas de origen: " (if coor-origen (strcat (rtos (car coor-origen) 2 2) ", " (rtos (cadr coor-origen) 2 2)) "NIL"))) (princ (strcat "\\nCoordenadas de destino: " (if coor-destino (strcat (rtos (car coor-destino) 2 2) ", " (rtos (cadr coor-destino) 2 2)) "NIL"))) ;; Verifica si las coordenadas son válidas (if (and coor-origen coor-destino) (if (and (= (length coor-origen) 2) (= (length coor-destino) 2)) (progn ;; Validación de coordenadas (princ (strcat "\\nCoordenadas de origen: " (rtos (car coor-origen) 2 2) ", " (rtos (cadr coor-origen) 2 2))) (princ (strcat "\\nCoordenadas de destino: " (rtos (car coor-destino) 2 2) ", " (rtos (cadr coor-destino) 2 2))) ;; Depuración: Imprimir comando antes de ejecutar (princ (strcat "\\nEjecutando comando: _line " (rtos (car coor-origen) 2 2) "," (rtos (cadr coor-origen) 2 2) " " (rtos (car coor-destino) 2 2) "," (rtos (cadr coor-destino) 2 2))) ;; Imprimir cada argumento del comando para depuración (princ (strcat "\\nArgumentos del comando: " (rtos (car coor-origen) 2 2) ", " (rtos (cadr coor-origen) 2 2) ", " (rtos (car coor-destino) 2 2) ", " (rtos (cadr coor-destino) 2 2))) ;; Dibuja la línea entre los nodos (command "_.line" (rtos (car coor-origen) 2 2) (rtos (cadr coor-origen) 2 2) (rtos (car coor-destino) 2 2) (rtos (cadr coor-destino) 2 2) "") ;; Mensaje de confirmación (princ (strcat "\\nCircuito: " circuito " (" origen " -> " destino ") Potencia: " potencia " W"))) (princ "\\nError: Coordenadas no válidas.")) (princ "\\nError: Coordenadas no válidas para los nodos.")))) ;; Función para obtener coordenadas predefinidas (defun obtener-coordenadas (nombre) ;; Coordenadas para cada nodo conocido (cond ((equal nombre "Nodo1") '(10 10)) ((equal nombre "Nodo2") '(20 10)) ((equal nombre "Nodo3") '(30 10)) ((equal nombre "Nodo4") '(40 10)) (t nil))) ;; Devuelve NIL si no encuentra el nodo Edited December 19 by SLW210 Added Code Tags!! Quote
SLW210 Posted December 19 Posted December 19 In the future please use Code Tags for your code. (<> in the editor toolbar) Quote
AlanGon3 Posted December 19 Posted December 19 Hey DLV, I replaced the split function with something Lee-mac made as it was broken (did you have AI make it for you?) and switched out some of the let calls for setq and now there aren't any errors, however I'm not sure what the output is supposed to look like, so i don't know if the diagonal lines it creates are the intent or if it's still broken. Let me know. cargar-datos.lsp Quote
rlx Posted December 19 Posted December 19 (edited) your split function is causing this error (vl-string->list string delimiter) are 2 parameters , this function only has one use something like this instead : (defun Split (s d / p)(if (setq p (vl-string-search d s))(cons (substr s 1 p)(Split (substr s (+ p 1 (strlen d))) d))(list s))) p.s. welcome to cadtutor p.p.s. sorry AlanGon3 , did not see your response at time of posting. But you're also right about some functions that are not part of standard lisp. like (let or (let* or elementos. Maybe because of different language or are they defined elswhere? oh , and you also welcome to Cadtutor Edited December 19 by rlx Quote
AlanGon3 Posted December 19 Posted December 19 Thanks rlx for the warm welcome - I think let is a command in common lisp (Source: https://stackoverflow.com/questions/19067632/difference-between-let-and-setq) Which gives me a feeling this was written (at least in part) by AI - for reasons that I feel are obvious if you've ever seen an AI write code before (especially in autolisp). Based on how I saw elementos used in the code I believe is intended to be a variable name not a function Quote
BIGAL Posted December 19 Posted December 19 If you starting with a Excel can do 2 things have excel draw the lines in CAD or have the CAD read the cell values direct from Excel. So post the excel and a matching dwg. Quote
rlx Posted December 20 Posted December 20 #MeToo has seen common lisp so I think AI had a bad haircut day by using 'let' instead of setq. Elementos is probably spanish or something for member. Asked AI one time to write something for me and the result was far below expectations so no AI for me. A few decades ago microsoft introduced a 'smart' (and super irritating) paperclip and this AI maybe better , unless it reaches 'star trek' level I say get the @#$% of my computer(s) 1 Quote
BIGAL Posted December 20 Posted December 20 Waiting for AlanGon3 for samples. @rlx give COPILOT a try been playing with it a little bit, just to see what it produces, hint last word Autolisp. Quote
AlanGon3 Posted December 20 Posted December 20 @BIGAL I would provide you a sample if I worked at Costco or knew what you were talking about p.s. always last word autolisp Quote
rlx Posted Monday at 09:51 AM Posted Monday at 09:51 AM (edited) On 12/19/2024 at 6:19 PM, DLV said: This is my csv code: Circuito,Origen,Destino,Potencia C1,Nodo1,Nodo2,5000 C2,Nodo2,Nodo3,3000 C3,Nodo3,Nodo4,2500 OP has provided csv data but its not something we can work with , they look more like blocknames. So working could be like connection / circuit C1 goes from node 1 (insertionpoint Nodo1) to node 2 (insertionpoint Nodo2) with length / height / whatever 5000. So without example that is as far as we can take this. That's what you get when you replace braincells with qubits. Before you know it Cyberdyne Systems activates Skynet and sends one of its Terminators to kick you in the But don't mind me , you all dream on and have a good while you still can Edited Monday at 10:39 AM by rlx Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.