这段填充图案的代码错在那里了?
<p>Sub test()<br/> Dim hatchObj As AcadHatch<br/> Dim patternName As String<br/> Dim PatternType As Long<br/> Dim bAssociativity As Boolean<br/> Dim outerLoop(0 To 0) As AcadEntity<br/> ' 定义图案填充<br/> patternName = "ANSI31"<br/> PatternType = 0<br/> bAssociativity = True</p><p> ' 当前图纸的实体数目<br/> Dim n As Long<br/> n = ThisDrawing.ModelSpace.Count<br/> <br/> ' 调用BOUNDARY命令获取某一点处的边界<br/> Dim Pt As Variant<br/> Pt = ThisDrawing.Utility.GetPoint(, "指定内部点: ")<br/> ThisDrawing.SendCommand "_-Boundary" & vbCr & Pt(0) & "," & Pt(1) & vbCr & vbCr<br/> <br/> ' 如果存在边界,则会生成新的实体<br/> If ThisDrawing.ModelSpace.Count > n Then<br/> Set outerLoop(0) = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)<br/> Else<br/> MsgBox "未发现有效的边界。"<br/> <br/> End If<br/>hatchObj.AppendOuterLoop (outerLoop)<font color="#f70909">'这里 运行时错误‘91’ 对象变量或with块变量未设置</font><br/> ' 计算并显示图案填充<br/> hatchObj.Evaluate<br/> ThisDrawing.Regen True<br/>End Sub</p> <p>Sub test()<br/> Dim hatchObj As AcadHatch<br/> Dim patternName As String<br/> Dim PatternType As Long<br/> Dim bAssociativity As Boolean<br/> Dim outerLoop(0) As AcadEntity<br/> ' 定义图案填充<br/> patternName = "ANSI31"<br/> PatternType = 0<br/> bAssociativity = True<br/>Set hatchObj = ThisDrawing.ModelSpace. _<br/> AddHatch(PatternType, patternName, bAssociativity)</p><p> ' 当前图纸的实体数目<br/> Dim n As Long<br/> n = ThisDrawing.ModelSpace.count<br/> <br/> ' 调用BOUNDARY命令获取某一点处的边界<br/> Dim Pt As Variant<br/> Pt = ThisDrawing.Utility.GetPoint(, "指定内部点: ")<br/> ThisDrawing.SendCommand "_-Boundary" & vbCr & Pt(0) & "," & Pt(1) & vbCr & vbCr<br/> <br/> ' 如果存在边界,则会生成新的实体<br/> If ThisDrawing.ModelSpace.count > n Then<br/> Set outerLoop(0) = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.count - 1)<br/> Else<br/> MsgBox "未发现有效的边界。"<br/> <br/> End If<br/>hatchObj.AppendOuterLoop outerLoop '这里 运行时错误‘91’ 对象变量或with块变量未设置<br/> ' 计算并显示图案填充<br/> hatchObj.Evaluate<br/> ThisDrawing.Regen True<br/>End Sub<br/></p><p>改了几处,程序运行正常。</p> 非常感谢<strong><font face="Verdana" color="#61b713">chtd<font color="#000000">!我QQ:22742129交个朋友吧!</font></font></strong>
页:
[1]