วันพฤหัสบดีที่ 12 พฤศจิกายน พ.ศ. 2563

Slope Line

 

;|

       Slope Line

       - Select Top slope

       - Select bottom slope

       - Select Color By Dialog

       - Enter Line slope distance

|;

(defun slope-line (/ is-on-pl? talud_boven talud_onder  afstand     

                                         afstand_totaal count p1 p2 colr

                    )

 

(defun is-on-pl? (ename pkt /)

       (vl-catch-all-apply

              'vlax-curve-getdistatpoint

                     (list

                           ename

                           pkt

                     ) ;_ end of list

       ) ;_ end of vlax-curve-getdistatpoint

       pkt

) ;_ end defun

 

(vl-load-com)

 

       (if (and (setq talud_boven (car (entsel "\nSelect top slope: ")))

               (setq talud_onder (car (entsel "\nSelect bottom slope: ")))

             (setq colr (acad_colordlg 8))

              ) ;_ end of and

    (progn

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

    (or afstand (setq afstand 10.0))

        (setq afstandtemp

            (getDist (strcat "Line slope distance <"

                             (rtos afstand 2 2)

                                     ">: "

                     ) ;_ strcat

            ) ;_ getint

        ) ;_ setq

    (and afstandtemp (setq afstand afstandtemp))

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

       ;(setq colr 8)

              (setq afstand_totaal 0)

              (setq count 0)

              (setq p1 (vlax-curve-getstartpoint

                                  talud_boven

                           ) ;_ end of vlax-curve-getstartpoint

              ) ;_ end of setq

              (while p1

                     (if (equal (/ count 2.0) (fix (/ count 2.0)) 0.001)

                           (setq p2

                                         (vlax-curve-getclosestpointto

                                                talud_onder

                                                p1

                                         ) ;_ end of vlax-curve-getclosestpointto

                           ) ;_ end of setq

                           (setq p2

                                  (mapcar '(lambda (x) (/ x 2))

                                         (mapcar '+

                                                       p1

                                                       (vlax-curve-getclosestpointto

                                                              talud_onder

                                                              p1

                                                       ) ;_ end of vlax-curve-getclosestpointto

                                         ) ;_ end of mapcar

                                  ) ;_ end of mapcar

                           ) ;_ end of setq

                     ) ;_ end of if

                     (entmake

                           (list '(0 . "LINE")

                                         (cons 10 p1)

                                         (cons 11 p2)

                                                                                  ;'(62 . 1) ; standaard colour

                                         (cons 62 colr)              ; colour by dialog

                           ) ;_ end of list

                     ) ;_ end of entmake

                     (if (not (vl-catch-all-error-p

                                  (setq

                                         p1

                                         (is-on-pl?

                                                talud_boven

                        (vl-catch-all-apply

                          'vlax-curve-getpointatdist

                          (list talud_boven

                                (if (<

                                      (setq afstand_totaal

                                             (+ afstand_totaal afstand)

                                      )

                                      (vlax-curve-getdistatpoint

                                        talud_boven

                                        (vlax-curve-getendpoint talud_boven)

                                      )

                                    )

                                  afstand_totaal

                                  nil

                                ) ;_ end of if

                          ) ;_ end of list

                        ) ;_ end of vl-catch-all-apply

                                         ) ;_ end of is-on-pl?

                                  ) ;_ end of setq

                ) ;_ end of vl-catch-all-error-p

                           ) ;_ end of not

                           p1

                           (setq p1 nil)

                     ) ;_ end of if

                     (setq count (1+ count))

              ) ;_ end of while

    ) ;_ end of progn

       ) ;_ end of if

(princ)

) ;_ end of defun

(defun c:spl ()

       (slope-line)

)

(prompt "\nEnter SPL to Start Slope Line.")

วันอาทิตย์ที่ 8 พฤศจิกายน พ.ศ. 2563

Simple Curve

 

;;-------------Start Copy--------------------

;|

      Create and Design by AutolispTH November 2020

      Contact AutolispTH@hotmail.com

      - Select Sinlge curve or Multi curve

      - Pick Position the data table

|;

(vl-load-com)

