CoCreate User Forum

CoCreate User Forum (https://www.cocreateusers.org/forum/index.php)
-   Customization (https://www.cocreateusers.org/forum/forumdisplay.php?f=12)
-   -   Circular slot in Modeling (https://www.cocreateusers.org/forum/showthread.php?t=8189)

Maximus172 01-09-2015 06:05 AM

Circular slot in Modeling
 
Hi,

I did a macro doing circular slot in ME10 and would like to do similar in LISP for Modeling.

ME10
Code:


DEFINE circular_slot
LOCAL P1
LOCAL P2
LOCAL B
LOCAL D
LOCAL V
LOCAL R
LET B 5
LET D 20
LINETYPE
SOLID
COLOR
WHITE Cr
READ NUMBER 'Angle ± ' DEFAULT B B
READ NUMBER 'Diameter' DEFAULT D D
READ PNT 'Center' P1
LOOP
READ PNT 'Position of slot' P2
 
LINETYPE
    DASH_CENTER
    COLOR
    YELLOW
LET V (ROT (P2 - P1) 0)
LET V1 (ROT(V) B)
LET V2 (ROT(V) (-B))
LET V11 (ROT(V) (2*B))
LET V12 (ROT(V) (-2*B))
LET V13 (ROT (P2 - P1) 0)
LET V13 (V13/(LEN (V13)))
LET V13 (V13*(D/2))
LINE TWO_PTS P1 P2
ARC THREE_PTS (V11+P1) (V12+P1) P2
    LINETYPE
    SOLID
    COLOR
    WHITE Cr
LET V5 (V1/(LEN(V1)))
LET V5 (V5*(-D/2))
ARC DIAMETER (P1+(V1-V5)) (P1+(V1+V5))
LET V6 (V2/(LEN(V2)))
LET V6 (V6*(-D/2))
ARC DIAMETER (P1+(V2+V6)) (P1+(V2-V6))
LET V (V/(LEN(V)))
LET V (V*(-D/2))
ARC THREE_PTS (P1+(V1-V5)) (P1+(V2-V6)) (P2-V)
ARC THREE_PTS (P1+(V1+V5)) (P1+(V2+V6)) (P2+V)
END_LOOP
END_DEFINE

I started but have problem with vectors :(

Could you help me ?

Thanks

jkramer 06-17-2015 06:05 AM

Re: Circular slot in Modeling
 
Hi,

just came across your post, and couldn't resist...
This kind of slots are too common not to have a button for it :-)
Here's my way of doing it. The code could be shorter if I would have nested some formulas, but this makes all the math easier to understand for myself...
If you copy-paste the code below to an empty text file with the extension .lsp, it should work.
By the way, I assumed that you wanted to draw a circular slot on a workplane. For creating one in an Annotation Drawing, a couple of things need to be changed.
Code:

(in-package :JAAPS_TOOLS)
(use-package :OLI)

(sd-defdialog 'circular_slot
  :dialog-title "Circular Slot"
  :toolbox-button t
  :variables
  '(
    (point_1 :value-type :point-2d
            :Title "Center"
                :next-variable 'point_2
        )
    (point_2 :value-type :point-2d
            :title "Pick Point"
                :next-variable 'width
        )
    (width :value-type :positive-length
          :title "Width"
          :next-variable 'angle
        )
        (angle :value-type :number :title "+/- Angle")
        (GO :toggle-type :wide-toggle :title "Create Slot!" :push-action (progn
        (sd-call-cmds(create_circular_slot point_1 point_2 width angle))
        :next-variable 'point_1
        (setf point_1 nil)
        (setf point_2 nil)
        );progn
        )
        );variables
        :local-functions
          '(
)

        :ok-action
        '()
)

(defun create_circular_slot (point_1 point_2 width angle)
                        (setf angle (/ (* pi angle) 180))
                        (setf point_1_x (gpnt2d_x point_1))
                        (setf point_1_y (gpnt2d_y point_1))
                        (setf point_2_x (gpnt2d_x point_2))
                        (setf point_2_y (gpnt2d_y point_2))
                        (setf delta_x (- point_2_x point_1_x))
                        (setf delta_y (- point_2_y point_1_y))
                        (setf radius (sqrt (+ (expt delta_x 2) (expt delta_y 2))))
                        (setf r_max (+ radius (/ width 2)))
                        (setf r_min (- radius (/ width 2)))
                        (setf abs_angle (asin (/ delta_y radius)))
                        (if (< delta_x 0) (setf abs_angle (- pi abs_angle))())
                        (setf angle_1 (- abs_angle angle))
                        (setf angle_2 (+ abs_angle angle))
                        (setf begin_1_x (* r_min (cos angle_1)))
                        (setf begin_1_y (* r_min (sin angle_1)))
                        (setf center_1_x (* radius (cos angle_1)))
                        (setf center_1_y (* radius (sin angle_1)))
                        (setf end_1_x (* r_max (cos angle_1)))
                        (setf end_1_y (* r_max (sin angle_1)))
                        (setf begin_2_x (* r_max (cos angle_2)))
                        (setf begin_2_y (* r_max (sin angle_2)))
                        (setf center_2_x (* radius (cos angle_2)))
                        (setf center_2_y (* radius (sin angle_2)))
                        (setf end_2_x (* r_min (cos angle_2)))
                        (setf end_2_y (* r_min (sin angle_2)))
                        (setf begin_1 (gpnt2d begin_1_x begin_1_y))
                        (setf center_1 (gpnt2d center_1_x center_1_y))
                        (setf end_1 (gpnt2d end_1_x end_1_y))
                        (setf begin_2 (gpnt2d begin_2_x begin_2_y))
                        (setf center_2 (gpnt2d center_2_x center_2_y))
                        (setf end_2 (gpnt2d end_2_x end_2_y))
                        (ARC :CENTER center_1 begin_1 end_1)
                        (ARC :CENTER center_2 begin_2 end_2)
                        (ARC :CENTER point_1 begin_1 end_2)
                        (ARC :CENTER point_1 end_1 begin_2)
);defun



All times are GMT -8. The time now is 09:32 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.