明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2121|回复: 1

如何进行块操作以及填充(带实例)

[复制链接]
发表于 2009-11-8 18:07:00 | 显示全部楼层 |阅读模式

Sub CPT()

Dim myLayer As AcadLayer

Dim myBlock As AcadBlock
Dim p0(0 To 2) As Double


Dim arc1 As AcadArc
Dim arc2 As AcadArc
Dim arc3 As AcadArc
Dim arc_p1 As Variant
Dim arc_p2 As Variant
Dim arc_p3 As Variant

Dim mySelect(0 To 7) As AcadEntity
Dim myOuterLoop(0 To 2) As AcadEntity
Dim hatchObj As AcadHatch

'设置层属性
Set myLayer = ThisDrawing.Layers.Add("000_GI_CPT")      '新增层
myLayer.Lineweight = acLnWt035      '设定层的线性
myLayer.color = 6       '设定层的颜色为粉色
ThisDrawing.ActiveLayer = myLayer       '设定该层为当前层

p0(0) = 0
p0(1) = 0
p0(2) = 0

'绘制填充边界
Set arc1 = ThisDrawing.ModelSpace.AddArc(p0, r, -pi / 2, pi / 6)
arc_p1 = arc1.StartPoint
Set arc2 = ThisDrawing.ModelSpace.AddArc(p0, r, pi / 6, 5 * pi / 6)
arc_p2 = arc2.StartPoint
Set arc3 = ThisDrawing.ModelSpace.AddArc(p0, r, 5 * pi / 6, 3 * pi / 2)
arc_p3 = arc3.StartPoint

Set myOuterLoop(0) = ThisDrawing.ModelSpace.AddLine(arc_p1, arc_p2)
Set myOuterLoop(1) = ThisDrawing.ModelSpace.AddLine(arc_p2, arc_p3)
Set myOuterLoop(2) = ThisDrawing.ModelSpace.AddLine(arc_p3, arc_p1)

'进行填充
Set hatchObj = ThisDrawing.ModelSpace.AddHatch(0, "solid", True)        '创建填充对象为实心填充
Call hatchObj.AppendOuterLoop(myOuterLoop)        '将外边界加入到其中
Call hatchObj.Evaluate      '必须先计算填充范围
Call hatchObj.Update        '填充操作应刷新

'删除选择集
Set mySelect(0) = myOuterLoop(0)
Set mySelect(1) = myOuterLoop(1)
Set mySelect(2) = myOuterLoop(2)
Set mySelect(3) = arc1
Set mySelect(4) = arc2
Set mySelect(5) = arc3
Set mySelect(6) = ThisDrawing.ModelSpace.AddCircle(p0, r)
Set mySelect(7) = hatchObj
Set myBlock = ThisDrawing.Blocks.Add(p0, "静力触探孔")
Call ThisDrawing.ModelSpace.InsertBlock(p0, "静力触探孔", 1, 1, 1, 0)
Call ThisDrawing.CopyObjects(mySelect, myBlock)

For Each element In mySelect             '删除除块以外的线
element.Delete
Next

ZoomExtents
End Sub

 

上面的代码是在图上画一个勘探孔的符号,这里已经把他做成了块,但问题是我双击块的时候发现其中线以及填充都重复画了好几次,比如其中的园画了5个,但是我代码里面只画了一次,麻烦高人给小弟指点一下

发表于 2013-3-29 10:44:14 | 显示全部楼层
是不是copyobjects的目标对象不是你的块?。如果没有指定所有者,对象将被创建到与 Objects 数组中的对象相同的所有者中。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 15:44 , Processed in 0.172908 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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