@cadking2k5 wrote:
Is there a way to select a cylinder and get the two end center points or the direction it is going in autolisp.
Hi
Try this........
This is a little modified code of the post......
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/end-points-of-3dsolid-cylinder/td-p/...
Here "C1" & "C2" will give you the two end center points of a cylinder.
(defun c:CCYL ( / ss i a)
(if
(setq ss (ssget '((0 . "3DSOLID"))))
(repeat (setq i (sslength ss))
(if
(setq a (Cyl_ends (ssname ss (setq i (1- i)))))
(progn
(setq C1 (car a))
(setq C2 (cadr a))
)
)
)
)
(print C1)
(print C2)
(princ)
)
(defun Cyl_ends (e / i v r l c d)
(setq e (vlax-ename->vla-object e)
v (vlax-get e 'Volume)
i ((lambda (x)
(if
(equal (car x) (cadr x) (* 0.001 (car x)))
(list (caddr x) (car x) 3)
(if
(equal (car x) (caddr x) (* 0.001 (car x)))
(list (cadr x) (car x) 2)
(if
(equal (cadr x) (caddr x) (* 0.001 (cadr x)))
(list (car x) (cadr x) 1)
)
)
)
)
(vlax-get e 'PrincipalMoments)
)
)
(if i
(progn
(setq r (sqrt (/ (* 2.0 (car i)) v))
l (/ v (* pi r r)))
(if
(equal (/ (cadr i) (/ (* v (+ (* 3.0 r r) (* l l))) 12.0)) 1.0 1e-5)
(progn
(setq c (vlax-get e 'Centroid)
d (vlax-get e 'PrincipalDirections)
d (cond
((= (caddr i) 1) (list (nth 0 d) (nth 1 d) (nth 2 d)))
((= (caddr i) 2) (list (nth 3 d) (nth 4 d) (nth 5 d)))
((= (caddr i) 3) (list (nth 6 d) (nth 7 d) (nth 8 d)))
)
)
(list
(mapcar '(lambda (a b) (- a (* b l 0.5))) c d)
(mapcar '(lambda (a b) (+ a (* b l 0.5))) c d)
)
)
)
)
)
)
Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....