(defun c:spc ( / ss ctr obj )

(setq old_cmdecho  (getvar "cmdecho"))  ;  cmdecho

(setq old_osnap (getvar "osmode"))  ; osnap

(setq old_layer (getvar "clayer")) ;  layer

(setvar "cmdecho" 0)    ;  (off) cmdecho

(setvar "osmode" 0)

      (if (not (tblsearch "LAYER" "Simple_Curve"));;<=== Layer Name

            (command "._layer" "_M" "Simple_Curve" "_Color" "2" "" "LType" "Continuous" "" "");;<=== Layer Name

      )

      (if (not (tblsearch "LAYER" "Simple_Curve_Data"));;<=== Layer Name

            (command "._layer" "_M" "Simple_Curve_Data" "_Color" "3" "" "LType" "Continuous" "" "");;<=== Layer Name

      )

(princ "\n Select Simple Curve")   

(if (setq ss (ssget '((0 . "ARC"))))

      (progn

            (setq ctr 0)

            (repeat (sslength ss)

                  (setq obj (vlax-ename->vla-object (ssname ss ctr)))               

                  (setq ce (vlax-get obj 'center))

                  (setq sp (vlax-get obj 'startpoint))

                  (setq ep (vlax-get obj 'endpoint))

                  (setq len (vlax-get obj 'arcLength ))

                  (setq rad (vlax-get obj 'radius))

                  (setq dd (/ 5729.58 rad))

                  (setq ad (dms dd))

                  (setq ang (cvunit (vlax-get obj 'totalAngle)"radians" "degrees"));ANG

                  (setq aa (dms ang))

                  (setq lc (*(* 2.0 rad)(sin (dtor(/ ang 2.0)))))     ;C

                  (setq lt (* rad (tan (dtor(/ ang 2.0)))))          ;T

                  (setq lm (* (/ lc 2.0)(tan (dtor(/ ang 4.0)))))    ;M

                  (setq le (* lt(tan (dtor(/ ang 4.0)))))                  ;E

                  (setq pc (polar sp (angle sp ep) (/ lc 2.0)))

                  (setq p1 (polar ce (angle ce pc) (+ rad le)))

                  (setvar "clayer" "Simple_Curve")

                  (command "_pline" sp ce ep p1 "c")

                  (command "_pline" sp ep "")

                  (princ)

                  (setq ctr (1+ ctr))

                  (data)

            );repeat

      )

);if ss

;(princ (strcat "\n \U+0394 = " aa "\n D = " ad))

(setvar "cmdecho" old_cmdecho)  ; old_cmdecho

(setvar "osmode" old_osnap) ; old_osnap

(setvar "clayer" old_layer) ; old_layer

(princ)

);defun

(prompt "\nEnter SPC to Start Simple Curve.")

(defun data ()

      (setq txth 2.5    ;Text Height

              dec 3           ;Number Decimal

              styl (getvar "TEXTSTYLE")

      )

      (setq pt (getpoint "\n Pick Data Table Point :"))

;;-------------table points--------------

      (setq pta (list (+(car pt)(* txth 45))(cadr pt))

              pt1 (list (car pt)(-(cadr pt)(* txth 4)))

              pt1a (list (+(car pt1)(* txth 45))(cadr pt1))

              pt2 (list (car pt1)(-(cadr pt1)(* txth 8)))

              pt2a (list (+(car pt2)(* txth 45))(cadr pt2))

              pt3 (list (car pt2)(-(cadr pt2)(* txth 4)))

              pt3a (list (+(car pt3)(* txth 45))(cadr pt3))

              pt4 (list (+(car pt)(* txth 22))(cadr pt))

              pt4a (list (car pt4)(-(cadr pt4)(* txth 4)))

      )

;;-------------Text Points----------------

      (setq ptxt1 (list (+(car pt)txth)(-(cadr pt)(* txth 2.5)))

              ptxt2 (list (+(car pt4)txth)(-(cadr pt4)(* txth 1.75)))

              ptxt3 (list (car ptxt2)(-(cadr ptxt2)(* txth 1.5)))

              ptxt4 (list (+(car pt1)txth)(-(cadr pt1)(* txth 1.75)));;new row

              ptxt5 (list (car ptxt4)(-(cadr ptxt4)(* txth 1.5)))

              ptxt6 (list (car ptxt5)(-(cadr ptxt5)(* txth 1.5)))

              ptxt7 (list (car ptxt6)(-(cadr ptxt6)(* txth 1.5)))

              ptxt8 (list (car ptxt7)(-(cadr ptxt7)(* txth 1.5)))

      )

      (setq ptxt9 (list (+(car pt4a)txth)(-(cadr pt4a)(* txth 1.75)));;new row

              ptxt10 (list (car ptxt9)(-(cadr ptxt9)(* txth 1.5)))

              ptxt11 (list (car ptxt10)(-(cadr ptxt10)(* txth 1.5)))

              ptxt12 (list (car ptxt11)(-(cadr ptxt11)(* txth 1.5)))

              ptxt13 (list (car ptxt12)(-(cadr ptxt12)(* txth 1.5)))

              angt (/ (* (angle pt pta) 180) pi)

      )

      (setvar "clayer" "Simple_Curve_Data")

      (command "_text" "_j" "bl" ptxt1 txth angt "P.I.    STA.");;text1

      (command "_text" "_j" "bl" ptxt2 txth angt (strcat "N = " (countn(cadr p1))));;text2 N

      (command "_text" "_j" "bl" ptxt3 txth angt (strcat "E = " (countn(car p1))));;text3 E

      (command "_text" "_j" "bl" ptxt4 txth angt (strcat "\U+0394 = " aa));;text4 Delta

      (command "_text" "_j" "bl" ptxt5 txth angt (strcat "D = " ad));;text5 D

      (command "_text" "_j" "bl" ptxt6 txth angt (strcat "R = " (rtos rad 2 dec)" M."));;text6 R

      (command "_text" "_j" "bl" ptxt7 txth angt (strcat "T = " (rtos lt 2 dec) " M."));;text7 T

      (command "_text" "_j" "bl" ptxt8 txth angt (strcat "L = " (rtos len 2 dec)" M."));;text8 L

      (command "_text" "_j" "bl" ptxt9 txth angt (strcat "E = " (rtos le 2 dec) " M."));;text9 E

      (command "_text" "_j" "bl" ptxt10 txth angt (strcat "V = " "    K.P.H."));;text9 E

      (command "_text" "_j" "bl" ptxt11 txth angt (strcat "S.E. = " "    M/M"));;text9 E

      (command "_text" "_j" "bl" ptxt12 txth angt (strcat "Ts. = " "    M."));;text9 E

      (command "_text" "_j" "bl" ptxt13 txth angt (strcat "W = " "    M."));;text9 E

      (command "_pline" pt pta pt3a pt3 "c")

      (command "_pline" pt1 pt1a "")

      (command "_pline" pt2 pt2a "")

      (command "_pline" pt4 pt4a "")

)

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

(defun tan (x)

    (/ (sin x)(cos x))

)

(defun arsin (x)

    (setq y (sqrt (- 1 (* x x))))

    (atan x y)

)

(defun arcos (x)

    (- (/ pi 2)(arsin x))

)

(defun rtod (x)

    (/ (* x 180) pi)

)

(defun dtor (x)

    (* x (/ pi 180))

)

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

(defun DMS (ang) ;;degrees minutes seconds (ang=degrees)

      (setq angA (angtos (* ang (/ pi 180)) 1 3)

              na (strlen anga)

      )

      (setq aa (strcat (SUBSTR anga 1 2) "\U+00B0-"

                               (SUBSTR anga 4 2)"'-"

                               (SUBSTR anga 7 (- na 7)) "''"

                   )

      )

)

(defun countn (numx /);;100000.000 ==> 100,000.000

      (setq num (rtos numx 2 3))

      (setq tnum

            (cond ((< (read num) 1000) (strcat (SUBSTR num 1 3)));;100

                    ((and (>= (read num)  1000)(<(read num)  10000))  (strcat (SUBSTR num 1 1) "," (SUBSTR num 2 )));;1,000.000(SUBSTR num 5 4)

                    ((and (>= (read num)  10000)(<(read num)  100000)) (strcat (SUBSTR num 1 2) "," (SUBSTR num 3 )));;10,000.000(SUBSTR num 6 4)

                    ((and(>= (read num)  100000)(<(read num)  1000000)) (strcat (SUBSTR num 1 3) "," (SUBSTR num 4 )));;100,000.000(SUBSTR num 7 4)

                    ((and(>= (read num)  1000000)(<(read num)  10000000))(strcat (SUBSTR num 1 1) "," (SUBSTR num 2 3) "," (SUBSTR num 5 )));;1,000,000.000(SUBSTR num 8 4)

                    ((and(>= (read num)  10000000)(<(read num)  100000000))(strcat (SUBSTR num 1 2) "," (SUBSTR num 3 3) "," (SUBSTR num 6 )));;10,000,000(SUBSTR num 9 4)

                    ((and(>= (read num)  100000000)(<(read num)  1000000000))(strcat (SUBSTR num 1 3) "," (SUBSTR num 4 3) "," (SUBSTR num 7 )));;100,000,000.000(SUBSTR num 10 4)

            );cond

      );setq

      ;(setq cnum (atof tnum))

)

;;----------------End Copy---------------------

วันจันทร์ที่ 2 พฤศจิกายน พ.ศ. 2563

วันเสาร์ที่ 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. ")

วันอาทิตย์ที่ 26 กรกฎาคม พ.ศ. 2563

breakpipe

breakpipe

(defun c:breakpipe ()

(setq old_cmdecho  (getvar "cmdecho"))

(setq old_osnap (getvar "osmode"))

(setq pe (getvar 'PEDITACCEPT))

(setvar 'PEDITACCEPT 1)

(setvar "cmdecho" 0)

(setvar "osmode" 1)

(while (setq p1 (getpoint "\nPick Frist Point :"))

              (setq p2 (getpoint p1 "\nPick Second Point :"))

(setvar "osmode" 0)

       (setq ang(angle p1 p2)

                dis (distance p1 p2)

                dis2 (/ dis 2.0)

                dis4 (/ dis 4.0)

                dis8 (/ dis 8.0)

       )

       (setq p3 (polar p1 ang dis2)

                p3a (polar p1 ang dis4)

                p3b (polar p3 ang dis4)

                p4 (polar p3a (+ ang 1.5708) dis8); 1.5708 = 90.0 dreegee to radial

                p5 (polar p3b (+ ang 1.5708) dis8)

                p6 (polar p3b (- ang 1.5708) dis8)

       )

       (command "_arc" p1 p4 p3)

       (setq ss1 (ssget "L"))

       (command "_arc" p3 p5 p2)

       (setq ss2 (ssget "L"))

       (command "_arc" p3 p6 p2)

       (setq ss3 (ssget "L"))

       (command "_.pedit" "_M" ss1 ss2 ss3 "" "_J" "" "")

(setvar "osmode" 1)

);while

(setvar "cmdecho" old_cmdecho)

(setvar "osmode" old_osnap)

(setvar 'PEDITACCEPT pe)

(princ)

);end


วันอังคารที่ 16 มิถุนายน พ.ศ. 2563

Define Functions

Define Functions   ทุกฟังก์ชั่นที่เราสร้าง กำหนดไว้ให้เริ่มต้นด้วยการประกาศ ฟังก์ชั่น ด้วย defun เสมอ เช่น  (defun myProg () หรือ (defun C:myProg () ทั้งสองแบบ มีความแตกต่างระหว่างการใช้  C: และไม่ได้ใช้ C: นำหน้าชื่อโปรแกรมของเรา ซึ่งจะมีความต่างกัน เวลาเรียกใช้งาน แต่ตอนนี้ มารู้จักอีกฟังก์ชั่นการใช้  AutoLISP ในโปรแกรมแรกของเรา myProg ก็คือฟังก์ชั่น princ เพียงพิมพ์คำสั่ง (princ "AutoLISP") ที่ Command : (princ " AutoLISP ") แล้ว Enter จะได้ผลลัพธ์  AutoLISP ออกมา

ทีนี้เรามาลองใส่  Command: (defun myProg () (princ "AutoLISP")) และกด  Enterโปรแกรมจะแสดงชื่อฟังก์ชั่น (ชื่อโปรแกรม) ของเราเอง MYPROG ตอนนี้ ฟังก์ชั่นของเราพร้อมแล้วลองเรียกใช้ฟังก์ชั่นของเราที่  Command: (myprog)โปรแกรมจะประมวลผลและพิมพ์  AutoLISP จากนั้น โปรแกรมสะท้อนคำสั่งสุดท้าย "AutoLISP" เสมอเรียกว่าเอคโค่ echo  นั่นคือสาเหตุที่ทำให้ออกมาเป็น  AutoLISP  "AutoLISP"  วิธีการที่จะกำจัด  echo

คือการใช้ princ เป็นคำสั่งสุดท้ายในโปรแกรมของเรา เราลองเขียน (princ) เพิ่มในโปรแกรม เป็นฟังก์ชั่นที่จะกำจัด  echo ออกไปดังนี้

Command: (defun myProg () (princ "AutoLISP") (princ))

แล้วก็เรียกใช้โปรแกรมของเรา  (myprog) และกด Enter

* ผลปรากฏว่า echo หายไปแล้ว ในบางทีเราอาจจะพบคำว่า nil แทนในโปรแกรมอื่นๆ มันเป็น echo เหมือนกัน *

เจ้า C: ที่เราได้กล่าวถึงก่อนหน้านี้ เจ้าตัวนี้ C: จะบอกให้เจ้า AutoCAD ให้พร้อมรับคำสั่งและทำซ้ำโปรแกรมของเรา เราลองใส่ C: เพิ่มเข้าไปจากตัวอย่างที่แล้วเป็น

Command: (defun C:myProg () (princ "\n Autolisp") (princ))

แล้วเราลองเรียกใช้งานดูทั้งแบบ (myprog) และ (c:myprog) และลอง myprog ด้วย

จะเห็นได้ว่าถ้าเราใส่ C: นำหน้าเราสามารถเรียกใช้จากชื่อได้โดยตรงไม่ต้องมีวงเล็บเปิดและปิดหน้าหลังเลยทำให้เราสะดวกในการเรียกใช้งาน