Footpeg Posted August 9, 2008 Share Posted August 9, 2008 Using AutoLisp, does anyone know how to obtain two 3D points that define the centerline of a 3DSOLID cylinder? The orientation and diameter of the cylinder are unknown, and each end may have been cut to fit another 3D object, of any shape, using the SUBTRACT command. If you know how to do this manually in AutoCAD, even if it requires exploding the object, I may be able to automate it. Footpeg Quote Link to comment Share on other sites More sharing options...
fixo Posted August 9, 2008 Share Posted August 9, 2008 ;; written by Hikolay Poleshuk ;; http://www.private.peterlink.ru/poleshchuk/cad/eng.html (defun 3dsolidinfo (/ ae w wl1 wl1e wl2 wle wltemp wstr) (setq ae (car (entsel "\nSelect a 3dSolid (cylinder):"))) (setq wle (entget ae)) (setq wl1e (mapcar 'cdr (vl-remove-if-not (function (lambda (w) (= 1 (car w)))) wle))) (while wl1e (setq wstr (car wl1e)) (setq wl1 (vl-string->list wstr)) (setq wl2 (mapcar '(lambda (w) (setq w (if (= w 32) 32 (boole 6 w 95))) (if (< w 32) (setq w (+ w 64)) w) ) wl1 ) ) (setq wltemp (append wltemp (list (vl-list->string wl2)))) (setq wl1e (cdr wl1e)) ) wltemp ) ; by *** 2004 (defun strlist (strExp strDel / strLst) (while (setq pos (vl-string-position (ascii strDel) strExp)) (setq itm (substr strExp 1 pos)) (setq strLst (append strLst (list itm))) (setq strExp (substr strExp (+ pos 2))) ) (setq strLst (append strLst (list strExp))) ) (defun C:test(/ axis_points info p1 p2) (setq info (3dsolidinfo)) (setq axis_points (mapcar (function (lambda (n) (cdddr (mapcar 'atof (strlist n " "))))) (mapcar (function (lambda (s) (substr s 18))) (vl-remove-if-not (function (lambda (x) (wcmatch x "ellipse-curve $*"))) info)))) (setq p1 (car axis_points) p2 (cadr axis_points) p1 (list (car p1)(cadr p1)(caddr p1)) p2 (list (car p2)(cadr p2)(caddr p2)) ) (alert (strcat "Height of cylinder = " (rtos (distance p1 p2)) " drawing units")) (princ) ) Feel free to modify them to your suit or just grab the points P1 and P2 from there ~'J'~ Quote Link to comment Share on other sites More sharing options...
Footpeg Posted August 9, 2008 Author Share Posted August 9, 2008 SPARKY77, Thank you very much, it almost worked! Actually, it works quite well if the cylinder ends have not be modified, or if a cylinder of the same diameter is subtracted from it. Below is a test command that will create 3 cylinders to demonstrate the condition. Use your test command on the red cylinder it creates and you'll see what I mean. (defun c:test2 ( / ss1) ;; Create 3 cylinders, one of which is shaped to fit the other two. (command ".ucs" "W") ;; Create the two chord cylinders (that will be subtracted). (command ".cylinder" "0,0,0" 2.0 10.0) (setq ss1 (ssadd (entlast))) (command ".cylinder" "10,0,0" 1.0 10.0) (ssadd (entlast) ss1) (command ".vpoint" "1,-1,1") ;; Create the cylinders and fit the ends to the first two cylinders. (command ".ucs" "ZA" "10,0,2" "0,0,8") (command ".color" "r") (command ".cylinder" "0,0,0" 1.0 11.66190379) ;; Cope both ends to fit the chord cylinders. (command ".subtract" (entlast) "" ss1 "") ;; Recreate the two cylinders deleted by the subtract command. (command ".ucs" "W") (command ".color" "y") (command ".cylinder" "0,0,0" 2.0 10.0) (command ".cylinder" "10,0,0" 1.0 10.0) (command ".color" "w") (alert "Try the 'test' command on the red cylinder. It reports the height of the cylinder is 0.0 units and p1 and p2 are identical.") ) ;_ defun c:test2 Footpeg Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.