วันเสาร์ที่ 26 ธันวาคม พ.ศ. 2563

Scale Area

 

***ScaleArea ตัวนี้จะมีสองส่วนด้วยกันเป็นไฟล์ Dialog Control กับตัว Lisp File ให้ Copy แยกเป็นไฟล์ ScaleArea.dcl กับ ScaleArea.lsp โดยสร้างโฟลเดอร์ใหม่แล้วบันทึกทั้งสองไฟล์นี้ไว้ในโฟลเดอร์นี้แล้วทำการ Set Support Files Search Path โฟลเดอร์นี้ด้วยจึงจะสามารถใช้งานได้***

//Save As Name : ScaleArea.dcl

ScaleArea : dialog

{

       label = "Scale AREA ";

              : boxed_row

              {

                     label = "ย่อ - ขยายพื้นที่ / Scale Area";

                     width = 15;

                     fixed_width = true;

                     : column

                     {

                           : button

                           {

                                  label = "Pick Area";

                                  key = "hide";

                                  width = 8;

                                  fixed_width = true;

                                  mnemonic = "P";

                           }                          

                           : edit_box

                           {

                                  key = "eb4";

                                  label = "พื้ น ที่ จ ริ ง    m\U+00B2  ";

                                  width = 8;

                                  fixed_width = true;

                           }

                           : edit_box

                           {

                                  key = "eb5";

                                  label = "พื้นที่ย่อ - ขขาย  m\U+00B2";

                                  width = 8;

                                  fixed_width = true;

                           }                          

                     }                                 

                     : column

                     {                                 

                           : edit_box

                           {

                                  key = "eb1";

                                  label = "&X :";

                                  width = 3;

                                  fixed_width = true;

                           }

                           : edit_box

                           {

                                  key = "eb2";

                                  label = "&Y :";

                                  width = 3;

                                  fixed_width = true;

                           }

                           : edit_box

                           {

                                  key = "eb3";

                                  label = "&Z :";

                                  width = 3;

                                  fixed_width = true;

                           }     

                     }                   

              }     

       ok_cancel;  

       : row

       {

              : image  //define image tile

              {            

                     key = "im" ; //give it a name

                     height = 2.5 ; //and a height

                     width = 10 ; //and now a width

                     alignment = centered;

              } //end image

              : paragraph

              {

                     : text_part

                     {

                           label = "Scale Area by Songkhran Jongkul Sep. 2016";

                     }            

              }//paragraph

       }//boxed_column

}//End

//End of dialog control ScaleArea.dcl

 

;;--------Lisp File Save As Name : ScaleArea.lsp

