nhy12345678 发表于 2008-5-9 18:38:00

这段填充图案的代码错在那里了?

<p>Sub test()<br/>&nbsp;&nbsp;&nbsp; Dim hatchObj As AcadHatch<br/>&nbsp;&nbsp;&nbsp; Dim patternName As String<br/>&nbsp;&nbsp;&nbsp; Dim PatternType As Long<br/>&nbsp;&nbsp;&nbsp; Dim bAssociativity As Boolean<br/>&nbsp;&nbsp;&nbsp; Dim outerLoop(0 To 0) As AcadEntity<br/>&nbsp;&nbsp;&nbsp; ' 定义图案填充<br/>&nbsp;&nbsp;&nbsp; patternName = "ANSI31"<br/>&nbsp;&nbsp;&nbsp; PatternType = 0<br/>&nbsp;&nbsp;&nbsp; bAssociativity = True</p><p>&nbsp;&nbsp;&nbsp; ' 当前图纸的实体数目<br/>&nbsp;&nbsp;&nbsp; Dim n As Long<br/>&nbsp;&nbsp;&nbsp; n = ThisDrawing.ModelSpace.Count<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 调用BOUNDARY命令获取某一点处的边界<br/>&nbsp;&nbsp;&nbsp; Dim Pt As Variant<br/>&nbsp;&nbsp;&nbsp; Pt = ThisDrawing.Utility.GetPoint(, "指定内部点: ")<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.SendCommand "_-Boundary" &amp; vbCr &amp; Pt(0) &amp; "," &amp; Pt(1) &amp; vbCr &amp; vbCr<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 如果存在边界,则会生成新的实体<br/>&nbsp;&nbsp;&nbsp; If ThisDrawing.ModelSpace.Count &gt; n Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set outerLoop(0) = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)<br/>&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "未发现有效的边界。"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; End If<br/>hatchObj.AppendOuterLoop (outerLoop)<font color="#f70909">'这里 &nbsp;运行时错误‘91’ 对象变量或with块变量未设置</font><br/>&nbsp;&nbsp;&nbsp; ' 计算并显示图案填充<br/>&nbsp;&nbsp;&nbsp; hatchObj.Evaluate<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Regen True<br/>End Sub</p>

chtd 发表于 2008-5-11 19:54:00

<p>Sub test()<br/>&nbsp;&nbsp;&nbsp; Dim hatchObj As AcadHatch<br/>&nbsp;&nbsp;&nbsp; Dim patternName As String<br/>&nbsp;&nbsp;&nbsp; Dim PatternType As Long<br/>&nbsp;&nbsp;&nbsp; Dim bAssociativity As Boolean<br/>&nbsp;&nbsp;&nbsp; Dim outerLoop(0) As AcadEntity<br/>&nbsp;&nbsp;&nbsp; ' 定义图案填充<br/>&nbsp;&nbsp;&nbsp; patternName = "ANSI31"<br/>&nbsp;&nbsp;&nbsp; PatternType = 0<br/>&nbsp;&nbsp;&nbsp; bAssociativity = True<br/>Set hatchObj = ThisDrawing.ModelSpace. _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddHatch(PatternType, patternName, bAssociativity)</p><p>&nbsp;&nbsp;&nbsp; ' 当前图纸的实体数目<br/>&nbsp;&nbsp;&nbsp; Dim n As Long<br/>&nbsp;&nbsp;&nbsp; n = ThisDrawing.ModelSpace.count<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 调用BOUNDARY命令获取某一点处的边界<br/>&nbsp;&nbsp;&nbsp; Dim Pt As Variant<br/>&nbsp;&nbsp;&nbsp; Pt = ThisDrawing.Utility.GetPoint(, "指定内部点: ")<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.SendCommand "_-Boundary" &amp; vbCr &amp; Pt(0) &amp; "," &amp; Pt(1) &amp; vbCr &amp; vbCr<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 如果存在边界,则会生成新的实体<br/>&nbsp;&nbsp;&nbsp; If ThisDrawing.ModelSpace.count &gt; n Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set outerLoop(0) = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.count - 1)<br/>&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "未发现有效的边界。"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; End If<br/>hatchObj.AppendOuterLoop outerLoop '这里&nbsp; 运行时错误‘91’ 对象变量或with块变量未设置<br/>&nbsp;&nbsp;&nbsp; ' 计算并显示图案填充<br/>&nbsp;&nbsp;&nbsp; hatchObj.Evaluate<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Regen True<br/>End Sub<br/></p><p>改了几处,程序运行正常。</p>

nhy12345678 发表于 2008-5-14 15:05:00

非常感谢<strong><font face="Verdana" color="#61b713">chtd<font color="#000000">!我QQ:22742129交个朋友吧!</font></font></strong>
页: [1]
查看完整版本: 这段填充图案的代码错在那里了?