求救lisp高手,我按书的例子写了下面这个程序,为什么在cad上实施的时候,有时候第二个圆没有被剪切到
刚开始画几个都可以剪切到校园,后来画就不可以了,不知道是什么原因。情况如图所示:代码如下:(defunc:T14()(setqen1(car(entsel"\n选取圆1:...
刚开始画几个都可以剪切到校园,后来画就不可以了,不知道是什么原因。情况如图所示:代码如下:
(defun c:T14()
(setq en1 (car(entsel"\n选取圆1:")))
(setq en2 (car(entsel"\n选取圆2:")))
(setq en1data(entget en1))
(setq en2data(entget en2))
(setq cen1 (cdr(assoc 10 en1data))) ;取得第一个圆的圆心
(setq cen2 (cdr(assoc 10 en2data))) ;取得第二个圆的圆心
(setq r1(cdr(assoc 40 en1data))) ;取得第一个圆的半径
(setq r2(cdr(assoc 40 en2data))) ;取得第二个圆的半径
(setq ang (angle cen1 cen2)) ;计算en1至en2中心点的角度
(setq p1(polar cen1 (+ ang (/ pi 2))r1))
(setq p2(polar cen1 (- ang (/ pi 2))r1))
(setq p3(polar cen2 (+ ang (/ pi 2))r2))
(setq p4(polar cen2 (- ang (/ pi 2))r2))
;绘制切线
(command "line" "tan" p1 "tan" p4 "")
(setq en3 (entlast))
(command "line" "tan" p2 "tan" p3 "")
(setq en4 (entlast))
(setq nn (getint "\n重复次数<8>:"))
(if (null nn)(setq nn 8))
(command "trim" en3 en4 "" (list en2 (polar cen2 ang (* -1 r2))) "") ;修剪第二个圆
(command "array" en3 en4 (polar cen2 ang r2) "" "p" cen1 nn "" "")
(prin1)
)
还有对这个语句有点疑问:: (command "trim" en3 en4 "" (list en2 (polar cen2 ang (* -1 r2))) "")
为什么en2不是校园的名字吗,为什么和一个点组成一个list之后做剪切。这个语句是怎么搞的。 展开
(defun c:T14()
(setq en1 (car(entsel"\n选取圆1:")))
(setq en2 (car(entsel"\n选取圆2:")))
(setq en1data(entget en1))
(setq en2data(entget en2))
(setq cen1 (cdr(assoc 10 en1data))) ;取得第一个圆的圆心
(setq cen2 (cdr(assoc 10 en2data))) ;取得第二个圆的圆心
(setq r1(cdr(assoc 40 en1data))) ;取得第一个圆的半径
(setq r2(cdr(assoc 40 en2data))) ;取得第二个圆的半径
(setq ang (angle cen1 cen2)) ;计算en1至en2中心点的角度
(setq p1(polar cen1 (+ ang (/ pi 2))r1))
(setq p2(polar cen1 (- ang (/ pi 2))r1))
(setq p3(polar cen2 (+ ang (/ pi 2))r2))
(setq p4(polar cen2 (- ang (/ pi 2))r2))
;绘制切线
(command "line" "tan" p1 "tan" p4 "")
(setq en3 (entlast))
(command "line" "tan" p2 "tan" p3 "")
(setq en4 (entlast))
(setq nn (getint "\n重复次数<8>:"))
(if (null nn)(setq nn 8))
(command "trim" en3 en4 "" (list en2 (polar cen2 ang (* -1 r2))) "") ;修剪第二个圆
(command "array" en3 en4 (polar cen2 ang r2) "" "p" cen1 nn "" "")
(prin1)
)
还有对这个语句有点疑问:: (command "trim" en3 en4 "" (list en2 (polar cen2 ang (* -1 r2))) "")
为什么en2不是校园的名字吗,为什么和一个点组成一个list之后做剪切。这个语句是怎么搞的。 展开
1个回答
展开全部
trim命令需要的是图元名+点坐标,称作双元表。
有时不能剪切可能是自动捕捉在作怪。
有时不能剪切可能是自动捕捉在作怪。
追问
请问在那里可以查看这些命令,如trim在lisp里面的详细操作过程吗。难道要再cad里面试验吗,然后得出操作步骤再做吗?
有没有就是想这些命令的 函数原型这样子,在哪里可以查到呢???
追答
一般的lisp教材上都有的
还有帮助里也有,如下
For AutoCAD commands that require the selection of an object (like the BREAK and TRIM commands in the Command Reference), you can supply a list obtained with entsel instead of a point to select the object.
Some AutoCAD commands (such as TRIM, EXTEND, and FILLET) require the user to specify a pick point as well as the object itself. To pass such pairs of object and point data by means of the command function without the use of a PAUSE, you must first store them as variables. Points can be passed as strings within the command function or can be defined outside the function and passed as variables, as shown in the following example. This code fragment shows one method of passing an entity name and a pick point to the command function.
(command "circle" "5,5" "2") Draws circle
(command "line" "3,5" "7,5" "") Draws line
(setq el (entlast)) Gets last entity name
(setq pt '(5 7)) Sets point pt
(command "trim" el "" pt "") Performs trim
If AutoCAD is at the Command prompt when these functions are called, AutoCAD performs the following actions:
Draws a circle centered at (5,5) with a radius of 2.
Draws a line from (3,5) to (7,5).
Creates a variable el that is the name of the last object added to the database. (See Using AutoLISP to Manipulate AutoCAD Objects for more discussion of objects and object-handling functions.)
Creates a pt variable that is a point on the circle. (This point selects the portion of the circle to be trimmed.)
Performs the TRIM command by selecting the el object and by selecting the point specified by pt.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询