Civil 3D Points from .CSV LISP = "too many arguments" in Civil 3D 2025

Civil 3D Points from .CSV LISP = "too many arguments" in Civil 3D 2025

EBDBC3D
Advocate Advocate
265 Views
16 Replies
Message 1 of 17

Civil 3D Points from .CSV LISP = "too many arguments" in Civil 3D 2025

EBDBC3D
Advocate
Advocate

When I try to run the attached LISP routine in Civil 3D 2025.2.2, I get a "too many arguments" error after picking any .CSV file. Is there a way to update it to work with this version?

 

I found the LISP routine here:

https://forums.autodesk.com/t5/civil-3d-customization-forum/lisp-or-pogram-to-push-civil-3d-points-t...

0 Likes
Accepted solutions (1)
266 Views
16 Replies
Replies (16)
Message 2 of 17

pbejse
Mentor
Mentor

Perhaps the issue is the csv file

If you don't mind, Can you post your csv file here?

0 Likes
Message 3 of 17

EBDBC3D
Advocate
Advocate

Here's a csv file I tested it on.

0 Likes
Message 4 of 17

CodeDing
Advisor
Advisor

@EBDBC3D ,

 

Why not just create a custom point file format?

See my image below. I added "NU" as a comment so it would ignore the header row.

This would be better than having to use a custom lisp I believe.

 

image.png

 

Best,

~DD

0 Likes
Message 5 of 17

EBDBC3D
Advocate
Advocate

I know how to import points, but I'm trying to get the functionality from this LISP to work as part of something else. I'm wondering why it works in earlier versions but not Civil 3D 2025.

0 Likes
Message 6 of 17

pbejse
Mentor
Mentor

Only thing i can think of is if somehow the Str2List function is redefined by another function of the same name that accepts one less argument than the loaded Str2List function, then it would result to "too many arguments" 

 

If that is the case, it would be better to place the Str2List  function as local, that way, that version of the function 

