วันเสาร์ที่ 31 ตุลาคม พ.ศ. 2563

ความลาดเอียง (Slope)

 

ความลาดเอียง (Slope)

ตั้งค่าความสูงตัวอักษร และจำนวนเลขทศนิยมที่ต้องการ แล้วเลือกว่าต้องการแบบอัตราส่วน หรือเปอร์เซ็นต์ แล้วเลือกเส้นความลาดเอียงที่ต้องการ

;;+--- Slope -----------------+

;;|  Select Slope line        |

;;|  options Ratio or Percent |

;;+---------------------------+

(defun c:slp ()

(setq old_cmdecho  (getvar "cmdecho"))

(setq old_osnap (getvar "osmode")) 

(setvar "CMDECHO" 0)

(setvar "osmode" 0)

      (setq ;txth 0.2    ;Text Height

              ;dec 1           ;Number Decimal

              styl (getvar "TEXTSTYLE")

      )

(initget "Ratio Percent")

      (setq opt (getkword "Select Options =[ Ratio/Percent ] : < Ratio >"))

      (if (= opt "") (setq opt "Ratio"))   

;;-------------------------------------------------------

      (or txth (setq txth 10.0))

        (setq txthtemp

            (getDist (strcat "Enter Text Height <"

                             (rtos txth 2 2)

                                     ">: "

                     ) ;_ strcat

            ) ;_ getint

        ) ;_ setq

    (and txthtemp (setq txth txthtemp))

;;-------------------------------------------------------    

      (or dec (setq dec 2))

        (setq dectemp

            (getDist (strcat "Enter Number Decimal <"

                             (rtos dec 2 0)

                                     ">: "

                     ) ;_ strcat

            ) ;_ getint

        ) ;_ setq

    (and dectemp (setq dec (fix dectemp)))

;;-------------------------------------------------------

     

(while (setq e (car (entsel "\nSelect Slope line : ")))

      (setq x_object (vlax-Ename->Vla-Object e))

      (setq x_length (vlax-curve-getdistatparam x_object

                           (vlax-curve-getendparam x_object ))

      )

      (setq pl (vlax-curve-getstartpoint x_object);start point

              pt (vlax-curve-getendpoint x_object);end point

      )    

;;---------1---------------

(if (and(> (car pt)(car pl))(> (cadr pt)(cadr pl)))

      (progn

            (setq pct (list (car pt)(cadr pl)(caddr pt))

                    disl (distance pl pct)

                    dist (distance pt pct)

                    ;rat (/ disl dist)

                    txt (if (= opt "Ratio")

                              (strcat "1 : " (rtos (/ disl dist) 2 dec));" Q 1"

                              (strcat "Slope " (rtos (* (/ dist disl) 100.0) 2 dec) "%")

                          )

                    ptx  (polar pl (angle pl pt) (/ (distance pl pt) 2.0))

                    ptxt (polar ptx (+(angle pl pt)(* 90 (/ pi 180))) txth)

            )

            ;(princ (strcat "\n 1"))

            (command "_text" "_j" "bc" ptxt txth (/ (* (angle pl pt) 180) pi) txt)

           

      )

)

;;---------2---------------

(if (and(< (car pt)(car pl))(< (cadr pt)(cadr pl)))

      (progn

            (setq pct (list (car pl)(cadr pt)(caddr pt))

                    disl (distance pt pct)

                    dist (distance pl pct)

                    ;rat (/ disl dist)

                    txt (if (= opt "Ratio")

                              (strcat "1 : " (rtos (/ disl dist) 2 dec));" Q 1"

                              (strcat "Slope " (rtos (* (/ dist disl) 100.0) 2 dec) "%")

                          )

                    ptx  (polar pt (angle pt pl) (/ (distance pl pt) 2.0))

                    ptxt (polar ptx (+(angle pt pl)(* 90 (/ pi 180))) txth)

            )          

            ;(princ (strcat "\n 2"))

            (command "_text" "_j" "bc" ptxt txth (/ (* (angle pt pl) 180) pi) txt)

           

      )

)

;;---------3---------------

(if (and(> (car pl)(car pt))(> (cadr pt)(cadr pl)))

      (progn

            (setq pct (list (car pt)(cadr pl)(caddr pt))

                    disl (distance pl pct)

                    dist (distance pt pct)

                    ;rat (/ disl dist)

                    txt (if (= opt "Ratio")

                              (strcat "1 : " (rtos (/ disl dist) 2 dec));" Q 1"

                              (strcat "Slope " (rtos (* (/ dist disl) 100.0) 2 dec) "%")

                          )

                    ptx  (polar pt (angle pt pl) (/ (distance pl pt) 2.0))

                    ptxt (polar ptx (+(angle pt pl)(* 90 (/ pi 180))) txth)

            )

            ;(princ (strcat "\n 3"))

            ;(command "_text" "_non" ptxt txth (/ (* (angle pt pl) 180) pi) txt)

            (command "_text" "_j" "bc" ptxt txth (/ (* (angle pt pl) 180) pi) txt)

      )

)

;;---------4---------------

(if (and(< (car pl)(car pt))(> (cadr pl)(cadr pt)))

      (progn

            (setq pct (list (car pl)(cadr pt)(caddr pt))

                    disl (distance pt pct)

                    dist (distance pl pct)

                    ;rat (/ disl dist)

                    txt (if (= opt "Ratio")

                              (strcat "1 : " (rtos (/ disl dist) 2 dec));" Q 1"

                              (strcat "Slope " (rtos (* (/ dist disl) 100.0) 2 dec) "%")

                          )

                    ptx  (polar pt (angle pt pl) (/ (distance pl pt) 2.0))

                    ptxt (polar ptx (-(angle pt pl)(* 90 (/ pi 180))) txth)

            )

            ;(princ (strcat "\n 3"))

            (command "_text" "_j" "bc" ptxt txth (/ (* (angle pl pt) 180) pi) txt)

      )

)

)    

(setvar "cmdecho" old_cmdecho)

(setvar "osmode" old_osnap)

 

(princ)

)

(prompt "\nEnter SLP to start. ")