明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 785|回复: 6

Addhatch有多个AppendInnerLoop

[复制链接]
发表于 2015-6-5 23:23:57 | 显示全部楼层 |阅读模式
Addhatch有多个AppendInnerLoop时运行出错,提示“输入无效” ,请问应如何修改?我试了把下面改成 inloop(0 to 0)只使用一个内部的inloop就可以运行,确认了图形没有错,item(1)和item(2)是在 item(0)的内部,并封闭。
Sub kk()

Dim pname As String
Dim hatchobj As AcadHatch
Dim ba As Boolean
Dim pat As Long
Dim outloop(0 To 0) As AcadEntity
Dim inloop(0 To 1) As AcadEntity
pat = 0
pname = "ANSI31"
ba = True
Set outloop(0) = ThisDrawing.ModelSpace.Item(0)
Set inloop(0) = ThisDrawing.ModelSpace.Item(1)
Set inloop(1) = ThisDrawing.ModelSpace.Item(2)
Set hatchobj = ThisDrawing.ModelSpace.AddHatch(pat, pname, ba)
hatchobj.AppendOuterLoop (outloop)
hatchobj.AppendInnerLoop (inloop)
hatchobj.Evaluate
ThisDrawing.Regen True

End Sub

 楼主| 发表于 2015-6-6 11:24:38 | 显示全部楼层
没人会吗?我就想知道,如果有两个inloop时,怎么改?
发表于 2015-6-6 15:48:47 | 显示全部楼层
inloop如果使用多于一个对象,它们的端点必须相接以形成一个环。
发表于 2015-6-6 15:50:02 | 显示全部楼层
Sub Example_AppendInnerLoop()
    ' This example creates an associative hatch in model space.
   
    Dim hatchObj As AcadHatch
    Dim patternName As String
    Dim PatternType As Long
    Dim bAssociativity As Boolean
   
    ' Define the hatch
    patternName = "Solid"
    PatternType = 0
    bAssociativity = True
   
    ' Create the associative Hatch object
    Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity)
   
    ' Create the outer loop for the hatch.
    ' An arc and a line are used to create a closed loop.
   
    Dim outerLoop(0 To 1) As AcadEntity
    Dim center(0 To 2) As Double
    Dim radius As Double
    Dim startAngle As Double
    Dim endAngle As Double
    center(0) = 5: center(1) = 3: center(2) = 0
    radius = 3
    startAngle = 0
    endAngle = 3.141592
    Set outerLoop(0) = ThisDrawing.ModelSpace.AddArc(center, radius, startAngle, endAngle)
    Set outerLoop(1) = ThisDrawing.ModelSpace.AddLine(outerLoop(0).StartPoint, outerLoop(0).EndPoint)
        
    ' Append the outer loop to the hatch object
    hatchObj.AppendOuterLoop (outerLoop)
   
    ' Append a circle as the inner loop for the hatch.
    Dim innerLoop(1) As AcadEntity
    center(0) = 5: center(1) = 4.5: center(2) = 0
    radius = 1
    Set innerLoop(0) = ThisDrawing.ModelSpace.AddArc(center, radius, startAngle, endAngle)
    Set innerLoop(1) = ThisDrawing.ModelSpace.AddLine(innerLoop(0).StartPoint, innerLoop(0).EndPoint)
    hatchObj.AppendInnerLoop (innerLoop)
   
    ' Evaluate and display the hatch
    hatchObj.Evaluate
    ThisDrawing.Regen True
   
End Sub
 楼主| 发表于 2015-6-6 15:53:28 | 显示全部楼层
zzyong00 发表于 2015-6-6 15:48
inloop如果使用多于一个对象,它们的端点必须相接以形成一个环。

如果是分开的两个独立图形怎么办?有没有其他办法?我的图形就相当于一个脸上(圆),有两眼睛(里面两个眼),还有嘴巴(三角形),鼻子(小矩形)等。
发表于 2015-6-6 16:09:53 | 显示全部楼层
baneit319 发表于 2015-6-6 15:53
如果是分开的两个独立图形怎么办?有没有其他办法?我的图形就相当于一个脸上(圆),有两眼睛(里面两个 ...

Option Explicit

Sub Example_AppendInnerLoop()
    ' This example creates an associative hatch in model space.
   
    Dim hatchObj As AcadHatch
    Dim patternName As String
    Dim PatternType As Long
    Dim bAssociativity As Boolean
   
    ' Define the hatch
    patternName = "Solid"
    PatternType = 0
    bAssociativity = True
   
    ' Create the associative Hatch object
    Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity)
   
    ' Create the outer loop for the hatch.
    ' An arc and a line are used to create a closed loop.
   
    Dim outerLoop(0 To 1) As AcadEntity
    Dim center(0 To 2) As Double
    Dim radius As Double
    Dim startAngle As Double
    Dim endAngle As Double
    center(0) = 5: center(1) = 3: center(2) = 0
    radius = 3
    startAngle = 0
    endAngle = 3.141592
    Set outerLoop(0) = ThisDrawing.ModelSpace.AddArc(center, radius, startAngle, endAngle)
    Set outerLoop(1) = ThisDrawing.ModelSpace.AddLine(outerLoop(0).StartPoint, outerLoop(0).EndPoint)
        
    ' Append the outer loop to the hatch object
    hatchObj.AppendOuterLoop (outerLoop)
   
    ' Append a circle as the inner loop for the hatch.
    Dim innerLoop(1) As AcadEntity
    center(0) = 5: center(1) = 4.5: center(2) = 0
    radius = 1
    Set innerLoop(0) = ThisDrawing.ModelSpace.AddArc(center, radius, startAngle, endAngle)
    Set innerLoop(1) = ThisDrawing.ModelSpace.AddLine(innerLoop(0).StartPoint, innerLoop(0).EndPoint)
    hatchObj.AppendInnerLoop (innerLoop)
   
    Dim innerLoop2(1) As AcadEntity
    center(0) = 3.3: center(1) = 3.3: center(2) = 0
    radius = 1
    Set innerLoop2(0) = ThisDrawing.ModelSpace.AddArc(center, radius, startAngle, endAngle)
    Set innerLoop2(1) = ThisDrawing.ModelSpace.AddLine(innerLoop2(0).StartPoint, innerLoop2(0).EndPoint)
    hatchObj.AppendInnerLoop (innerLoop2)
   
    ' Evaluate and display the hatch
    hatchObj.Evaluate
    ThisDrawing.Regen True
   
End Sub
 楼主| 发表于 2015-6-6 17:22:18 | 显示全部楼层
zzyong00 发表于 2015-6-6 16:09
Option Explicit

Sub Example_AppendInnerLoop()

明白了,感谢老大,原来一个inner要appendinnerloop一遍呀。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 12:59 , Processed in 0.144062 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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