VBA 如何实现点选模式的填充呢?
本帖最后由 作者 于 2008-5-9 17:55:08 编辑 <br /><br /> <p>我们经常需要填充不同的填充图案,每次输入H命令后都要去调整填充样式,比例,角度等很麻烦,最近研究了下VBA可以自动设置需要的填充,采用不同的命令直接填充不同的填充样式,其中就遇到如何实现象H命令的点选填充那样确定填充范围。如果不行的话能否用VBA改变当前填充设置中的样式。</p><p>Sub jmg()<br/>On Error GoTo err<br/> Dim hatchObj As AcadHatch<br/> Dim patternName As String<br/> Dim PatternType As Long<br/> Dim bAssociativity As Boolean<br/> ' 定义和创建图案填充<br/> patternName = "cork"<br/> PatternType = 0<br/> bAssociativity = True<br/> Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity)<br/> hatchObj.PatternScale = 4<br/> hatchObj.PatternAngle = 0.7853981 '90度<br/> '----------------------------------------------这里代码怎么写呢?<br/> hatchObj.Evaluate<br/> ThisDrawing.Regen True<br/>err:</p><p>End Sub</p><p></p><p>这中间代码怎么写呢?</p> 本帖最后由 作者 于 2008-5-14 15:12:31 编辑 <br /><br /> <p>解决了!一起分享下!</p><p>Public Sub qt() '快速填充<br/> On Error GoTo err<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/> patternName = "ANSI31"<br/> PatternType = 0<br/> bAssociativity = True<br/> Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity) ' 当前图纸的实体数目<br/> Dim n As Long<br/> n = ThisDrawing.ModelSpace.Count ' 调用BOUNDARY命令获取某一点处的边界<br/> Dim Pt As Variant<br/> Pt = ThisDrawing.Utility.GetPoint(, "指定内部点: ")<br/> ThisDrawing.SendCommand "_-Boundary" & vbCr & Pt(0) & "," & Pt(1) & vbCr & vbCr ' 如果存在边界,则会生成新的实体<br/> If ThisDrawing.ModelSpace.Count > n Then<br/> Set outerLoop(0) = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)<br/> Else<br/> MsgBox "未发现有效的边界。"<br/> GoTo err<br/> End If<br/> hatchObj.AppendOuterLoop outerLoop ' 计算并显示图案填充<br/> hatchObj.Evaluate<br/> ThisDrawing.Regen True<br/>outerLoop(0).Delete<br/>ThisDrawing.Regen True<br/>err:<br/>End Sub</p>
页:
[1]