Cylinder Two end center points or the direction it is going

Cylinder Two end center points or the direction it is going

cadking2k5
Advocate Advocate
759 Views
3 Replies
Message 1 of 4

Cylinder Two end center points or the direction it is going

cadking2k5
Advocate
Advocate

Is there a way to select a cylinder and get the two end center points or the direction it is going in autolisp.

0 Likes
760 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant

I can imagine a way if it is orthogonally oriented  [within limits], but not if it runs at some non-orthogonal angle.  Do you always have them with that limitation?

Kent Cooper, AIA
0 Likes
Message 3 of 4

dbhunia
Advisor
Advisor

@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....
0 Likes
Message 4 of 4

cadking2k5
Advocate
Advocate

I think you but there is something I forgot is there a way to get those if the cylinder is union with another 3D solid object 

0 Likes