我有一个例程,旨在在 AutoCAD 中创建管道弯头,然后插入转向叶片。
我的程序工作得几乎完美,只是当我插入块时,我设置了它,以便块的比例是从点 2 到点 5 的横截面距离(这是内角和外角分别是肘部)并且插入的块严重扭曲。
我不知道是否有办法避免这种情况。
; Garrett Ford 6/23/17
; The purpose of this program is to allow the user to enter a few
; dimensions and then insert and elbow with a turning vane
(defun C:bow(/ oldsnap oldlayer oldblip flag iw fw tt rot ip ang bend p1 p2 p3 p4 p5 p6 ss)
;***********************************************************************
; Save System Variables
(setq oldsnap (getvar "osmode"))
(setq oldlayer (getvar "clayer"))
(setq oldblip (getvar "blipmode"))
;***********************************************************************
;Change Settings & User Input
(setvar "osmode" 35)
(setvar "blipmode" 0)
(setq flag (tblsearch "Layer" "LP-DUCT")) ; checks for LP-DUCT
(if flag
(setvar "clayer" "LP-DUCT") ; changes layer to LP-DUCT
(alert ("No LP-DUCT Layer!")) ; if layer doesn't exist fuction terminates
)
(setq iw (getdist "\nWhat is the Initial Width? : "))
(setq fw (getdist "\nWhat is the Final Width? : "))
(setq tt (getdist "\nWhat is the Throat Length: "))
;(setq rot (getangle "\nWhat is the Angle of Rotation? : "))
(setq ip (getpoint "\nSelect an Insertion Point: "))
(setq ang (getangle ip "\nWhat is the Initial Throat direction from the Insertion point?: "))
(initget 1 "Left Right")
(setq bend (if (= (getkword "\nBend direction [Left/Right]: ") "Right") - +))
;***********************************************************************
; Polar Calculations
(setq p1 (polar ip (bend ang (/ pi 2)) (/ iw 2)))
(setq p2 (polar p1 ang tt)) ; Inside Corner
(setq p3 (polar p2 (bend ang (/ pi 2)) tt))
(setq p4 (polar p3 ang fw))
(setq p5 (polar p4 (bend ang (- (/ pi 2))) (+ tt iw))) ; Outside Corner
(setq p6 (polar p5 (+ ang pi) (+ tt fw)))
;***********************************************************************
; Line & Insert Commands
;(setq ss (ssadd))
(setvar "osmode" 0)
(command "_.pline" ip p1 p2 p3 p4 p5 p6 "_close")
;(ssadd (entlast) ss)
(setvar "osmode" 7079)
(command "_.insert" "tvain" p2 (distance p2 p5) (+ ang (/ pi 2)))
;(ssadd (entlast) ss)
;(command "rotate" ss "rot" ip pause)
(setvar "osmode" oldsnap)
(setvar "clayer" oldlayer)
(setvar "blipmode" oldblip)
) ; End Defun
;************************************************************************
;Converts the Degrees into Radians
(defun dtr (ang) ;define degrees to radians function
(* pi (/ ang 180.0))
;divide the angle by 180 then
;multiply the result by the constant PI
) ;end of function
;************************************************************************