Updated version (below and attached). This version will miter corners without a bend. If the CSV contains no bend radius information the user is now prompted for a radius. Code tested on BricsCAD V18.
(vl-load-com)
(defun KGA_Conv_EnameList_To_Pickset (lst / ret)
(setq ret (ssadd))
(foreach enm lst (if (not (vlax-erased-p enm)) (ssadd enm ret)))
(if (/= 0 (sslength ret)) ret)
)
(defun KGA_Conv_Pickset_To_EnameList (ss / i ret)
(if ss
(repeat (setq i (sslength ss))
(setq ret (cons (ssname ss (setq i (1- i))) ret))
)
)
)
(defun KGA_Data_FileRead (fnm / lst ptr str)
(if (setq ptr (open fnm "r"))
(progn
(while (setq str (read-line ptr))
(setq lst (cons str lst))
)
(close ptr)
(reverse lst)
)
)
)
; Every record in the CSV has to have 3 or 4 numerical fields: X,Y,Z[,Radius].
(defun CsvToSweep_ReadCsv (fnm)
(mapcar
'(lambda (str / lst)
(setq lst (read (strcat "(" (vl-string-translate "," " " str) ")")))
(cond
((not (vl-every 'numberp lst))
nil
)
((= 4 (length lst))
(list (list (car lst) (cadr lst) (caddr lst)) (cadddr lst))
)
((= 3 (length lst))
(list lst)
)
)
)
(KGA_Data_FileRead fnm)
)
)
; Return value: List of lines, (3D) polylines and arcs as enames. The enames are in a random order.
(defun CsvToSweep_CreatePath (spc datLst userRad / linLst lst oldClayer oldFilletrad tmpLyr tmpLyrNme)
;; Create a temp layer for the path entities:
(while (tblsearch "layer" (setq tmpLyrNme (strcat "CsvToSweep_" (rtos (getvar 'cdate) 2 8))))
)
(setq tmpLyr (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) tmpLyrNme))
(setq oldClayer (getvar 'clayer))
(setvar 'clayer tmpLyrNme)
;; Create the lines:
(setq linLst
(mapcar
'(lambda (subA subB)
(vlax-vla-object->ename
(vla-addline spc (vlax-3d-point (car subA)) (vlax-3d-point (car subB)))
)
)
datLst
(cdr datLst)
)
)
;; Create the arcs:
(setq oldFilletrad (getvar 'filletrad))
(mapcar
'(lambda (linA linB datRad / enm)
(setvar 'filletrad (cond (datRad) (userRad) (0.0)))
(command "_.fillet" linA linB)
)
linLst
(cdr linLst)
(mapcar 'cadr (cdr datLst))
)
(setvar 'filletrad oldFilletrad)
;; Try to join the lines:
(princ "\nTrying to join the lines in the path (will fail at bends): ")
(command "_.join" (KGA_Conv_EnameList_To_Pickset linLst) "")
;; Cleanup and return value:
(setq lst (KGA_Conv_Pickset_To_EnameList (ssget "_X" (list (cons 8 tmpLyrNme)))))
(mapcar
'(lambda (enm) (vla-put-layer (vlax-ename->vla-object enm) oldClayer))
lst
)
(setvar 'clayer oldClayer)
(vla-delete tmpLyr)
lst
)
(defun CsvToSweep_CreateSolid (spc pathLst rad / lst oldDelobj prof)
(setq prof (vlax-vla-object->ename (vla-addcircle spc (vlax-3d-point 0.0 0.0 0.0) rad)))
(setq oldDelobj (getvar 'delobj))
(setvar 'delobj 0)
(setq lst
(vl-remove
nil
(mapcar
'(lambda (path / enm)
(setq enm (entlast))
(command "_.sweep" prof "" path)
(if (not (equal enm (entlast)))
(entlast)
)
)
pathLst
)
)
)
(setvar 'delobj oldDelobj)
(entdel prof)
(if (< 1 (length lst))
(command "_.union" (KGA_Conv_EnameList_To_Pickset lst) "")
)
(vl-remove-if 'vlax-erased-p lst)
)
(defun c:CsvToSweep ( / bendRad datLst profDiam doc fnm pathLst spc)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vla-endundomark doc)
(vla-startundomark doc)
(setvar 'cmdecho 0)
(if
(and
(setq fnm (getfiled "Select CSV file" "" "csv" 4))
(setq datLst (CsvToSweep_ReadCsv fnm))
(or
(not (vl-position nil datLst))
(prompt "\nError: invalid data ")
)
(or
(not (vl-every '(lambda (sub) (= 1 (length sub))) datLst))
(setq bendRad (getdist "\nBend radius: "))
)
(setq profDiam (getdist "\nProfile diameter: "))
)
(progn
(setq spc ((if (= 1 (getvar 'cvport)) vla-get-paperspace vla-get-modelspace) doc))
(setq pathLst (CsvToSweep_CreatePath spc datLst bendRad))
(if (= 1 (length (CsvToSweep_CreateSolid spc pathLst (/ profDiam 2.0))))
(princ "\nSweep successfully created ")
(princ "\nAn unxpected error occured ")
)
(mapcar 'entdel pathLst)
)
)
(setvar 'cmdecho 1)
(vla-endundomark doc)
(princ)
)
CsvToSweep_20200104.zip