明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1625|回复: 4

[求助]VBA这样的选择集怎样写

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

直线的起点坐标为10,25,终点的坐标为100,129,图层名为LINE1,画图之前现要判断这条线是否存在,如果存在且图层相同,则不画这条线,如果不存在或存在但图层不是LINE1就画这条线,在直线的两端分别插入两个名称为2的块,图层名为BLOCK1,再在直线两端分别插入两个单行文字“起点”“终点”,画图之前现要判断他们是否存在,块和文字同样要做与直线相同的判断。有那位大哥知道改怎么写吗?

发表于 2009-8-10 00:46:00 | 显示全部楼层

过滤器:pnt1,pnt2先赋值

0,"line",

10,pnt1,

10,pnt2,

8,"line1"

 楼主| 发表于 2009-8-10 03:27:00 | 显示全部楼层

我这样写怎么不行,而且直线都画不出来,问题出在哪里?

Sub lline()


Dim linex As AcadLine
Dim pnt1(2) As Double, pnt2(2) As Double
pnt1(0) = 10:  pnt1(1) = 25:  pnt1(2) = 0
pnt2(0) = 100: pnt2(1) = 129: pnt2(2) = 0

Dim sset As AcadSelectionSet
Set sset = ThisDrawing.SelectionSets.Add("temline")

Dim FilterType As Variant, FilterData As Variant
Dim gpCode(3) As Integer, dataValue(3) As Variant


gpCode(0) = 0
dataValue(0) = "LINE"


gpCode(1) = 8
dataValue(1) = "LINE1"


gpCode(2) = 10
dataValue(2) = pnt1


gpCode(3) = 10
dataValue(3) = pnt2


FilterType = gpCode
FilterData = dataValue


sset.Select acSelectionSetAll, FlterType, FilterData

If sset.Count = 0 Then
        Set linex = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
    Else
        MsgBox "该线段已存在"
    End If

End Sub

发表于 2009-8-10 08:34:00 | 显示全部楼层

搞错:),终点DXF码是11

Sub test()
On Error Resume Next
    Dim sset As AcadSelectionSet
    ThisDrawing.SelectionSets("temline").Delete
    Set sset = ThisDrawing.SelectionSets.Add("temline")
   
    Dim pnt1(2) As Double, pnt2(2) As Double
    pnt1(0) = 10:  pnt1(1) = 25:  pnt1(2) = 0
    pnt2(0) = 100: pnt2(1) = 129: pnt2(2) = 0
   
    Dim ft(3) As Integer, fd(3) As Variant
    ft(0) = 0: fd(0) = "LINE"
    ft(1) = 8: fd(1) = "LINE1"
    ft(2) = 10: fd(2) = pnt1
    ft(3) = 11: fd(3) = pnt2
   
    sset.Select acSelectionSetAll, , , ft, fd
   
    Dim linex As AcadLine
    If sset.Count = 0 Then
        Set linex = ThisDrawing.ModelSpace.AddLine(pnt1, pnt2)
        linex.Layer = "LINE1"
    Else
        MsgBox "该线段已存在"
    End If
End Sub

 楼主| 发表于 2009-8-10 22:19:00 | 显示全部楼层
原来是这样,谢谢指点!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-26 02:45 , Processed in 0.144507 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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