วันอาทิตย์ที่ 12 กันยายน พ.ศ. 2564

Import CSV File CADTHAI & AutoCAD

 

;|

       - Import Coordinate X Y from .CSV Excel File.

       - Create by Songkhran Jongkul September 2021

       - Contact : https://www.facebook.com/groups/AutolispTH

|;

(defun c:imcsv (/ lst)

(setq old_cmdecho  (getvar "cmdecho"))

(setq old_osnap (getvar "osmode"))

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

(defun Deconstruct_String (st delimiter / p l)

       (while (setq p (vl-string-search delimiter st 0))

              (setq l  (cons (substr st 1 p) l)

                       st (substr st (+ p 2) (strlen st))

              )

       )

       (if st (setq l (cons st l)))

       (setq l (reverse l))

)

(setvar "cmdecho" 0)

(setvar "osmode" 0)

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

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

)

(if (setq file (getfiled "Select .CSV Excel file ..." "" "csv" 16))

       (progn       

              (setq file (open file "r"))

              (while (setq st (read-line file))

                     (setq st (Deconstruct_String st ";"))

                     (setq p (Deconstruct_String (car st) ","))

                     (setq xy (list (read (car p))(read (cadr p))))

                     (setq lst (append lst (list xy)))

              )

              (close file)

              (setvar "clayer" "pline_csv")

              (command "_pline" )

              (foreach x lst

                     (command x)

              )

              (command "")

              (command "_zoom" "_E")

              (setvar "clayer" old_layer)

       )

)

(setq mylst lst)     

(princ)

(setvar "cmdecho" old_cmdecho)

(setvar "osmode" old_osnap)

(setvar "clayer" old_layer)  

(princ)

)

(prompt "\nCreate by Songkhran Jongkul September 2021")

(prompt "\nContact : https://www.facebook.com/groups/AutolispTH")

(prompt "\nEnter IMCSV to start Import Coordinate X Y from .CSV Excel File. ")


วันเสาร์ที่ 11 กันยายน พ.ศ. 2564

Hole Chart for CADTHAI & AutoCAD

 

;|

        - Update Text height and TextStyle

- Hole Chart for CADTHAI and AutoCAD

- Pick Refferent X 0 : Y 0

- Select Circle all and pick a Table point.

- Create by Songkhran Jongkul 11 September 2021

- https://www.facebook.com/groups/AutolispTH

|;

(defun c:hoch ( / e i ss ch_lst)

(setq old_cmdecho  (getvar "cmdecho"))

(setq old_osnap (getvar "osmode")) 

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

(setvar "cmdecho" 0) 

(setvar "osmode" 0)

(setq tstyle "Hole_chart"

  txth (getdist "\nEnter Text Height : <0.025> ")

  fname "ISOCPEUR"

)

(if (not txtH) (setq txtH 0.025))

;;--------------SET LAYER NAME-----------

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

(command "._layer" "_M" "Hole_chart" "_Color" "3" "" "LType" "Continuous" "" "") 

)

(mystyle tstyle txtH fname)

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

(setvar "osmode" 32) 

(initget 1)

(setq ptu (getpoint "\n Pick reference point X 0 : Y 0 "))

(command "_ucs" "o" (strcat (rtos (car ptu)) "," (rtos (cadr ptu)) "")) ;change UCS to pick point

(setvar "osmode" 0) 

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

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

        (progn

(setq is 1)

(repeat (setq i (sslength ss))

(setq e (ssname ss (setq i (1- i)))

  ly (cdr(assoc 8  (entget e))) ;layer name

  ct (cdr(assoc 10 (entget e))) ;center point

  rd (cdr(assoc 40 (entget e))) ;radial   

)

(setq lst (list is  (trans (list (car ct)(cadr ct) (caddr ct)) 0 1) rd)

  ch_lst (append ch_lst (list lst))

)

(setvar "clayer" "Hole_chart")

(myText tstyle "bl" ct txtH 0 (rtos is 2 0))

(setq is (1+ is))

)

)

    )

(setvar "clayer" old_layer)  

;(print ch_lst)

(table)

(command "_UCS" "world")

(setvar "cmdecho" old_cmdecho)

(setvar "osmode" old_osnap)

(setvar "clayer" old_layer)   

(princ)

)


(defun table ()

(initget 1)

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

  pt (trans pt 1 0) ;;change coordinate to new ucs

  wt (* txtH 10)

  ht (* txtH 3)

)

(setq ntab (list "Hole No." " X " " Y " "\U+2205"))

(setq pt1 (list (+(car pt)wt) (cadr pt))

  pt2 (list (+(car pt1)wt)(cadr pt))

  pt3 (list (+(car pt2)wt)(cadr pt))

  pt4 (list (+(car pt3)wt)(cadr pt))

)

(setq ptx1 (list (+(car pt)(/ wt 2)) (-(cadr pt)(/ ht 2)))

  ptxt (list (car ptx1)(-(cadr ptx1)ht))

)

(setvar "clayer" "Hole_chart")

(foreach x ntab

(myText tstyle "mc" ptx1 txtH 0 x)

(setq ptx1 (list (+(car ptx1)wt) (cadr ptx1)))

)