(defun scar ()

(setq old_cmdecho  (getvar "cmdecho")) 

(setvar "cmdecho" 0)

 

(IF (NOT ptx)    (SETQ ptx "0")  (if (= (type ptx) 'STR)  T (SETQ ptx "0")));edt1

(IF (NOT pty)    (SETQ pty "0")  (if (= (type pty) 'STR)  T (SETQ pty "0")));edt2

(IF (NOT ptz)    (SETQ ptz "0")  (if (= (type ptz) 'STR)  T (SETQ ptz "0")));edt3

(IF (NOT area1)  (SETQ area1 "0")(if (= (type area1) 'STR)T (SETQ area1 "0")));edt4

(IF (NOT area2)  (SETQ area2 "0")(if (= (type area2) 'STR)T (SETQ area2 "0")));edt5

(setq flag 4);setq

  ;set default x,y, and z values

  ;and set flag to 4

 

(if(not(setq dcl_id (load_dialog "ScaleArea.dcl")))

    (progn

              (alert "The DCL file could not be loaded!")

              (exit)

    )

(progn

(while (> flag 2)

    (if (not(new_dialog "ScaleArea" dcl_id))

        (progn

                     (alert "The Scale Area definition could not be loaded!")

                     (exit)

        )

        (progn

;;------------Signager Image---------------------  

              (setq w (dimx_tile "im") ;get image tile width

                       h (dimy_tile "im") ;get image tile height

              );setq

              (start_image "im") ;start the image

              (fill_image 0 0 w h -15) ;fill it with blue

              (mapcar 'vector_image; Color 5

                     (list 36 42 42 48 54 48 48 42 36 21 21 27 27 33 32 32 32 27 27 21  5  5  8 15 11 11  5  5  5  8 18 21 18 11 11 11 15 15 21 18  8 5)

                     (list  8 15 15 27  3  3  3  3  3 11 27 18 18 27 15 15  3 11  3  3  6 14 17 17 24 20 20 20 24 27 27 24 14 14  6  6  6 11  3  3  3 6)

                     (list 36 42 48 54 54 54 48 48 42 21 27 27 33 42 36 36 36 32 27 27  5  8 15 15 15 11 11  5  8 18 21 21 21 18 11 15 15 21 21 21 18 8)

                     (list 22 27 27 27 27  3 18 18  3 17 27 27 27 27 22  8  3  3 11  3 14 17 17 24 24 24 20 24 27 27 24 27 17 14 14  6 11 11  6  6  3 3)

                     (list  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5  5 5)

              );mapcar

              (end_image)

             

              (set_tile "eb1" ptx)

              (set_tile "eb2" pty)

              (set_tile "eb3" ptz)

              (set_tile "eb4" area1)

              (set_tile "eb5" area2)

              (mode_tile "eb1" 1);0 on ;1 off

              (mode_tile "eb2" 1)

              (mode_tile "eb3" 1)

              (mode_tile "eb4" 1)

              (mode_tile "eb5" 0) 

              (mode_tile "eb5" 2)

              ;set focus to x edit box

              (mode_tile "eb4" 2)

              ;set focus to x edit box

              (mode_tile "eb5" 3)

              ;select contents

 

              (action_tile

                     "cancel"

                     "(done_dialog)

                     (setq result nil)

                     (exit)"

              )

 

              (action_tile

                     "accept"

                     "(setq ptx   (get_tile \"eb1\"))

                      (setq pty   (get_tile \"eb2\"))

                      (setq ptz   (get_tile \"eb3\"))

                      (setq area2 (get_tile \"eb5\"))

                      (done_dialog)

                      (setq result T)"

              )

 

              (action_tile

                     "hide"

                     "(done_dialog 4)"

              )

 

              (setq flag (start_dialog))

 

       (if (= flag 4)

       (progn

              (setq selpoint (getpoint "\nInsertion Point: "))

              (setq ptx (rtos (car selpoint) 2 4))

              (setq pty (rtos (cadr selpoint) 2 4))

              (setq ptz (rtos (caddr selpoint) 2 4))

 

              (setq txtH (getvar "TEXTSIZE")); Current height

              (setq txtS (getvar "textstyle")); Current Style

 

              (setq int_reg selpoint)

              (command "._-boundary" int_reg "")

              ;(command "region" "last" "")

              (setq entidad (entlast))

              (setq obj (vlax-ename->vla-object entidad))

              (setq  m_area

              (vla-get-area obj))

              (setq area1 (rtos m_area 2 2))

              (setq sqm m_area)

              (setq rl_r (fix(/ sqm 1600)))

              (setq rl_ng (fix(/ (- sqm (* rl_r 1600)) 400)))

              (setq rl_wa (/ (- sqm (+ (* rl_r 1600) (* rl_ng 400))) 4))

              (setq old_area (strcat "พื้นที่เดิม = " (rtos rl_r 2 0) " ไร่ "(rtos rl_ng 2 0) " งาน " (rtos rl_wa 2 2) " ตารางวา" "\n"

                                         "Old Area = " (rtos sqm 2 2) " m\U+00B2"

                                  )

              )

              (txtme int_reg txtH 8 txtS old_area)

              (princ)

    );progn

       );if flag 4

);progn

);if

);while                    

 

       (setq area1 (atof area1))

       (setq area2 (atof area2))

       (setq scl (sqrt(/ area2 m_area)))

       (command "_scale" entidad "" int_reg scl)

       (setq sqm area2)

       (setq rl_r (fix(/ sqm 1600)))

       (setq rl_ng (fix(/ (- sqm (* rl_r 1600)) 400)))

       (setq rl_wa (/ (- sqm (+ (* rl_r 1600) (* rl_ng 400))) 4))

       (setq new_area (strcat "พื้นที่ ย่อ-ขยาย = " (rtos rl_r 2 0) " ไร่ "(rtos rl_ng 2 0) " งาน " (rtos rl_wa 2 2) " ตารางวา" "\n"

                                  "New Area = " (rtos sqm 2 2) " m\U+00B2"

                                  )

       )

       (txtme int_reg txtH 2 txtS new_area)

      

       (setq area1 (rtos area1 2 3)

                area2 (rtos area2 2 3)  

       )            

  (unload_dialog dcl_id)

 

(setvar "cmdecho" old_cmdecho)

(princ)

);progn

);if not dcl_id

);defun

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

(princ);load clean

 

(defun c:SAR ()

(scar)

)

(prompt "\nCreate and Design by Songkhran Jongkul August 2016")

(prompt "\nEnter SAR to start Scale Area")

      

(defun txtme (ptxt txtH pos txtS txt /)

(entmake

       (list

              (cons 0 "MTEXT")

              (cons 100 "AcDbEntity")

              (cons 100 "AcDbMText")          

              (cons 410 "Model")

              (cons 8 "0")

              (cons 10 ptxt);text position

              (cons 40 txtH);text height

              (cons 71 pos) ; 1=Top Left   /2=Top Center   /3= Top Right

                                  ; 4=Middle Left/5=Middle Center/6=Middle Right

                                  ; 7=Bottom Left/8=Bottom Center/9=Bottom Right

              ;(cons 72 5)

              (cons 7 txtS)

              (cons 1 txt);text massege

              (cons 11 '(1.0 0.0 0.0))

       ); list

); entmake  

)

;;---------------End of Lisp File--------------------

 

วันพฤหัสบดีที่ 24 ธันวาคม พ.ศ. 2563

Boundary and Hatch to Area.

 

;; boundary and hatch to area.

(defun c:BHA (/ pt)

(setq old_cmdecho  (getvar "cmdecho"))

(setvar "cmdecho" 0)

       (setq txtH 10.0); Current height

       (setq txtS (getvar "textstyle")); Current Style

       (setq dec 3)  ; decimal 3  

       (setq tot_area 0.0)

      

       (while (setq pt (getpoint "\nPick internal point: "))

              (command "_.-boundary" "_a" "_i" "_n" "" "" "_non" pt "")

              (command "_.-hatch" "_p" "_solid" pt "")

              (command "_area" "o" "l")

              (setq tot_area (+ tot_area (getvar "area")))                      

       )

       (command "_erase" "l" "")

       (setq txt (strcat (rtos tot_area 2 dec)" m\U+00B2")) ;add , comma 

       (setq ptxt (getpoint "\n Pick Area Location: "))

       ;(setvar "cecolor" old_cecolor)

       (entmake

              (list

                     '(0 . "MTEXT")

                     '(100 . "AcDbEntity")

                     '(100 . "AcDbMText")

                     (cons 10 ptxt)

                     (cons 7  txtS)

                     (cons 40 txtH) 

                     (cons 41 0) ; 0 Width = no wrap

                     (cons 71 5) ; 1=Top Left   /2=Top Center   /3= Top Right

                                         ; 4=Middle Left/5=Middle Center/6=Middle Right

                                         ; 7=Bottom Left/8=Bottom Center/9=Bottom Right

                     (cons 50 0.0) ; rotation angle

                     (cons 1 txt)

              )

       )

(setvar "cmdecho" old_cmdecho)

(princ)

)

(prompt "\nEnter BHA to Start boundary and hatch to area.")


วันอาทิตย์ที่ 20 ธันวาคม พ.ศ. 2563

Layer ON-OFF

;----Save to name layer_of.lsp

;-------------------Layer OFF---------------------

(defun c:lof ( / )

(if (null lnlyr)

 

       (progn

              (setq lnlyr (cdr (assoc 8(entget (car (entsel

                     "\nSelect Object on Layer to turn OFF.")))))

              )

              (command "-layer" "off" lnlyr "")

              (prompt (strcat "\nLayer " lnlyr " has been Temporarily turned OFF, use LON to turn ON."))

       )

       (princ (strcat "\nLayer " lnlyr " is already Temporarily turned OFF."))

)

(princ)

);end layer off

;-------------------Layer ON----------------------

(defun c:lon ( / )

(if (null lnlyr)

    (princ "\nNo Layer is Temporarily turned OFF.")

    (progn

        (princ (strcat "\nTurning ON Temporarily turned OFF layer " lnlyr "."))

        (command "-layer" "on" lnlyr "")

        (setq lnlyr nil)

    )

)

(princ)

);end layer on

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

ส่วนนี้นำไปเพิ่มในไฟล์เมนู ดูเรื่องการ Creating Menu

สร้างไอคอนชื่อ LOF.bmp และ LON.bmp ด้วย

***TOOLBARS

 

**Layer ON-OFF

[_Toolbar("Layer ON-OFF", _Floating, _Show, 202, 163, 1)]

[_Button("Layer OFF", "LOF.bmp", "ICON_24_BLANK")]^C^C^P+

(cond ((not LOF) (prompt "Please Wait...")(load "layer_of"))) LOF (princ)

[_Button("Layer ON", "LON.bmp", "ICON_24_BLANK")]^C^C^P+

(cond ((not LON) (prompt "Please Wait...")(load "layer_of"))) LON (princ)


วันเสาร์ที่ 19 ธันวาคม พ.ศ. 2563

Get Area4

 

(defun rtoc ( n p / d i l x );; n = any number  p = precision

    (setq l (vl-string->list (rtos n 2 p))

          x (cond ((cdr (member 46 (reverse l)))) ((reverse l)))

          i 0

    )

    (vl-list->string

        (append

            (reverse

                (apply 'append

                    (mapcar

                       '(lambda ( a b )

                            (if (and (zerop (rem (setq i (1+ i)) 3)) b)

                                (list a 44)

                                (list a)

                            )

                        )

                        x (append (cdr x) '(nil))

                    )

                )

            )

            (member 46 l)

        )

    )

);end

 

(defun c:GAR(/ clor tot_area )

(setq old_cecolor (getvar "cecolor"))

(setq old_cmdecho  (getvar "cmdecho"))

 

(setvar "cmdecho" 0)

(setq clor 1) ;start colour 1 red

(setq dec 3)  ;decimal 3

 

(initget "1 2")

       (setq opt_ar (getkword "\nSelect Options : \n [1  Rai-Ngan-Wah / 2  square metre.] <1> "))

       (if (= opt_ar "")(setq opt_ar "1"))

(initget "1 2")

       (setq opt (getkword "\nSelect Options : \n [1  Pick in Area. / 2  Select Polyline Closed.] <1> "))

       (if (= opt "")(setq opt "1"))

(initget "Yes No")

       (setq opt_ab (getkword "\nAuto Boundary : \n [Yes / No] <Yes> "))

       (if (= opt_ab "")(setq opt_ab "Yes"))

(setq txtH 10.0); Current height

(setq txtS (getvar "textstyle")); Current Style

(setq ins 1)

(setq tot_area 0.0)

 

(if (= opt "1")

(while (setq ins (getpoint "\nPick in Area: "))

       (setvar "cecolor" (rtos clor 2 0))

       (command "_boundary" ins "")   

       (command "_area" "o" "l")

       (if (= opt_ab "No")(command "_erase" "l" ""))

       (setq tot_area (+ tot_area (getvar "area")))

       (setq clor (1+ clor))

);while

);if opt "1"

(if (= opt "2")

       (if (setq ss1 (ssget '((-4 . "<OR")

                         (0 . "POLYLINE")

                         (0 . "LWPOLYLINE")

                         (0 . "CIRCLE")

                         (0 . "ELLIPSE")

                         (0 . "SPLINE")

                         (0 . "REGION")

                         (-4 . "OR>")

                        )

                                  )

              )

              (progn

                     (setq nr 0)

                     (setq en (ssname ss1 nr))

                     (while en

                           (command "._area" "_O" en)

                           (command "_chprop" en "" "Color" clor "")

                           (setq tot_area (+ tot_area (getvar "area")))

                           (setq nr (1+ nr))

                           (setq en (ssname ss1 nr))

                           (setq clor (1+ clor))

                     );while

              )

       )

);if opt "2"

(if (= opt_ar "1")

       (setq txt (areath tot_area))

       (setq txt (strcat (rtoc tot_area dec)" m\U+00B2")) ;add , comma

)     

       (setq pt (getpoint "\n Pick Area Location: "))

       (setvar "cecolor" old_cecolor)

       (entmake

              (list

                     '(0 . "MTEXT")

                     '(100 . "AcDbEntity")

                     '(100 . "AcDbMText")

                     (cons 10 pt)

                     (cons 7  txtS)

                     (cons 40 txtH) 

                     (cons 41 0) ; 0 Width = no wrap

                     (cons 71 5) ; 1=Top Left   /2=Top Center   /3= Top Right

                                         ; 4=Middle Left/5=Middle Center/6=Middle Right

                                         ; 7=Bottom Left/8=Bottom Center/9=Bottom Right

                     (cons 50 0.0) ; rotation angle

                     (cons 1 txt)

              )

       )

(setvar "cmdecho" old_cmdecho)

(setvar "cecolor" old_cecolor)

(princ)

)

(prompt "\nEnter GAR to Start Get Area.")

 

(defun areath (sqm / rl_r rl_ng rl_wa th_area)

       (setq rl_r (fix(/ sqm 1600)))

       (setq rl_ng (fix(/ (- sqm (* rl_r 1600)) 400)))

       (setq rl_wa (/ (- sqm (+ (* rl_r 1600) (* rl_ng 400))) 4))

       (setq th_area (strcat (rtos rl_r 2 0) "-"(rtos rl_ng 2 0) "-" (rtos rl_wa 2 2)))                                   

)