(defun c:csvTOCivil (/ Str2List C3D C3DDOC D DATA F FILEPATH I LN OCOGO OK POINTS)
(vl-load-com)
;;;str2list by John Uhden, as posted to the adesk customization newsgroup a long time ago
(defun Str2List	(str pat / i j n lst)
  (cond
    ((/= (type str) (type pat) 'STR))
    ((= str pat) '(""))
    (T
     (setq i 0
	   n (strlen pat)
     )
     (while (setq j (vl-string-search pat str i))
       (setq lst (cons (substr str (1+ i) (- j i)) lst)
	     i	 (+ j n)
       )
     )
     (reverse (cons (substr str (1+ i)) lst))
    )
  )
)
....

We can clean up the current code if you want, it a bit of a mess now

0 Likes
Message 7 of 17

CodeDing
Advisor
Advisor

@EBDBC3D ,

 

You could try this re-work:

 

;; String to List  -  Lee Mac
;; Separates a string using a given delimiter
;; str - [str] String to process
;; del - [str] Delimiter by which to separate the string
;; Returns: [lst] List of strings
(defun LM:str->lst ( str del / len lst pos )
    (setq len (1+ (strlen del)))
    (while (setq pos (vl-string-search del str))
        (setq lst (cons (substr str 1 pos) lst)
              str (substr str (+ pos len))
        )
    )
    (reverse (cons str lst))
)

(defun c:CSVTOCIVIL ( / GetC3D SmallestAvailablePointNumber fPath f ln data points num loc exPt ptNew)
  (vl-load-com)
  ;; Helper Function(s)
  (defun GetC3D ( / C3D)
    (setq	C3D (strcat "HKEY_LOCAL_MACHINE\\"
                      (if vlax-user-product-key
                        (vlax-user-product-key)
                        (vlax-product-key)
                      );if
              );strcat
          C3D (vl-registry-read C3D "Release")
          C3D (substr
                C3D
                1
                (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1))
              );substr
          *C3D* (vla-getinterfaceobject
                  (vlax-get-acad-object)
                  (strcat "AeccXUiLand.AeccApplication." C3D)
                );vla-getinterfaceobject
          *docC3D* (vla-get-activedocument *C3D*)
    );setq
  );defun
  (defun SmallestAvailablePointNumber (pts / )
    (if (null *NextPtNo*)
      (setq *NextPtNo* 1)
    )
    (while
      (not
        (vl-catch-all-error-p
          (vl-catch-all-apply
            'vlax-invoke
            (list pts 'Find *NextPtNo*)
          )
        )
      )
      (setq *NextPtNo* (1+ *NextPtNo*))
    )
    *NextPtNo*
  )
  ;; ----- Begin Work -----
  (GetC3D)
  ;; Have user select point file
  (setq fPath
    (getfiled "Select TEXT file to read :"
              (getvar "dwgprefix")
              "csv"
              4
    )
  )
  ;; Ensure user selected a file
  (if (not fPath)
    (progn (prompt "\nNo file selected, exiting.") (exit))
  ;else, inform user of status
    (prompt (strcat "\nFile selected: " fPath))
  )
  ;; Read lines from file
  (prompt "\nReading file... ")
  (setq f (open fPath "r"))
  (read-line f) ;; ignore header line
  (while (setq ln (read-line f))
    (if (not (eq "" ln))
      (setq data (cons ln data))
    )
  )
  (close f)
  (prompt "Complete.")
  ;; Parse lines retrieved from file
  ;; CSV is in format: PENZ
  (prompt "\nParsing file data... ")
  (setq data
    (mapcar
     '(lambda (str / lst)
        (setq lst (LM:str->lst str ";"))
        (list
          (atoi (car lst))      ; P
          (list
            (atof (cadr lst))   ; E (X)
            (atof (caddr lst))  ; N (Y)
            (atof (cadddr lst)) ; Z
          )
        )
      )
      (reverse data)
    )
  )
  (prompt "Complete.")
  ;; Create points in dwg
  (prompt "\nCreating points... ")
  (setq points (vlax-get *docC3D* 'Points))
  (foreach pt data
    (setq num (car pt) loc (cadr pt))
    ;; Create the point (a default number will be assigned automatically)
    (setq ptNew (vlax-invoke points 'Add loc))
    ;; Now, we test to see if our desired point number is available
    (setq exPt (vl-catch-all-apply 'vlax-invoke (list points 'Find num)))
    (if (vl-catch-all-error-p exPt)
      ;; Desired point number is available, assign it to point
      (vlax-put-property ptNew 'Number num)
      ;; else, The default number may NOT have been the smallest available number, let's assign the smallest available
      (vlax-put-property ptNew 'Number (setq num (SmallestAvailablePointNumber points)))
    )
    ;;----- Assign desired properties to point 'ptNew' -----
    ;(vlax-put-property ptNew 'Layer "0") ;; need to check if layer exists first!
    ;;------------------------------------------------------
    (prompt (strcat (itoa num) ", ")) ;; provide update to user
  )
  (prompt "Complete.")
  (prompt "\nCSVTOCIVIL Complete.")
  (princ)
)

 

Output looks like:

Command: CSVTOCIVIL
File selected: C:\Users\me\Desktop\test.csv
Reading file... Complete.
Parsing file data... Complete.
Creating points... 1, 2, 3, Complete.
CSVTOCIVIL Complete.

 

Best,

~DD

0 Likes
Message 8 of 17

pbejse
Mentor
Mentor

@CodeDing wrote:

 

image.png

 


Nice Dialog @CodeDing 

Message 9 of 17

EBDBC3D
Advocate
Advocate

I did that, but still got the "too many arguments" error.

0 Likes
Message 10 of 17

EBDBC3D
Advocate
Advocate

Did that work in Civil 3D 2025? It gave me the "too many arguments" error.

0 Likes
Message 11 of 17

CodeDing
Advisor
Advisor

@EBDBC3D ,

 

You're right, I was testing in 2023.

But in 2025, I was getting a different error about ActiveX object being empty.

2025 for me was acting up if points did not already exist in the drawing. Try the new attached LSP file and see if that resolves it.

 

Updated code portion:

.......
  (setq points (vlax-get *docC3D* 'Points))
  ;; In 2025+, in dwgs with no points, we need to initialize point creation manually for some reason...
  (setq ptCnt (vlax-get points 'Count))
  (if (and (>= (atoi (substr (getvar 'ACADVER) 1 2)) 25)
           (zerop ptCnt))
    (progn
      (setq cmd (getvar 'CMDECHO))
      (setvar 'CMDECHO 0)
      (setq e (entlast))
      (command "_AECCCREATEPOINTMANUAL" "non" '(0. 0. 0.) "" "" "")
      (if (and (not (equal e (setq e2 (entlast))))
               (eq "AECC_COGO_POINT" (cdr (assoc 0 (entget e2)))))
        (entdel e2)
      )
      (setvar 'CMDECHO cmd)
    )
  )
  (foreach pt data
.......

 

Best,

~DD

0 Likes
Message 12 of 17

EBDBC3D
Advocate
Advocate

Thanks, I'm still getting "too many arguments" with that implemented.

0 Likes
Message 13 of 17

CodeDing
Advisor
Advisor

@EBDBC3D wrote:

I'm still getting "too many arguments" with that implemented.


If you're still getting that error, then you're going to need to do some more troubleshooting on your own. I've implemented as much as I can and receive no errors.

Things to try:

- Adding individual (prompt "...1,2,3...") statements between lines to verify where your error is happening.

- Check ANY and ALL other code you have to be sure you are not overwriting a default function symbol somewhere [ e.g. (setq null ....), (setq while ...) ]

 

It's working on my end in 2025.

 

Best,

~DD

0 Likes
Message 14 of 17

EBDBC3D
Advocate
Advocate
Accepted solution

Thanks, I did get it working with a little/lot of AI help. Seemed like multiple things were causing the error as it kept moving farther in the process as I fixed things. I've attached the new version in case anyone needs it.

0 Likes
Message 15 of 17

CodeDing
Advisor
Advisor

@EBDBC3D ,

 

I'm glad you got it working, but I'm worried that you're just kicking the can down the line.

 

This note from ChatGPT makes me think you overwrote your 'close' function somewhere else (not in this lisp file, but ANY other one you're running)...

;; Skip the problematic close function - let AutoLISP handle cleanup
;; In Civil 3D 2025, the close function appears to have a different signature
;; The file will be closed automatically when the variable goes out of scope
(setq file-handle nil)

 

You should try to find the error instead of avoiding it. The code I wrote will be MUCH better than AI's when you start using it regularly.

 

Try this simple code and tell us if the successful text file pops up. If it is successful, then it's not your 'close' function like I suspect, but probably another function that was overwritten. Be sure to always declare proper local variables and not to overwrite default function symbols.

(defun c:TEST ( / fPath f)
  (setq fPath (vl-filename-mktemp "XX.txt"))
  (setq f (open fPath "w"))
  (write-line "Success" f)
  (close f)
  (startapp "notepad" fPath)
  (princ)
)

 

Just my thoughts on it.. but what would I know..

~DD

0 Likes
Message 16 of 17

EBDBC3D
Advocate
Advocate

I get the "too many arguments" with your code too. Maybe my Civil 3D install is broken.

Message 17 of 17

CodeDing
Advisor
Advisor

@EBDBC3D ,

 

Do you load other Lisp files into your drawings? If so, you need to review ALL of them to check if "close" is being redefined soemwhere.. It would look like this:

(defun close .....
...or...
(setq close (lambda .....

 

If you do NOT load ANY other Lisp files (or custom add ons) then you should consider a new install of C3D.

 

Best,

~DD

0 Likes