(setq pt0_ (list (car pt)  (-(cadr pt) ht))

  pt1_ (list (car pt1) (-(cadr pt1)ht))

  pt2_ (list (car pt2) (-(cadr pt2)ht))

  pt3_ (list (car pt3) (-(cadr pt3)ht))

  pt4_ (list (car pt4) (-(cadr pt4)ht))

)

(command "_line" (trans pt 0 1) (trans pt4 0 1) "" 

"_line" (trans pt0_ 0 1) (trans pt4_ 0 1) "" 

)

(foreach x ch_lst

(myText tstyle "mc" ptxt txtH 0 (rtos (car x) 2 0))

(setq ptxt1 (list (+(car ptxt)wt) (cadr ptxt)))

(myText tstyle "mc" ptxt1 txtH 0 (rtos (car (cadr x))2 2))

(setq ptxt2 (list (+(car ptxt1)wt) (cadr ptxt1)))

(myText tstyle "mc" ptxt2 txtH 0 (rtos (cadr (cadr x))2 2))

(setq ptxt3 (list (+(car ptxt2)wt) (cadr ptxt2)))

(myText tstyle "mc" ptxt3 txtH 0 (rtos (*(caddr x)2)2 2))

(setq ptxt (list (car ptxt) (-(cadr ptxt2)ht)))

(setq pt0_ (list (car pt0_) (-(cadr pt0_) ht))

  pt4_ (list (car pt4_) (-(cadr pt4_) ht))

)

(command "_line" (trans pt0_ 0 1) (trans pt4_ 0 1) "" )

)

(setq htab (* ht (1+(length ch_lst))))

(setq pt0_ (list (car pt)  (-(cadr pt) htab))

  pt1_ (list (car pt1) (-(cadr pt1)htab))

  pt2_ (list (car pt2) (-(cadr pt2)htab))

  pt3_ (list (car pt3) (-(cadr pt3)htab))

  pt4_ (list (car pt4) (-(cadr pt4)htab))

)

(command "_line" (trans pt 0 1) (trans pt0_ 0 1) "" 

"_line" (trans pt1 0 1) (trans pt1_ 0 1) "" 

"_line" (trans pt2 0 1) (trans pt2_ 0 1) ""

"_line" (trans pt3 0 1) (trans pt3_ 0 1) ""

"_line" (trans pt4 0 1) (trans pt4_ 0 1) ""

"_line" (trans pt0_ 0 1) (trans pt4_ 0 1) "" 

)

(setvar "clayer" old_layer)

(princ)

)


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

(defun myText (txtStyle txtJust insertPt textHeight ang txtString)

;(myText tstyle "mc" ptxt txtH ang txt)

(if (= txtJust "M")  (setq horJust 4 verJust 0));Middle

(if (= txtJust "L")  (setq horJust 0 verJust 0));Left

(if (= txtJust "C")  (setq horJust 1 verJust 0));Center

(if (= txtJust "R")  (setq horJust 2 verJust 0));Right

(if (= txtJust "bl") (setq horJust 0 verJust 1));Bottom Left

(if (= txtJust "bc") (setq horJust 1 verJust 1));Bottom Center

(if (= txtJust "br") (setq horJust 2 verJust 1));Bottom Right   

(if (= txtJust "tl") (setq horJust 0 verJust 3));Top Left

(if (= txtJust "tc") (setq horJust 1 verJust 3));Top Center

(if (= txtJust "tr") (setq horJust 2 verJust 3));Top Right

(if (= txtJust "ml") (setq horJust 0 verJust 2));Middle Left    

(if (= txtJust "mc") (setq horJust 1 verJust 2));Middle Center

(if (= txtJust "mr") (setq horJust 2 verJust 2));Middle Right

(entmake

(list

(cons 0 "TEXT")

(cons 100 "AcDbEntity")

(cons 100 "AcDbText")

(cons 7 txtStyle) ;Text style name

(cons 10 insertPt) ;First alignment point

(cons 11 insertPt) ;Second alignment point

(cons 40 textHeight);text Height

(cons 1 txtString) ;Default value (the string itself)

(cons 50 ang) ;Text rotation

(cons 71 0) ;Flags 0=Normal, 2=Backward, 4=Upside down

(cons 72 horJust) ;Horizontal text justification,0=Left,1=Center,2=Right,3=Aligin,4=Middle,5=Fit

(cons 73 verJust) ;Vertical text justification, 0=Baseline,1=Bottom,2=Middle,3=Top

)

)

)

(defun mystyle (tstyle txtH fname)

(entmake

(list

   (cons 0  "STYLE")

   (cons 100  "AcDbSymbolTableRecord")

   (cons 100  "AcDbTextStyleTableRecord")

   (cons 2  tstyle)

   (cons 70  0)

   (cons 40  txtH);<- text height not defined

   (cons 41  1.0)

   (cons 50  0.0)

   (cons 71  0)

   (cons 42  2.0)

   (cons 3  fname)

   (cons 4  "")

 )

)

)


(prompt "\nCreate by Songkhran Jongkul September 2021")

(prompt "\nContact https://www.facebook.com/groups/AutolispTH")

(prompt "\nEnter HOCH to start Hole Chart. ")

(princ)