(in-package :my-custom-package) (use-package :oli) (sd-defdialog 'arc-text :dialog-title (sd-multi-lang-string "Text on arc" :german "Text auf Bogen") :toolbox-button :force :variables '( (strt-pnt :title (sd-multi-lang-string "Start point" :german "Startpunkt") :value-type :point-3d) (arc-edge :title (sd-multi-lang-string "Arc edge" :german "Bogenkante") :selection (*sd-circle-2d-seltype* *sd-arc-2d-seltype* *sd-circle-3d-seltype* *sd-arc-3d-seltype*)) (txt :title (sd-multi-lang-string "Text" :german "Text") :value-type :string) (txt-type :title (sd-multi-lang-string "Text type" :german "Textart") :range ("none") :initial-value (let ((fonts (sort (label_3d:inquire-label-fonts) #'sd-string<))) (sd-set-range 'txt-type fonts) (first fonts))) (txt-size :title (sd-multi-lang-string "Text size" :german "Textgröße") :initial-value 10 :value-type :positive-number) (txt-angle :title (sd-multi-lang-string "Text angle" :german "Textwinkel") :initial-value 0 :value-type :number) (txt-gap :title (sd-multi-lang-string "Character gap (angle)" :german "Buchst. Abstand (Winkel)") :initial-value 0.5 :value-type :number) (mono-spc :title (sd-multi-lang-string "Monospace font" :german "Festbreitenschrift") :value-type :boolean :initial-value nil :after-input (if mono-spc (setq txt-gap 5) (setq txt-gap 0.5))) (go-action :title (sd-multi-lang-string "Create text" :german "Text erstellen") :toggle-type :wide-toggle :push-action (sd-call-cmds (go-create-text strt-pnt arc-edge txt txt-size txt-angle txt-gap txt-type mono-spc))))) (defun go-create-text (strt-pnt arc-edge txt txt-size txt-angle txt-gap txt-type mono-spc) (let* ( txt-pos char-gap (wp-rot-ang 0) (wp-temp (sd-gen-obj-basename :workplane :parent "/" :prefix "txt-temp-plane")) (wp-master (sd-gen-obj-basename :workplane :parent "/" :prefix "txt-master-plane")) (all-prop (sd-inq-geo-props arc-edge :dest-space :global)) (cnt-pnt (sd-circle-center all-prop)) (u-dir (sd-vec-subtract strt-pnt cnt-pnt)) (axis-r (sd-circle-normal all-prop))) (create_workplane :new :name wp-master :owner "/" :pt_dir :origin cnt-pnt :normal axis-r :u_dir u-dir) (setq txt-pos (gpnt3d_x (sd-vec-xform strt-pnt :source-space :global :dest-space (sd-inq-curr-wp)))) (loop for char across txt do (let ( (spc-char nil)) (create_workplane :new :name wp-temp :owner "/" :pt_dir :origin cnt-pnt :normal axis-r :u_dir u-dir) (when (string= char " ") (setq char "X") (setq spc-char t)) (create_geo_text :text (format nil "~a" char) :pos (make-gpnt2d :x 0 :y txt-pos) :angle txt-angle :size txt-size :font txt-type) (position_wp :current :rotate :axis :w :rotation_angle (/ pi -2)) (position_wp :current :rotate :axis :w :rotation_angle (/ (* pi wp-rot-ang) 180)) (setq char-gap (proj-curr-wp-geo-to-master wp-master (format nil "/~a" wp-temp) mono-spc spc-char)) (decf wp-rot-ang txt-gap) (when (not mono-spc) (decf wp-rot-ang char-gap)) (delete_3d (format nil "/~a" wp-temp)))) (current_wp (format nil "/~a" wp-master)))) (defun proj-curr-wp-geo-to-master (wp-master wp-temp mono-spc spc-char) (let ( (max-x 0) (min-y 140000) (all-2d-edges-on-wp (sd-call-cmds (get_selection :focus_type *sd-edge-2d-seltype* :curr_wp_only :select :all_2d)))) (current_wp (format nil "/~a" wp-master)) (dolist (2d-edge-proj all-2d-edges-on-wp) (when (not mono-spc) (let ( (max-x-ll (gpnt3d_x (sd-edge-ll-pnt (sd-inq-edge-geo 2d-edge-proj :dest-space :local)))) (max-x-ur (gpnt3d_x (sd-edge-ur-pnt (sd-inq-edge-geo 2d-edge-proj :dest-space :local)))) (min-y-ll (gpnt3d_y (sd-edge-ll-pnt (sd-inq-edge-geo 2d-edge-proj :dest-space :local)))) (min-y-ur (gpnt3d_y (sd-edge-ur-pnt (sd-inq-edge-geo 2d-edge-proj :dest-space :local))))) (if (>= max-x-ll max-x-ur) (when (> max-x-ll max-x) (setq max-x max-x-ll)) (when (> max-x-ur max-x) (setq max-x max-x-ur))) (if (<= min-y-ll min-y-ur) (when (< min-y-ll min-y) (setq min-y min-y-ll)) (when (< min-y-ur min-y) (setq min-y min-y-ur))))) (when (not spc-char) (uic_project_2d_edge 2d-edge-proj))) (current_wp wp-temp) (inq-wp-rot-angle max-x min-y))) (defun inq-wp-rot-angle (max-x min-y) (let (all-2d-c-lines-on-wp) (c_line_inf :two_points (make-gpnt2d :x max-x :y min-y) (make-gpnt2d :x 0 :y 0)) (c_line_inf :vertical 0) (setq all-2d-c-lines-on-wp (sd-call-cmds (get_selection :focus_type *sd-c-line-2d-seltype* :curr_wp_only :select :all_2d))) (- 180 (sd-rad-to-deg (sd-vec-angle-between (sd-line-dir (sd-inq-geo-props (first all-2d-c-lines-on-wp) :dest-space :local)) (sd-line-dir (sd-inq-geo-props (second all-2d-c-lines-on-wp) :dest-space :local)))))))