;This lisp is developed as part of Survey Drawing project, which aims to help people prepare survey drawings easily. ;You may find more such lisps at www.surveydrawing.net and www.esurveying.net (defun c:celn() (cre_lay "Cen_Line" 2) (setq selDetails(nentsel "\nSelect First Polyline:")) (setq plen(car selDetails)) (setq plpt(cadr selDetails)) (setq ptList1(FindNEntPList plen plpt)) (setq selDetails(nentsel "\nSelect Second Polyline:")) (setq plen(car selDetails)) (setq plpt(cadr selDetails)) (setq ptList2(FindNEntPList plen plpt)) (if (> (distance (nth 0 ptList1) (nth 0 ptList2)) (distance (nth 0 ptList1) (nth 1 ptList2))) (command "Line" (midp (nth 0 ptList1) (nth 1 ptList2)) (midp (nth 1 ptList1) (nth 0 ptList2)) "") (command "Line" (midp (nth 0 ptList1) (nth 0 ptList2)) (midp (nth 1 ptList1) (nth 1 ptList2)) "") ) (cpl (entlast) "Cen_Line") (princ) ) (defun c:altc() (command "erase" (entlast) "") (if (> (distance (nth 0 ptList1) (nth 0 ptList2)) (distance (nth 0 ptList1) (nth 1 ptList2))) (command "Line" (midp (nth 0 ptList1) (nth 0 ptList2)) (midp (nth 1 ptList1) (nth 1 ptList2)) "") (command "Line" (midp (nth 0 ptList1) (nth 1 ptList2)) (midp (nth 1 ptList1) (nth 0 ptList2)) "") ) (cpl (entlast) "Cen_Line") ) (defun FindNEntPList(ent1 pntDetails) (setq entl1(Entget ent1)) (setq entty1(Cdr (Assoc 0 entl1))) (If (= entty1 "VERTEX") (progn (setq fp(Cdr (Assoc 10 entl1))) (setq sp(Cdr (Assoc 10 (Entget (Entnext ent1))))) ) ) (If (= entty1 "LINE") (progn (setq fp(Cdr (Assoc 10 entl1))) (setq sp(Cdr (Assoc 11 entl1))) ) ) (If (= entty1 "LWPOLYLINE") (progn (setq obj(vlax-ename->vla-object ent1)) (setq ptOnLine(vlax-curve-getClosestPointTo obj pntDetails)) (setq ptPara(vlax-curve-getParamAtPoint obj ptOnLine)) (setq ptFirst(fix ptpara)) (setq ptnext(1+ ptFirst)) (setq fp(vlax-curve-getPointAtParam obj ptFirst)) (setq sp(vlax-curve-getPointAtParam obj ptnext)) ) ) (setq return(List fp sp)) ) ;Function to Change the Layer of Specified Entity to Specified Layer (defun CPL(ent entlay) (command "._change" ent "" "p" "layer" entlay "") ) ;Function to Create a Layer with given color (defun Cre_Lay(lay_layn lay_laycol) (if (= (tblsearch "Layer" lay_layn) nil) (command "._Layer" "n" lay_layn "c" lay_laycol lay_layn "") (command "._Layer" "t" lay_layn "on" lay_layn "c" lay_laycol lay_layn "") ) (princ) ) ;Function to find the midpoint of two points. (Defun MidP(midp_fpo midp_spo) (setq midp_mpo(list (/ (+ (car midp_fpo) (car midp_spo)) 2) (/ (+ (cadr midp_fpo) (cadr midp_spo)) 2))) ) (princ "\n1. \"CeLn\" to Create Centre Line\n2. AltC: Find Alternate") (princ)