nhy12345678 发表于 2008-5-15 10:43:00

帮忙看下代码从VBA编辑器运行正常,从命令行启动他就显示找不到边界!!

<p>帮忙看下代码从VBA编辑器运行正常,从命令行启动他就显示找不到边界!!(使用的是先选择后执行透明命令方式)</p><p>Public Sub qt() '快速填充<br/>&nbsp;&nbsp;&nbsp; On Error GoTo err<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&nbsp;&nbsp;&nbsp; ' 定义图案填充<br/>&nbsp;&nbsp;&nbsp; patternName = "ANSI31"<br/>&nbsp;&nbsp;&nbsp; PatternType = 0<br/>&nbsp;&nbsp;&nbsp; bAssociativity = True<br/>&nbsp;&nbsp;&nbsp; Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity)&nbsp;&nbsp; ' 当前图纸的实体数目<br/>&nbsp;&nbsp;&nbsp; Dim n As Long<br/>&nbsp;&nbsp;&nbsp; n = ThisDrawing.ModelSpace.Count&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; "a" &amp; vbCr &amp; "b" &amp; vbCr &amp; "e" &amp; vbCr &amp; vbCr &amp; Pt(0) &amp; "," &amp; Pt(1) &amp; vbCr &amp; vbCr&nbsp;&nbsp;&nbsp; ' 如果存在边界,则会生成新的实体<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Regen True<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; GoTo err<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; hatchObj.AppendOuterLoop outerLoop&nbsp;&nbsp;&nbsp; ' 计算并显示图案填充<br/>&nbsp;&nbsp;&nbsp; hatchObj.Evaluate<br/>&nbsp;&nbsp;&nbsp; outerLoop(0).Delete<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Regen True<br/>err:<br/>End Sub<br/></p>

nhy12345678 发表于 2008-5-15 10:50:00

补充说明:在命令行执行中其实通过《ThisDrawing.SendCommand "-boundary" &amp; vbCr &amp; "a" &amp; vbCr &amp; "b" &amp; vbCr &amp; "e" &amp; vbCr &amp; vbCr &amp; Pt(0) &amp; "," &amp; Pt(1) &amp; vbCr &amp; vbCr    ' 如果存在边界,则会生成新的实体》后模型空间中已经创建了封闭对象的,但是下一句ThisDrawing.ModelSpace.Count 就统计不到刚才生成的这个对象数量。请问是不是要在执行生成封闭对象后要更新或延时下呢?如何操作。

nhy12345678 发表于 2008-5-15 11:51:00

本帖最后由 作者 于 2008-5-15 14:23:16 编辑 <br /><br /> <p>我没有办法了!只有采用一个很笨的办法,先用一个命令生成边界后再在命令行调用另外一个命令生成填充</p><p>Public Sub qt() '快速填充<br/>&nbsp;&nbsp;&nbsp; On Error GoTo err<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&nbsp;&nbsp;&nbsp; ' 定义图案填充<br/>&nbsp;&nbsp;&nbsp; Dim eNt As AcadEntity<br/>&nbsp;&nbsp;&nbsp; patternName = "ANSI31"<br/>&nbsp;&nbsp;&nbsp; PatternType = 0<br/>&nbsp;&nbsp;&nbsp; bAssociativity = True<br/>&nbsp;&nbsp;&nbsp; Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity) </p><p>&nbsp; ' 当前图纸的实体数目<br/>&nbsp;&nbsp;&nbsp; Dim sset As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; Set sset = ThisDrawing.SelectionSets.Add("ss")<br/>&nbsp;&nbsp;&nbsp; sset.Select acSelectionSetLast'得到最近一次创建的图元<br/>&nbsp;&nbsp;&nbsp; For Each eNt In sset<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set outerLoop(0) = eNt<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; hatchObj.AppendOuterLoop outerLoop&nbsp;&nbsp;&nbsp; ' 计算并显示图案填充<br/>&nbsp;&nbsp;&nbsp; hatchObj.Evaluate<br/>&nbsp;&nbsp;&nbsp; outerLoop(0).Delete<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Regen True<br/>err:<br/>sset.Delete<br/>End Sub<br/>Public Sub bb() '快速填充前先画出边界准备<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; "a" &amp; vbCr &amp; "b" &amp; vbCr &amp; "e" &amp; vbCr &amp; vbCr </p><p>ThisDrawing.SendCommand "qt" &amp; vbCr </p><p>&amp; Pt(0) &amp; "," &amp; Pt(1) &amp; vbCr &amp; vbCr&nbsp;&nbsp;&nbsp; ' 如果存在边界,则会生成新的实体<br/>End Sub</p>
页: [1]
查看完整版本: 帮忙看下代码从VBA编辑器运行正常,从命令行启动他就显示找不到边界!!