This is so awesome! Really excited about this. Apologies again for the numerous posts today. But I got it to work and added a separate if statement. Wanting to double check that it's correct. It did work as I planned it to but possible is out of order? The point of the if statement is for points that would be sleeves I would want the cylinder to be extruded along the Z axis. It worked great when there was 1 point but as soon as I added another separate point the code read it as the "pair" and then extruded over to it instead of down so wondering how I can fix that.
; drawtubes by AlanH June 2025
; reads two xyz points and radius in a csv file
; thanks to Lee-mac for this defun
(defun C:dotubes ( / oldsnap oldaunits csv fo str x1 x2 y1 y2 z1 z2 rad)
(defun csv->lst (str del / pos )
(if (setq pos (vl-string-position del str))
(cons (substr str 1 pos) (csv->lst (substr str (+ pos 2)) del))
(list str)
)
)
(defun tube (ent rad / obj start end len)
(setq obj (vlax-ename->vla-object ent))
(setq start (vlax-curve-getstartPoint obj))
(setq end (vlax-curve-getEndPoint obj))
(setq len (vlax-get obj 'length))
(command "UCS" "3" start end "")
(command "circle" "0,0,0" rad)
(setq ent2 (entlast))
(command "rotate3d" ent2 "" "Y" "0,0,0" (/ pi 2.))
(command "extrude" ent2 "" len)
(command "UCS" "W")
(princ)
)
;;starts here
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq oldaunits (getvar 'aunits))
(setvar 'aunits 3)
(setq csv (getfiled "Select CSV File" "" "csv" 16))
(setq fo (open csv "R"))
(setq str (read-line fo))
(while (setq str (read-line fo))
(setq lst (csv->lst str 44))
(setq x1 (atof (nth 1 lst))
y1 (atof (nth 2 lst))
z1 (atof (nth 3 lst))
rad (atof (nth 4 lst)))
;;Read the next line
(setq str (read-line fo))
(if (or (null str) (= str ""))
;; If only one point provided — draw circle and extrude along Z
(progn
(command "UCS" "W")
(command "circle" (list x1 y1 z1) rad)
(setq ent2 (entlast))
(command "extrude" ent2 "" 10.0) ;; Extrude along Z axis by 10 units
)
;; Two points provided — draw line and tube
(progn
(setq lst (csv->lst str 44))
(setq x2 (atof (nth 1 lst))
y2 (atof (nth 2 lst))
z2 (atof (nth 3 lst)))
(command "line" (list x1 y1 z1)(list x2 y2 z2) "")
(tube (entlast) rad)
)
)
)
(CLOSE FO)
(command "zoom" "e")
(setvar 'aunits oldaunits)
(setvar 'osmode oldsnap)
(princ)
)
(c:dotubes)