Tuesday, August 5, 2025

FREELISP : Write, List, Export selected Coordinates

         If user have many points in drawing and want to

  •  Write Coordinate text at point
  • Sort all selected points in 4 direction : Left to Right , Right to Left, Upwards, Downwards
  • Export sorted list to text file in format x,y,z
        User can use this code below :

(defun insert-by-direction (pt lst dir)
  (cond
    ((null lst) (list pt))
    ((or
       (and (= dir "L") (< (car pt) (car (car lst))))
       (and (= dir "R") (> (car pt) (car (car lst))))
       (and (= dir "U") (< (cadr pt) (cadr (car lst))))
       (and (= dir "D") (> (cadr pt) (cadr (car lst))))
     )
     (cons pt lst)
    )
    (T (cons (car lst) (insert-by-direction pt (cdr lst) dir)))
  )
)
(defun insertion-sort-dir (pt-list dir)
  (if (null pt-list)
      nil
      (insert-by-direction (car pt-list) (insertion-sort-dir (cdr pt-list) dir) dir)
  )
)
(defun c:COMPAREPTSXY ( / ss i ent ed pt pt-list sorted idx dir x y txtpt txtfile)
  (prompt "\n Sort Direction:")
  (prompt "\n  L = Left → Right, R = Right → Left, U = Down → Up, D = Up → Down")
  (initget "L R U D")
  (setq dir (getkword "\nPls specify direction [L/R/U/D] <L>: "))
  (if (not dir) (setq dir "L"))
  ;; เลือก POINT
  (prompt "\nSelect points: ")
  (setq ss (ssget '((0 . "POINT"))))
  (if ss
    (progn
      (setq pt-list '()
            i 0)
      ;; Read objects
      (while (< i (sslength ss))
        (setq ent (ssname ss i)
              ed  (entget ent)
              pt  (cdr (assoc 10 ed)))
        (if pt
          (setq pt-list (cons pt pt-list))
        )
        (setq i (1+ i))
      )
      ;; Sort by direction
      (setq sorted (insertion-sort-dir pt-list dir))
      (setq txtfile (open "d://pointexport.TXT" "w"))   ;;=======
      ;; display 30 degree TEXT Coord at point 
      (prompt (strcat "\n--- List by wanted direction " dir " ---"))
      (setq idx 1)
      (foreach p sorted
        (setq x (rtos (car p) 2 2))
        (setq y (rtos (cadr p) 2 2))
        ;; print in Command Line
        (prompt (strcat "\n" (itoa idx)
                        ". X: " x ", Y: " y
                        ", Z: " (rtos (if (caddr p) (caddr p) 0.0) 2 2)))
        ;; place TEXT on coord
      (command "TEXT" p 0.8 30 (strcat x "," y))  

        ;; write coord to file
        (write-line (strcat  x ","y",0.0") txtfile)
        (setq idx (1+ idx))
      )
      (close txtfile)
      (prompt "\n✅ Coordinate written to file 'pointexport.TXT'")
      (prompt "\n-------------------------------------------")
    )
    (prompt "\n No POINT selection.")
  )
  (princ)
)

;;code ended

noted: 
user must create text file named >>> pointexport.TXT
user can change text file location at this line ;;=======

Friday, July 25, 2025

FREELISP : Find, mark and count line intersections

     If you want to find, mark and count line intersections, you can let ChatGPT help you code LISP program and run as VDO.


@ptcaduser

PTCAD-Intersect mark #ptcad #lisp #intersection #cad

♬ original sound - ptcaduser


Command : Intcnt

Source code

(defun intersect-line-line (a1 a2 b1 b2 / x1 y1 x2 y2 x3 y3 x4 y4 denom ua ub)
  (setq x1 (car a1) y1 (cadr a1)
        x2 (car a2) y2 (cadr a2)
        x3 (car b1) y3 (cadr b1)
        x4 (car b2) y4 (cadr b2))
  (setq denom (- (* (- x1 x2) (- y3 y4)) (* (- y1 y2) (- x3 x4))))
  (if (not (equal denom 0.0 1e-8))
    (progn
      (setq ua (/ (- (* (- x1 x3) (- y3 y4)) (* (- y1 y3) (- x3 x4))) denom))
      (setq ub (/ (- (* (- x1 x3) (- y1 y2)) (* (- y1 y3) (- x1 x2))) denom))
      (if (and (>= ua 0.0) (<= ua 1.0) (>= ub 0.0) (<= ub 1.0))
        (list (+ x1 (* ua (- x2 x1)))
              (+ y1 (* ua (- y2 y1)))
              0.0)
      )
    )
  )
)
(defun draw-colored-circle (pt rad color)
  (entmakex (list
              (cons 0 "CIRCLE")
              (cons 10 pt)
              (cons 40 rad)
              (cons 62 color))) ; 1 = red
)
(defun c:intcnt ( / ss i j e1 e2 ent1 ent2 ptA1 ptA2 ptB1 ptB2 ip radius count)
  (prompt "\nSelect LINE objects to check intersections: ")
  (setq ss (ssget '((0 . "LINE")))) ; Support LINEs only for now
  (if ss
    (progn
      (initget 7)
      (setq radius (getreal "\nEnter radius for intersection marks: "))
      (setq count 0)
      (setq i 0)
      (while (< i (sslength ss))
        (setq e1 (ssname ss i)
              ent1 (entget e1)
              ptA1 (cdr (assoc 10 ent1))
              ptA2 (cdr (assoc 11 ent1)))
        (setq j (1+ i))
        (while (< j (sslength ss))
          (setq e2 (ssname ss j)
                ent2 (entget e2)
                ptB1 (cdr (assoc 10 ent2))
                ptB2 (cdr (assoc 11 ent2)))
          (setq ip (intersect-line-line ptA1 ptA2 ptB1 ptB2))
          (if ip
            (progn
              (draw-colored-circle ip radius 4) ; cyan
              (setq count (1+ count))
            )
          )
          (setq j (1+ j))
        )
        (setq i (1+ i))
      )
      (prompt (strcat "\nNo. of Intersections: " (itoa count)))
    )
    (prompt "\nNo valid LINE objects selected.")
  )
  (princ)
)


Wednesday, June 11, 2025

Draw mechanical details with PTCAD Plus - MEC

    Draw mechanical details with PTCAD Plus - MEC


            PTCAD Plus edition contains many plug-ins  AECplus, MEC, Assetlink which can help user draw detail drawing faster normal commands

            MEC is plug-ins to help user draw detail of mechanical drawing including standard symbols  of mechanical part such as 

Angle, Bearing, Bushing, Caster,
Coupling, Hinge, Key, Lever,
Nut, Pulley, Screw & Bolt, Spring,
 Steel Shapes, Channel, Equal Angle, H-Section, Washer


                User can call mechanical functions by type  MECHLIB  command   program will show dialog to show symbols library as image


        There are three functions in dialog
  1. Library
    user can choose wanted symbol by clicking at symbol then press middle button to insert symbol into drawing   then do left click to place symbol at wanted location.

  2. Part Generator
    User can choose wanted part symbols as Gear , Belt ,Bolt       by clicking at symbol then press middle button to put value of symbols then follow enter value steps  before insert symbol into drawing   




  3. BOM or Bill Of Materials
    After use insert many mechanical symbols, program will count all symbols into BOM which can copy and paste into MSEXCEL sheet.


            Mechanical module in PTCAD Plus provide standard symbols in one stop command. This help user draw mechanical drawing complete faster. 


Monday, June 9, 2025

How to set alias command to work faster

 How to set alias command to work faster 


         To set up alias command, there is way to do


        Use command  ALIASEDIT 


  1. Type ALIASEDIT in the command line

    Program will display dialog as this
            If user want to create new alias command   
  1. Click at New button
  2. Enter wanted alias command (PN in this sample)
  3. In Available command , scroll  to wanted command to match with alias command, click at that command.
  4. Click Assign button   to  match  alias command and full command
  5. Click    Close button to end command
  6. Try using  alias command (PN in this sample) 

            User can import or export  alias command files  .ica  or .pgp (from AutoCAD) when migrate from other CAD to use PTCAD.

            Alias command is just basic step to type short command to run the command but entering parameters or options in command , user must do by yourself.   If user want simplify steps of command usage, user can develop your own command by cerating LISP command.





FREELISP : Write, List, Export selected Coordinates

         If user have many points in drawing and want to   Write Coordinate text at point Sort all selected points in 4 direction : Left to ...