更改线条角度
我知道这对你们来说可能很容易。但是你能帮我建立一个lisp来选择多条线并改变角度吗?if角度
如果角度>270,我们将180分为角度
这是我到目前为止得到的。。。
(defun c:anglefix ( / d e f i s spt ept)
(if (and (setq s (ssget '((0 . "LINE"))))
(repeat (setq i (sslength s))
(setq e (entget (ssname s (setq i (1- i))))
spt (cdr (assoc 10 e))
ept (cdr (assoc 11 e))
)
(princ)
我不知道如何使用阅读角度和改变它 加180度和减180度有什么区别?
他们不是一回事吗?
89 + 180 = 269
271 - 180 = 91
它与提取时的角度有关。。。
我只需要角度在90到270之间
因此
if角度
如果角度>270 i sub-180 要围绕中心旋转每条线吗?
你需要从代码中学习吗? 对是的!我真的很想学习
好的:
(defun c:anglefix ( / DTR RTD mid SS i e enx o spt ept cen ang ) ; localise the used defuns and set(ted) q(uotes)
; define some functions to help for the task:
(defun DTR (a) (* PI (/ a 180))); converts degrees to radians
(defun RTD (a) (/ (* a 180) PI)); converts radians to degrees
(defun mid (p1 p2) (mapcar (function (lambda (a b) (/ (+ a b) 2.))) p1 p2)) ; finds the midpoint between 2 points
(if (setq SS (ssget '((0 . "LINE")))) ; prompt for a SS of lines, if valid then iterate thru it
(repeat (setq i (sslength SS)) ; iterate through the selection set
(setq
e (ssname SS (setq i (1- i))) ; entity
enx (entget e) ; entity's data (elist)
o (vlax-ename->vla-object e) ; convert the entity into vla-object (for vla-Rotate)
spt (cdr (assoc 10 enx)) ; start point
ept (cdr (assoc 11 enx)) ; end point
cen (mid spt ept) ; mid point
ang (angle spt ept) ; angle of the line (in radians)
); setq
(if (not (<= 90 (RTD ang) 270)) ; if angle is not between 90 and 270 degrees
(cond ; depending on the angle perform the corresponding action, using (cond)
((< (RTD ang) 90) ; angle is below 90 deg
(setq ang (+ ang PI)) ; add 180 degrees (value in radians) - this line is redundant, unless you want do do calculations
(vla-Rotate o (vlax-3D-point cen) PI) ; rotate the line on +180 degrees, from its center
)
((> (RTD ang) 270) ; angle is above 270 deg
(setq ang (- ang PI)) ; subtract 180 degrees (value in radians) - this line is redundant, unless you want do do calculations
(vla-Rotate o (vlax-3D-point cen) (- PI)) ; rotate the line on -180 degrees, from its center
)
); cond
); if
); repeat
); if
(princ) ; exit cleanly
); defun
(vl-load-com) (princ) ; load the visual lisp extensions
为什么它旋转的直线不大于270??这与代码有关吗?
(command "aunits" 0 "" ""
"angdir" 1 "" ""
"angbase" 270 "" ""
"insunits" 6 "" "")
因为我总是把它设置为米和正北的方向
嗯,试试“angdir”0。
和“angbase”0。
顺便问一下,你是使用UCS,还是只在WCS上工作? UCS。。。
我无法更改我的angdir和angbase,因为我们所有的DWG文件都必须在该设置上。
然后试试这个:
(defun c:anglefix ( / DTR RTD mid *error* Svars SS i e enx o spt ept cen ang ) ; localise the used defuns and set(ted) q(uotes)
; define some functions to help for the task:
(defun DTR (a) (* PI (/ a 180))); converts degrees to radians
(defun RTD (a) (/ (* a 180) PI)); converts radians to degrees
(defun mid (p1 p2) (mapcar (function (lambda (a b) (/ (+ a b) 2.))) p1 p2)) ; finds the midpoint between 2 points
(defun *error* (m)
(and Svars (mapcar 'setvar (mapcar 'car Svars) (mapcar 'cdr Svars))) ; Restore the system variables
(and m (print m)) (princ)
); defun *error*
(setq Svars ; store the system variables into assoc list, where each item is (<varName> . <varVal>)
(mapcar '(lambda (x) (cons x (getvar x)))
'("AUNITS" "ANGDIR" "ANGBASE")
)
); setq Svars
(and Svars (mapcar 'setvar (mapcar 'car Svars) '(0 0 0))) ; set new values for the variables
(if (setq SS (ssget '((0 . "LINE")))) ; prompt for a SS of lines, if valid then iterate thru it
(repeat (setq i (sslength SS)) ; iterate through the selection set
(setq
e (ssname SS (setq i (1- i))) ; entity
enx (entget e) ; entity's data (elist)
o (vlax-ename->vla-object e) ; convert the entity into vla-object (for vla-Rotate)
spt (trans (cdr (assoc 10 enx)) 1 0) ; start point, coordinate translated from WCS to UCS
ept (trans (cdr (assoc 11 enx)) 1 0) ; end point, coordinate translated from WCS to UCS
cen (mid spt ept) ; mid point
ang (angle spt ept) ; angle of the line (in radians)
); setq
(if (not (<= 90 (RTD ang) 270)) ; if angle is not between 90 and 270 degrees
(cond ; depending on the angle perform the corresponding action, using (cond)
((< (RTD ang) 90) ; angle is below 90 deg
(setq ang (+ ang PI)) ; add 180 degrees (value in radians) - this line is redundant, unless you want do do calculations
(vla-Rotate o (vlax-3D-point cen) PI) ; rotate the line on +180 degrees, from its center
)
((> (RTD ang) 270) ; angle is above 270 deg
(setq ang (- ang PI)) ; subtract 180 degrees (value in radians) - this line is redundant, unless you want do do calculations
(vla-Rotate o (vlax-3D-point cen) (- PI)) ; rotate the line on -180 degrees, from its center
)
); cond
); if
); repeat
); if
(and Svars (mapcar 'setvar (mapcar 'car Svars) (mapcar 'cdr Svars))) ; Restore the system variables
(princ) ; exit cleanly
); defun
(vl-load-com) (princ) ; load the visual lisp extensions
我不经常使用trans,所以我可能会感到困惑,如果代码表现不符合预期,您可能需要切换如下值
(trans….0 1)而不是电流(trans….1 0)。
页:
[1]
2