See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Extract the radius of a 3D cylinder using LISP?

  1. #1
    Member
    Join Date
    2006-06
    Posts
    8
    Login to Give a bone
    0

    Default Extract the radius of a 3D cylinder using LISP?

    Howdy folks-

    Our company designs piping systems in AutoCAD using 3D solids for pipe and fittings and am now working on a LISP routine to automate inserting u-bolts. I'd like to set the u-bolt size by picking the cylinder the u-bolt will straddle, but haven't been able to decipher the dxf data for 3D solid entities.

    Would anyone have a piece of LISP code that can extract the radius or diameter of a 3D solid cylinder?

    Thanks in advance,

    Mike O'Flaherty
    Hebeler Corporation

  2. #2
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    201
    Login to Give a bone
    1

    Default Re: Extract the radius of a 3D cylinder using LISP?

    Hi,

    You can get some informations through VisualLISP if the cylinder is a primitive 3d solid (created with the CYLINDER command) but this won't work if it's an extruded solid.

    Code:
    (vl-load-com)
    
    (if (and
          ;; solid selection
          (setq cyl (car (entsel "\nSelect a cylinder: ")))
    
          ;; changing ename to vla-object
          (setq cyl (vlax-ename->vla-object cyl))
    
          ;; checking if it's a 3d solid
          (= (vla-get-ObjectName cyl) "AcDb3dSolid")
    
          ;; checking if it's a cylinder (primitive)
          (= (vl-catch-all-apply 'vla-get-SolidType (list cyl))
    	 "Cylindre"
          )
        )
    
      (setq
        ;; cylinder height
        ht	(* 2
    	   (distance (vlax-get cyl 'Position) (vlax-get cyl 'centroid))
    	)
    
        ;; cylinder radius
        rad	(sqrt (/ (vla-get-Volume cyl) (* pi ht)))
      )
    
      (princ "\nUnvalid Entity.")
    )

  3. #3
    Member
    Join Date
    2006-06
    Posts
    8
    Login to Give a bone
    0

    Talking Re: Extract the radius of a 3D cylinder using LISP?

    That is perfect! I can see several uses for this: locating o-let fittings on pipe spools, gathering total lengths of pipe used in an assembly, one-click to get the cut-length of a pipe, etc. This code was exactly what I needed. Thank you very much for sharing it!

    Mike

    Mike O'Flaherty
    Hebeler Corporation

  4. #4
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Extract the radius of a 3D cylinder using LISP?

    Just thought of a way of working around this. Maybe copy the 3dSolid to a temporary spot (to be deleted later). Then Explode the solid. Catch all exploded entities using (ssget "p"). Select all Regions from those entities. Explode them to check for Circle - then once you've obtained the Radius, erase the selection set of temporary exploded solid.
    This should work for most 3dObjects, even extruded ones - except of course if none of it's surfaces has a circle.

  5. #5
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Extract the radius of a 3D cylinder using LISP?

    This seems to work:
    Code:
    (defun c:ShowRadius (/ Cyl SS1 SS2 SS3 en ed n Rad)
      (setq Cyl (entsel "Select 3dSolid: "))
      (if (and Cyl
           (setq Cyl (car Cyl))
           (= "3DSOLID" (cdr (assoc 0 (entget Cyl))))
          ) ;_ end of and
        (progn
          (command "_copy" Cyl "" "0,0,0" "0,0,0") ;Copy 3dSolid
          (setq Cyl (entlast))        ;Get copied version's name
          (command "_explode" "_last" "")    ;Explode copied version
          (setq SS1 (ssget "P"))        ;Get selection set of exploded entities
          (setq SS2 (ssget "P" '((0 . "REGION"))))
                        ;Get sel-set of only Regions from Exploded
    
          ;; Remove all Regions from SS1
          (setq n 0)
          (while (< n (sslength SS2))
        (setq SS1 (ssdel (ssname SS2 n) SS1))
        (setq n (1+ n))
          ) ;_ end of while
    
          (command "_explode" SS2 "")    ;Explode Regions
          (setq SS2 nil)            ;Clear Selection Set
          (gc)                ;Force garbage collection
          (setq SS2 (ssget "P"))        ;Get selection set of exploded entities
          (setq n    0
            Rad    nil
          ) ;_ end of setq
          ;;Step through SS2 search for Circle
          (while (and (not Rad) (< n (sslength SS2)))
        (setq en (ssname SS2 n))
        (setq ed (entget en))
        (if (= "CIRCLE" (cdr (assoc 0 ed)))
          (setq Rad (cdr (assoc 40 ed)))
        ) ;_ end of if
        (setq n (1+ n))
          ) ;_ end of while
    
          (command "_erase" SS1 SS2 "")    ;Delete all temporary objects
          (setq SS1    nil
            SS2    nil
          )                    ;Clear select sets
          (gc)                ;Force garbage collection
    
          ;;Show radius
          (if Rad
        (princ (strcat "\nThe 3dSolid's radius is " (rtos Rad)))
        (princ "\nThe 3dSolid does not seem to have a Circle")
          ) ;_ end of if
        ) ;_ end of progn
        (princ
          "\Function canceled, either no / incorrect object selected."
        ) ;_ end of princ
      ) ;_ end of if
      (princ)
    ) ;_ end of defun

  6. #6
    Member
    Join Date
    2006-06
    Posts
    8
    Login to Give a bone
    0

    Default Re: Extract the radius of a 3D cylinder using LISP?

    Thanks for the post irneb, I'm going to do some experimenting with that code. I've got some ideas where it would be very handy.

    I'm amazed at how quickly help has been offered here. It is greatly appreciated.

    Thanks to you both,

    Mike

  7. #7
    Woo! Hoo! my 1st post
    Join Date
    2012-09
    Posts
    1
    Login to Give a bone
    0

    Default Re: Extract the radius of a 3D cylinder using LISP?

    Irne,

    That code " (defun c:ShowRadius (/ Cyl SS1 SS2 SS3 en ed n Rad).... " is awesome +++++++++++++...
    Is it possible to add on top of that routine the option to create the cylinder at the exact location of the existing one with the new-given by prompt radius?

    Thanks

    Alex B.

  8. #8
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Extract the radius of a 3D cylinder using LISP?

    You're welcome, glad it works for you.
    Quote Originally Posted by abrusil33864453 View Post
    Is it possible to add on top of that routine the option to create the cylinder at the exact location of the existing one with the new-given by prompt radius?
    Let me get this straight. You want to start creating a cylinder at the end of another one using the same radius? Not impossible I guess, just before I modify the code I'd like to know something: Which version of acad are you using? Can't you use the extrude faces / press-pull tool?

  9. #9
    Member
    Join Date
    2014-11
    Posts
    21
    Login to Give a bone
    0

    Default Re: Extract the radius of a 3D cylinder using LISP?

    is there a way you can get the Direction the Cylinder is going.

    Quote Originally Posted by _gile View Post
    Hi,

    You can get some informations through VisualLISP if the cylinder is a primitive 3d solid (created with the CYLINDER command) but this won't work if it's an extruded solid.

    Code:
    (vl-load-com)
    
    (if (and
          ;; solid selection
          (setq cyl (car (entsel "\nSelect a cylinder: ")))
    
          ;; changing ename to vla-object
          (setq cyl (vlax-ename->vla-object cyl))
    
          ;; checking if it's a 3d solid
          (= (vla-get-ObjectName cyl) "AcDb3dSolid")
    
          ;; checking if it's a cylinder (primitive)
          (= (vl-catch-all-apply 'vla-get-SolidType (list cyl))
    	 "Cylindre"
          )
        )
    
      (setq
        ;; cylinder height
        ht	(* 2
    	   (distance (vlax-get cyl 'Position) (vlax-get cyl 'centroid))
    	)
    
        ;; cylinder radius
        rad	(sqrt (/ (vla-get-Volume cyl) (* pi ht)))
      )
    
      (princ "\nUnvalid Entity.")
    )

  10. #10
    Member
    Join Date
    2014-11
    Posts
    21
    Login to Give a bone
    0

    Default Re: Extract the radius of a 3D cylinder using LISP?

    is there a way you can get the Direction the Cylinder is going. or the other end center point

Page 1 of 2 12 LastLast

Similar Threads

  1. delta radius length tangent lisp
    By mgonzales361438 in forum AutoLISP
    Replies: 3
    Last Post: 2014-06-11, 07:52 AM
  2. Lisp to extract Handle
    By tguy in forum AutoLISP
    Replies: 11
    Last Post: 2012-03-13, 03:04 PM
  3. Error While apply Rolling Joint: Cylinder on Cylinder 2C
    By klsandip in forum Inventor - General
    Replies: 3
    Last Post: 2010-02-03, 02:05 AM
  4. Cylinder on plane AND cylinder rotation
    By sanjay692 in forum Inventor - General
    Replies: 5
    Last Post: 2009-01-11, 03:53 PM
  5. Replies: 7
    Last Post: 2007-09-05, 03:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •