Creating a region to extrude from 2D shapes

Creating a region to extrude from 2D shapes

Anonymous
Not applicable
964 Views
4 Replies
Message 1 of 5

Creating a region to extrude from 2D shapes

Anonymous
Not applicable

Hello 

I need to create a region to extrude which is the combination of 2 circles and lines as in the shape,

I've written the lisp to develop the circles and lines but couldn't find a command to combine them together and then extrude the whole area together.

Can somebody help me please,

Thank you

 

11.png

Here is the lisp part

 

(setq pt1 (list 0 0 ))
(command "circle" pt1 (/ Di1 2) "")
(setq circle1 (ssget "L"))
(setq pt2 (list (+ (car pt1) Le1) 0))
(command "circle" pt2 (/ Di2 2) "")
(setq circle2 (ssget "L"))
(setq pt3 (list 0 (+ (car pt1)(/ Di1 2)))
(setq pt4 (list 0 (- (car pt1)(/ Di1 2)))
(setq pt5 (list (car pt2) (- (cadr pt2) (/Di2 2)))
(setq pt6 (list (car pt2) (- (cadr pt2) (/Di2 2)))
(command "line" pt3 pt6 "")
(command "line" pt4 pt5 "")




0 Likes
965 Views
4 Replies
Replies (4)
Message 2 of 5

CodeDing
Advisor
Advisor

@Anonymous,

 

It appears that the formula you are using does Not account for tangency when drawing your lines between the circles. This would be more evident if one circle is much larger than the other.

 

I would recommend you incorporate THIS beautiful code written by Lee Mac. This will give you one solid 2D exterior line (with appropriate tangents). Then you can extrude the object as you wish.

 

Best,

~DD

Message 3 of 5

Moshe-A
Mentor
Mentor

Cemreyvz,

 

here's a lisp that will do want you want. it is not finished, i left some work for you to do.

called it 3dshape (cause that what you will get after you extrude the region)

maybe it is little complicated for you but i add a comment at each code line

a local function (draw_circle) is called to draw the circles (one at a time) and return the cp + rad as a reference values (in autolisp it is known as quoted arguments). than the tangent line is calculated (and drawn)

than a trim command is invoked to remove the unneeded arcs and a region is created.

now heres comes your part,  do the extrution.

 

i you do not understand something? feel free to ask.

 

enjoy

moshe

 

(defun c:3dshape (/ draw_circle asine ; local functions
 		    ename ss p0 p1 p2 p3 p4 rad0 rad1 cx ax bx ang0 ang1 ang2)
  
 (defun draw_circle (msg base Qpt Qrad / ent) ; function take 2 quote arguments
  (if base
   (set Qpt (getpoint base (strcat "\n" msg " circle center point: "))) ; indirect assigment
   (set Qpt (getpoint      (strcat "\n" msg " circle center point: "))) ; indirect assigment
  ); if

  (if (eval Qpt)
   (progn
    (if base
     (progn
      ; if drawing was empty, make sure ename gets the first circle
      (if (not ename)
       (setq ename (entlast))
      )
      
      ; draw this line temporary to visualize the circle centers
      (command "._line" base (eval Qpt) "") 
      (setq ent (entlast))
     )
    )
    
    (setvar "cmdecho" 1)			    ; temporary enable command echo	
    (command "._circle" (eval Qpt) pause)	    ; enter radius
    						    ; warning: specifying diameter here will break the lisp with an error
    
    (set Qrad (cdr (assoc '40 (entget (entlast))))) ; get circle radius

    (if base
     (entdel ent) ; erase temporary line
    )
    
    (setvar "cmdecho" 0) ; disable command echo , ensures positiove value is return (not nil)
   ); progn
  ); if
 ); draw_circle


 ; return arcsine of an angle
 (defun asine (x)
  (atan x (sqrt (- 1 (expt x 2))))
 )
  
 ; here start c:3dshape
 (setvar "cmdecho" 1)				; disable command echo
 (command "._undo" "_begin")			; begin group commands for 1 undo

 (setq ename (entlast))
  
 (if (and
       (draw_circle "First"  nil 'p0 'rad0) 	; send 2 quote arguments
       (draw_circle "Second" p0  'p2 'rad1) 	; send 2 quote arguments
     )
  (progn
   (setq cx (distance p0 p2))			; distance between centers
   (setq ang0 (angle p0 p2))			; angle between centers
   
   (setq ax (- rad1 rad0))   			; the front edge of triangle
   (setq ang1 (asine (/ ax cx)))                ; sine angle -> real angle
   (setq ang2 (+ ang0 ang1 (/ pi 2)))           ; angle to tangent point
   
   (setq p3 (polar p0 ang2 rad0))		; first  tangent point
   (setq p4 (polar p2 ang2 rad1))		; second tangent point

   (setq ss (ssadd))				; declar selection set
   (command "._line" p3 p4 "")			; draw first tangent line
   (setq ss (ssadd (entlast) ss))		; collect to selection set

   (setq ang2 (- ang0 ang1 (/ pi 2)))		; angle to mirroed tangent point
   
   (setq p3 (polar p0 ang2 rad0))		; first  tangent point
   (setq p4 (polar p2 ang2 rad1))		; second tangent point	
   
   (command "._line" p3 p4 "")			; draw second tangent line
   (setq ss (ssadd (entlast) ss))		; collect to selection set

   ; trim the part of circles which are not needed to create region
   (command "._trim" "_si" ss (polar p0 (angle p0 p2) rad0) (polar p2 (angle p2 p0) rad1) "")
  
   ; gether remaining arcs to selection set
   (setq ss (ssadd))
   (while ename
    (ssadd ename ss)
    (setq ename (entnext ename))
   ); while

   (command "._region" "_si" ss) ; make region 

   ; continue here to create your extrude 3d solid
   ; ......
   ; ......
   
  ); progn
 ); if

 (command "._undo" "_end")			; end group commands
 (setvar "cmdecho" 1)				; enable command echo
  
 (princ)
)

 

Message 4 of 5

Moshe-A
Mentor
Mentor

attached is an update to lisp.

 

if you liked this help then send some likes and mark this thread as solusion.

 

thanks you

moshe

 

 

0 Likes
Message 5 of 5

_gile
Consultant
Consultant

Hi,

 

The code you posted cannot work as is (unpaired parenthesis), anayway I started from it.

If you do not care about tangency, you can simply draw arcs instead of circles so that the REGION command can work.

 

(defun c:test1 (/ di1 di2 le1 pt1 pt2 pt3 pt4 pt5 pt6 ss1)
  (setq	di1 10.
	di2 5.
	le1 15.
  )
  (setq pt1 (list 0. 0.))
  (setq pt2 (list (+ (car pt1) le1) 0))
  (setq pt3 (list 0. (+ (car pt1) (/ di1 2.))))
  (setq pt4 (list 0. (- (car pt1) (/ di1 2.))))
  (setq pt5 (list (car pt2) (- (cadr pt2) (/ di2 2.))))
  (setq pt6 (list (car pt2) (+ (cadr pt2) (/ di2 2.))))
  (command "_.line" "_non" pt3 "_non" pt6 "")
  (setq ss1 (ssadd (entlast)))
  (command "_.line" "_non" pt4 "_non" pt5 "")
  (ssadd (entlast) ss1)
  (command "_.arc" "_non" pt3 "_non" (list (- (/ di1 2.)) 0.) "_non" pt4)
  (ssadd (entlast) ss1)
  (command "_.arc" "_non" pt5 "_non" (list (+ le1 (/ di2 2.)) 0.) "_non" pt6)
  (ssadd (entlast) ss1)
  (command "_.region" ss1 "")
  (command "_.erase" ss1 "")
  (princ)
)

If tangency is mandatory, IMO, it's simpler to compute the tangency points an directly a closed polyline which can also be extruded.

 

(defun c:test2 (/ acos di1 di2 le1 r1 r2 a pt1 pt2 pt3 pt4 pt5 pt6)

  (defun acos (x)
    (cond
      ((equal x 1. 1e-9) 0.)
      ((equal x -1. 1e-9) pi)
      ((< -1. x 1.)
       (atan (sqrt (- 1. (* x x))) x)
      )
    )
  )

  (setq	di1 10.
	di2 5.
	le1 15.
  )
  (setq	r1 (/ di1 2.)
	r2 (/ di2 2.)
	a  (acos (/ (- r1 r2) le1))
  )
  (setq pt1 (list 0. 0.))
  (setq pt2 (polar pt1 0. le1))
  (setq pt3 (polar pt1 a r1))
  (setq pt4 (polar pt1 (- a) r1))
  (setq pt5 (polar pt2 (- a) r2))
  (setq pt6 (polar pt2 a r2))
  (command "_.pline" "_non" pt4 "_non" pt5 "_arc" "_non" pt6 "_line" "_non" pt3 "_arc" "_close")
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes