明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1505|回复: 0

请教关于填充的问题,总是返回“填充定义边界未闭合!”

[复制链接]
发表于 2012-5-4 15:36:01 | 显示全部楼层 |阅读模式
Public Function AddHatch(ByRef objList() As AcadEntity, ByVal patType As Integer, ByVal patName As String, _
    ByVal Associativity As Boolean) As AcadHatch
    On Error GoTo errHandle
    '定义填充对象
    Dim objHatch As AcadHatch

    Set objHatch = ThisDrawing.ModelSpace.AddHatch(patType, patName, Associativity, acHatchObject)
      objHatch.PatternScale = 10
    '添加边界
    objHatch.AppendOuterLoop (objList)
    objHatch.Evaluate
    ThisDrawing.Regen True

    Set AddHatch = objHatch
    Exit Function
errHandle:
    If Err.Number = -2145386493 Then
        MsgBox "填充定义边界未闭合!", vbCritical
    End If
    Err.Clear
End Function



Private Sub CommandButton1_Click()
UserForm2.Hide
Dim p1 As Variant
p1 = ThisDrawing.Utility.GetPoint(, "输入点:") '获取点坐标
Call AddRectangle(p1, 2)
End Sub
Public Function AddRectangle(ByVal pt1 As Variant, ByVal TH As Double) As AcadLWPolyline
    Dim ptArr(0 To 14) As Double
    Dim objList(0) As AcadEntity

    Dim objPline1 As AcadPolyline

    ptArr(0) = pt1(0): ptArr(1) = pt1(1): ptArr(2) = pt1(2)
    ptArr(3) = ptArr(0) + 1500: ptArr(4) = ptArr(1): ptArr(5) = ptArr(2)
    ptArr(6) = ptArr(3): ptArr(7) = ptArr(4) - 1000 * TH: ptArr(8) = ptArr(2)
    ptArr(9) = ptArr(0): ptArr(10) = ptArr(1) - 1000 * TH: ptArr(11) = ptArr(2)
    ptArr(12) = pt1(0): ptArr(13) = pt1(1): ptArr(14) = pt1(2)

     Set objPline1 = AddPline(ptArr(), 0.01)

    Set objList(0) = objPline1
AddHatch objList, 0, "LINEAR", True

End Function


Public Function AddPline(ByRef ptArr() As Double, ByVal width As Double) As AcadPolyline
    Dim objPline As AcadPolyline

    '错误处理
    If (UBound(ptArr) + 1) Mod 3 <> 0 Then
        MsgBox "数组元素个数必须为3的倍数!"
        Exit Function
    End If

    Set objPline = ThisDrawing.ModelSpace.AddPolyline(ptArr)
    objPline.ConstantWidth = width
    objPline.Update

    Set AddPline = objPline
End Function

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 16:26 , Processed in 0.159898 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表