The Method of Drawing Symmetric Centerline in AutoCAD

The Method of Drawing Symmetric Centerline in AutoCAD

AutoCAD is currently one of the most widely used CAD systems in China. AutoCAD is powerful and a universal CAD platform, but it is very inconvenient to use it if it is not secondary developed according to the needs of this major. Drawing a symmetrical centerline is a problem often encountered in mechanical design.
I used AutoLISP to develop two programs according to national standards, which can easily solve the problem of straight line centerline.
The first procedure is applicable when two sides are continuous straight lines. The method of use is to use the LOAD command to load GLS.LSP, run C: GSL, and select the two sides respectively according to the screen prompts to automatically draw the center line.
GSL.LSP:
(defun mid (pt1 pt2) Function function to calculate the midpoint between two points
(setq pt (mapcar '+ pt1 pt2))
(setq pt (mapcar '/ pt' (2 2 2)))
)
(defun c: gsl / m cl1 cl cl2 e pt pt1 pt2 pt3 pt4 a) (SETQ M 1)
(WHILE M
(SETQ CL1 (ENTSEL "Select the first straight line"))
(cond
((not cl1) (prompt "No entity found"))
((/ = "LINE" (cdr (assoc 0 (setqe (entget (car cl1))))))
(prompt "The selected line is not a straight line")
)
(t (prompt "find the first straight line")
(setq m nil); exit the loop)
)
)
(setq cl (ssget (nth 0 (cdr cl1)))); Get the entity data of the first line
(SETQ M 1)
(WHILE M
(SETQ CL2 (ENTSEL "Select the second straight line"))
(if cl2
(if (ssmemb (car cl2) cl)
(progn
(princ "select repeat, reselect")
(setq cl2 nil)
)
)
)
(cond
((not cl2) (prompt "No entity found or duplicate"))
((/ = "LINE" (cdr (assoc 0 (setq e (entget (car cl2))))))
(prompt "The selected line is not a straight line")
)
(t (prompt "Two straight lines have been selected")
(setq m nil) ;;; Exit the loop)
)
)
;;; Get the coordinates of the points on both ends of the first straight line (setq pt1 (cdr (assoc 10 e)) pt2 (cdr (assoc 11 e)))
(setq e (entget (car cl1))) ;; Get the entity data of the second straight line ;;; Get the coordinates of the two ends of the second straight line (setq pt3 (cdr (assoc 10 e)) pt4 (cdr (assoc 11 e )))
;; adjust the endpoint (if (inters pt1 pt3 pt2 pt4 t)
(setq pt pt1
pt1 pt2
pt2 pt
)
)
;; Calculate the coordinates of the midpoints of both ends (setq pt1 (mid pt1 pt3))
(setq pt2 (mid pt2 pt4))
(setq a (angle pt1 pt2)); calculate the inclination of the center line (setq pt2 (polar pt2 a 2.5)) ;; calculate the first endpoint of the center line (setq pt1 (polar pt1 (+ pi a) 2.5))
(command "layer" "SET" 5 ""); set center line layer (command "line" pt1 pt2 ""); draw center line
)
(princ "C: GSL has loaded")
(Princ "for symmetry line")
(princ)
The second procedure is applicable to various situations such as stepped shafts and stepped holes. The method of use is to load GLS1.LSP with the LOAD command, run C: GSL1, and select the endpoints on both sides according to the screen prompts, and automatically draw the center line.
GSL1.LSP
(defun mid (pt1 pt2)
(setq pt (mapcar '+ pt1 pt2))
(setq pt (mapcar '/ pt' (2 2 2)))
)
(defun c: gsl1 (/ p1 p1 p3 p4 a)
;; Save environment variables (setq os (getvar "osmode"))
(setq cm (getvar "cmdecho"))
;; Set environment variables (setvar "osmode" 33)
(setvar "cmdecho" 0)
;; Read the end points of two straight lines in turn (initget 1)
(setq p1 (getpoint "select the first point of the first line"))
(initget 1)
(setq p2 (getpoint "select the second point of the first line"))
(initget 1)
(setq p3 (getpoint "select the first point of the second line"))
(initget 1)
(setq p4 (getpoint "select the second point of the second line"))
;;;; Restore environment variables (setvar "osmode" os)
(setq p1 (mid p1 p3))
(setq p2 (mid p2 p4))
(setq a (angle p1 p2))
(setq p2 (polar p2 a 2.5))
(setq p1 (polar p1 (+ pi a) 2.5))
(command "layer" "set" 5 "")
(command "line" p1 p2 "")
)
(princ "C: GSL1 has loaded")
(Princ "for symmetry line")
Princ

Aluminum Electrolytic Capacitors

Aluminum Electrolytic Capacitors

Large Electrolytic Capacitor,HV Electrolytic Capacitors,Aluminum Electrolytic Capacitors

YANGZHOU POSITIONING TECH CO., LTD , https://www.yzpstcc.com

Posted on