Need lisp to draw 3D Capsule along selected line/s.

Need lisp to draw 3D Capsule along selected line/s.

Superbob3D
Explorer Explorer
367 Views
3 Replies
Message 1 of 4

Need lisp to draw 3D Capsule along selected line/s.

Superbob3D
Explorer
Explorer

Hello!

 

I am hoping someone out there would be willing to create a Lisp routine for me. I think it's pretty straight forward, but I'd rather not have to spend the time if someone experienced with such things can give me a hand.

 

I'm looking for a lisp routine that will draw 3D solid "Capsules" along selected lines. The capsule would be a comprised of a cylinder that runs length of the line, with spheres on either end (with all 3 separate solids "union"-ed together). The routine needs to prompt for the radius of the solid (i.e the radius of the cylinder and the two spheres). Ideally the new solid/s will be placed on the "current" layer.

 

I found this lisp routine, "Curve2cylinder_english_v2.lsp", in another thread today, which gets me close (it draws a cylinders along selected lines). I'm guessing this can just be modified. I just need it to add spheres to the end/s of the cylinder/s (using the same radius) and unionize it.

 

Thank you!

 

Bob

 

0 Likes
Accepted solutions (1)
368 Views
3 Replies
Replies (3)
Message 2 of 4

Sea-Haven
Mentor
Mentor

Why not extrude along PATH it's in built, and add sphere at ends, do you really need code ?

 

Are you experienced in working in 3D, adding 3d objects ?

 

SeaHaven_1-1664154294663.png

If you do want code then write down the steps that is your lisp sequence.

 

0 Likes
Message 3 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

Adding the SPHEREs at the ends and the UNIONing of them with the cylinders to my routine in that topic [which remembers your specified diameter], I get this [lightly tested]:

 

(vl-load-com)
(defun C:CYLRE (/ ss rad ent start end ssc) ; = CYLinder with Rounded Ends
  (initget (if *tubedia 6 7)); no 0, no negative, no Enter on first use
  (setq *tubedia
    (cond
      ((getdist
          (strcat
            "\nDiameter of Tubular Cross-Section(s)"
            (if *tubedia (strcat " <" (rtos *tubedia) ">") ""); offer default only on subsequent use
            ": "
          ); strcat
        ); getdist
      ); User-gives-distance condition
      (*tubedia); Enter for default on subsequent use
    ); cond
  ); setq
  (setq rad (/ *tubedia 2))
  (prompt "\nTo make tubular extrusions along paths,")
  (setq ss (ssget '((0 . "*POLYLINE,LINE,ARC,CIRCLE,ELLIPSE,SPLINE"))))
  (repeat (sslength ss)
    (setq
      ent (ssname ss 0)
      start (vlax-curve-getStartPoint ent)
      end (vlax-curve-getEndPoint ent)
    ); setq
    (command
      "_.ucs" "_ZA"
        (vlax-curve-getStartPoint ent)
        (mapcar '+
          (getvar 'lastpoint)
          (vlax-curve-getFirstDeriv ent (vlax-curve-getStartParam ent))
        ); mapcar & UCS
      "_.circle" "0,0" rad
      "_.ucs" "_previous"
      "_.extrude" (entlast) "" "_path" ent
    ); command
    (setq ssu (ssadd (entlast)))
    (command "_.sphere" "_non" start rad)
    (ssadd (entlast) ssu)
    (command "_.sphere" "_non" end rad)
    (ssadd (entlast) ssu)
    (command "_.union" ssu "")
    (ssdel (ssname ss 0) ss)
  ); repeat
  (princ)
); defun

 

Do you need Undo-Begin/End wrapping, and/or *error* handling to ensure resetting of the UCS?  Prevention of selection of paths on locked Layers?

 

[I was going to ask whether it should check for closed objects, and do only the extrusion and skip the spheres, but in the end it doesn't matter.]

 

Kent Cooper, AIA
0 Likes
Message 4 of 4

Superbob3D
Explorer
Explorer

Kent,

 

Wow! Perfect! Thank you SO much!

 

Bob

 

 

0 Likes