我做到了!谢谢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)
- )
顺便说一句,忽略注释,我已经对不同代码的元素进行了网格划分 |