使用Autolisp绘制pline。
嗨,谁能帮我检查一下我的代码出了什么问题,我无法得到数字。(defun c:huatu()
(setq n (getint "Input number of points: "))
(while(> n 0)
(setq n (- n 1))
(progn
(setq p (getpoint "Input x and y: "))
(command "pline" p "")
)
)
)
我试图在AUTOCAD中绘制6点pline。谢谢 这
(defun c:test(/ n a b i l)
(if (and (setq n (getint "\nInput number of points: "))
(setq a (getpoint "\nSpecify first point: "))
(setq l (cons a l))
)
(progn
(while (and (/= n 0)
(setq b (getpoint "\nNext point: " a))
)
(setq l (cons b l)
i (car l)
n (1- n)
)
(mapcar '(lambda (p) (grdraw i p 1 7) (setq i p)) (cdr l))
(setq a b)
)
(if l (progn
(command "_.pline")
(foreach x l
(command "_non" x)
)
(command "")
(redraw)
)
)
)
)
(princ)
)
代码中“l”的初始值是多少?它用作什么?
变量“l”包含函数grdraw使用的坐标点,以在通过命令pline绘制多段线之前,在表示多段线的点之间绘制向量 下面是一个简单的示例,并附上一些注释:
(defun C:test ( / lst p1 p2 )
(setq lst (list)) ; construct a empty list to store the points
(initget (+ 1 2 4)) ; disallow in the prompt: pressing enter, zero or negative value
(setq n (getint "\nInput number of points"))
(repeat n
(setq p1 (getpoint "\nSpecify point"))
(setq lst (cons p1 lst)) ; add the point to the list
); end of repeat, all points are stored in the list
(command "_.pline"
(foreach pt lst (command "_non" pt)) ; draw each point from the list
) ; draw the polyline
(princ) ; exit silently
);defun
编辑1:这里有一点更复杂(因此例程将更加用户友好):
(defun C:test ( / lst p1 )
(setq lst (list)) ; construct a empty list to store the points
(initget (+ 1 2 4)) ; disallow in the prompt: pressing enter, zero or negative value
(setq n (getint "\nInput number of points"))
(repeat n
(if (not p1) ; check if there p1 does not exist
(setq p1 (getpoint "\nSpecify first point")) ; ask for p1 if it does not exist
(setq p1 (getpoint "\nSpecify next point" (last (reverse lst)))) ; to display the vector from previous point
)
(setq lst (cons p1 lst)) ; add the point to the list
); end of repeat, all points are stored in the list
(command "_.pline"
(foreach pt lst (command "_non" pt)) ; draw each point from the list
) ; draw the polyline
(princ) ; exit silently
);defun
编辑2:根据我从塔瓦的代码中学到的,这里甚至更复杂:
(defun C:test ( / oldcmd lst p1 p2 col )
(setq oldcmd (getvar 'cmdecho)) ; store this variable
(setq lst (list)) ; construct a empty list to store the points
(initget (+ 1 2 4)) ; disallow in the prompt: pressing enter, zero or negative value
(if
(setq n (getint "\nInput number of points: ")) ; ask for the number of points
(progn ; if we get the number of points, do all the stuff within the progn function
(setvar 'cmdecho 0) ; set this variable to 0, to avoid any useless prompts
(repeat n
(if (not p1) ; check if there p1 does not exist
(setq p1 (getpoint "\nSpecify first point")) ; ask for p1 if it does not exist
(progn
(setq p1 (getpoint "\nSpecify next point" (setq p2 (last (reverse lst))))) ; to display the vector from previous point
(grdraw p1 p2 (if (not col) (setq col 1) (setq col (+ col 1))) 0) ; visualize the segments, with some colors
)
)
(setq lst (cons p1 lst)) ; add the point to the list
); end of repeat, all points are stored in the list
(command "_.pline"
(foreach pt lst (command "_non" pt)) ; draw each point from the list
) ; draw the polyline
(redraw) ; this is used as "regen" for the grdraw function
(setvar 'cmdecho oldcmd) ; reset the variable
); end of progn
);if
(princ) ; exit silently
);defun
这是我第一次使用grdraw函数,所以我发现他的代码是一个很好的例子。
谢谢,哈哈,我想我最好从你的第一个代码中学习,在我理解了所有的东西都是这个代码之后,我会检查你的edit1和edit2。非常感谢!!
嗯,那是我的意图!
那么l的初始值是多少??
setq l (cons a l)
这里的“And”用于保证“n”、“a”和“l”是有效值?
嗨,我还有一个问题,在你的代码1和代码2中,
这里的“非”是什么意思?我知道这一步是为了画出每一个点,对吗?
引自LM网站:
从此处开始:http://lee-mac.com/scriptwriting.html
我希望他能在这里描述更多像“暂停”这样的东西。
页:
[1]
2