创建闭合多段线
我试图创建一条闭合多段线,如下所示:(defun c:pol (/ pt pt2 ptlist tmp myobj a)
;;;some random stuff I probably gotta put everytime
(setq thisdrawing
(vla-get-activedocument
(vlax-get-acad-object)))
(setq mspace (vla-get-modelspace thisdrawing))
;;;select 1st point, assigned to variable pt
(setq pt (getpoint "\nSpecify start point: "))
;;;;assign the first point to a list, in this case ptlist
(setq ptlist (cons pt ptlist))
;;;select the following points, but these are cycled in variable pt2
(while (setq pt2 (getpoint "\nSpecify next point: " pt2))
(setq ptlist (cons pt2 ptlist))
)
;;;repeat initial point so that the polyline is closed
(setq ptlist (cons pt ptlist))
;; "dissolve" the points into atoms with append:
(setq ptlist (apply 'append ptlist))
(prin1 ptlist)
)
该代码最初将变量“pt”用于第一个点和后面的每个点,并工作。但是因为我想闭合它,我想把第一个点赋给一个排他变量,这样,我只需要在最后重复它,我就得到了一条闭合的多段线。现在我得到错误:错误的参数类型:点:nil 我不知道为什么第一个例子不起作用,我必须创建一个新变量I来计算while循环的数量,然后通过直接查看列表再次添加列表的最后一个元素(起点)。这样地:
(defun c:pol (/ pt pt2 ptlist tmp myobj a i)
;;;some random stuff I probably gotta put everytime
(setq thisdrawing
(vla-get-activedocument
(vlax-get-acad-object)))
(setq mspace (vla-get-modelspace thisdrawing))
;;;select 1st point, assigned to variable pt
(setq pt (getpoint "\nSpecify start point: "))
;;;;assign the first point to a list, in this case ptlist
(setq ptlist (cons pt ptlist))
(setq i 0)
;;;select the following points, this time they stay in pt2 or i will get a error
(while (setq pt (getpoint "\nSpecify next point: " pt))
(setq i (+ i 1))
(setq ptlist (cons pt ptlist))
)
;;;repeat initial point so that the polyline is closed (by going to the end of the list and adding the point again)
(setq ptlist (cons (nth i ptlist) ptlist))
;; "dissolve" the points into atoms with append:
(setq ptlist (apply 'append ptlist))
(prin1 ptlist)
(prin1 i)
(setq
tmp (vlax-make-safearray
vlax-vbDouble
(cons 0 (- (length ptlist) 1))
)
)
(vlax-safearray-fill tmp ptlist)
(setq myobj (vla-addPolyline mspace tmp))
)
下一步:对其进行图案填充 您可以在新创建的对象“myobj”上使用hatch命令(command "._hatch" "_S" myobj "" "") 这不起作用,因为他想要一个点,而折线没有被选中,但即使如此,我认为一个简单的命令是不够的,我想选择一个模式和比例以及。
我试着阅读李·麦克创作的elipse hatch,它看起来更强大、更灵活。这只是我评论他的一段代码
(vla-appendouterloop ;means it will associate the boundaries with the hatch
(setq hat ;hat is the hatch variable
(vla-addhatch ;add hatch command
(setq spc ;drawing space
(vlax-get-property (vla-get-activedocument (vlax-get-acad-object));;; stuff i'm supposed to do everytime, probably change the hatch properties below
(if (= 1 (getvar 'cvport))
'paperspace
'modelspace
)
)
)
achatchpatterntypepredefined
"SOLID"
:vlax-true
achatchobject
)
)
(vlax-make-variant ;;;draws the hatch boundaries (i'll try to replace with the polyline)
(vlax-safearray-fill (vlax-make-safearray vlax-vbobject '(0 . 0))
(list
(vla-addellipse spc
(vlax-3D-point (trans cen 1 0))
(vlax-3D-point (trans (mapcar '- maj cen) 1 0))
rat
)
)
)
)
)
(vla-evaluate hat)
您可以通过命令行版本将代码中的变量HPSCALE(用于scale)设置为您想要的,以及HPNAME(用于pattern),您只需将它们放回末尾即可。如果我没弄错的话,你是不是在画一条多段线并在其中进行图案填充,以此来实现图案填充?只是好奇,因为我会在周末研究这段代码并提供帮助。对不起,我还没有测试它,您也可以尝试使用entlast来选择最后一个对象。 我做到了!谢谢broncos15。
(vl-load-com)
(defun c:outerloop1(/ acadObj doc patternName patternType bAssociativity modelSpace hatchObj center radius startAngle endAngle arc line outerLoop pt pt2 ptlist tmp myobj a i)
;; This example creates an associative hatch in model space, and
;; then creates an outer loop for the hatch.
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
;; Define the hatch
(setq patternName "ANSI31"
patternType 0
bAssociativity :vlax-true)
;; Create the associative Hatch object
(setq modelSpace (vla-get-ModelSpace doc))
(setq hatchObj (vla-AddHatch modelSpace patternType patternName bAssociativity acHatchObject))
;;;select 1st point, assigned to variable pt
(setq pt (getpoint "\nSpecify start point: "))
;;;;assign the first point to a list, in this case ptlist
(setq ptlist (cons pt ptlist))
(setq i 0)
;;;select the following points, but these are cycled in variable pt2
(while (setq pt (getpoint "\nSpecify next point: " pt))
(setq i (+ i 1))
(setq ptlist (cons pt ptlist))
)
;;;repeat initial point so that the polyline is closed
(setq ptlist (cons (nth i ptlist) ptlist))
;; "dissolve" the points into atoms with append:
(setq ptlist (apply 'append ptlist))
(prin1 ptlist)
(prin1 i)
;; Create the outer loop for the hatch.
;; An arc and a line are used to create a closed loop.
(setq
tmp (vlax-make-safearray
vlax-vbDouble
(cons 0 (- (length ptlist) 1))
)
)
(vlax-safearray-fill tmp ptlist)
(setq poly(vla-AddPolyline modelSpace tmp))
(setq outerLoop (vlax-make-safearray vlax-vbObject '(0 . 0)))
(vlax-safearray-put-element outerLoop 0 poly)
;; Append the outer loop to the hatch object, and display the hatch
(vla-AppendOuterLoop hatchObj outerLoop)
(vla-Evaluate hatchObj)
)
顺便说一句,忽略注释,我已经对不同代码的元素进行了网格划分 别担心。我刚刚测试了你的代码,效果很好。如果我要提出一个建议,为什么不让它“直播”,这样用户就可以看到他们正在孵化什么。您可以通过在用户设置点上运行while语句来实现这一点:(while (setq ptn
(getpoint
ptn
"\nSpecify next point: "
)
)。在while语句中,绘制pline并立即对其进行图案填充。
页:
[1]