明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: amberilee

请教大虾,如何在一个cad文件里查找给定的关键字?用vba

  [复制链接]
发表于 2003-7-25 19:12:00 | 显示全部楼层
这个多重偏移程序给你,希望它可以帮到你做表格!程序代码如下:

Sub callp()

On Error GoTo err
Dim keyWord As String



'选择偏移模式
ThisDrawing.Utility.InitializeUserInput 0, "Add Noadd"
keyWord = ThisDrawing.Utility.GetKeyword _
(vbCrLf & "输入选项[分段偏移(A)/总长偏移(N)]:<分段偏移> ")

If keyWord = "" Then keyWord = "Add" '若为空则默认分段偏移
'MsgBox keyWord
Select Case keyWord
Case "Add"
Call soffset1
Case "Noadd"
Call soffset2
End Select

err:
Exit Sub
End Sub
Sub soffset1() '分段进行偏移
'偏移命令中的偏移值是正值的情况,将在线进向的左,否在右
On Error GoTo err
Dim offdist(58) As Variant
Dim s As Integer
Dim i As Integer
Dim spnt As Variant
Dim epnt As Variant
Dim ts As String
Dim points As Variant



Dim sset As AcadSelectionSet
For i = 0 To ThisDrawing.SelectionSets.Count - 1
    ThisDrawing.SelectionSets.Item(i).Clear
    ThisDrawing.SelectionSets.Item(i).Delete
Next

Set sset = ThisDrawing.SelectionSets.Add("offsetobj")
sset.SelectOnScreen

If sset.Item(0).ObjectName = "AcDbPolyline" Then
points = sset.Item(0).Coordinates


    If points(1) > points(3) Then
            ts = "请输入偏移距离:[正值向左,负值向右]"
        
            ElseIf points(1) < points(3) Then
            ts = "请输入偏移距离:[正值向右,负值向左]"
            ElseIf points(1) = points(3) And points(0) < points(2) Then
             ts = "请输入偏移距离:[正值向下,负值向上]"
             ElseIf points(1) = points(3) And points(0) > points(2) Then
             ts = "请输入偏移距离:[正值向上,负值向下]"

    End If
   
ElseIf sset.Item(0).ObjectName = "AcDb2dPolyline" Then
points = sset.Item(0).Coordinates
    If points(1) > points(4) Then
            ts = "请输入偏移距离:[正值向左,负值向右]"
              
               ElseIf points(1) < points(4) Then
               ts = "请输入偏移距离:[正值向右,负值向左]"
               ElseIf points(1) = points(4) And points(0) < points(3) Then
              
                ts = "请输入偏移距离:[正值向下,负值向上]"
                   ElseIf points(1) = points(4) And points(0) > points(3) Then
                 ts = "请输入偏移距离:[正值向上,负值向下]"
    End If
   
    ElseIf sset.Item(0).ObjectName = "AcDbLine" Then
    spnt = sset.Item(0).StartPoint
    epnt = sset.Item(0).EndPoint
        If spnt(1) < epnt(2) Then
            ts = "请输入偏移距离:[正值向左,负值向右]"
            ElseIf spnt(1) > epnt(1) Then
             ts = "请输入偏移距离:[正值向右,负值向左]"
             ElseIf spnt(1) = epnt(1) And spnt(0) < epnt(0) Then
              ts = "请输入偏移距离:[正值向上,负值向下]"
              ElseIf spnt(1) = epnt(1) And spnt(0) > epnt(0) Then
              ts = "请输入偏移距离:[正值向下,负值向上]"
        End If
End If


Dim offobj As Variant
offdist(0) = 0

s = 1
ss:


offdist(s) = ThisDrawing.Utility.GetReal(ts)


offdist(s) = offdist(s) + offdist(s - 1)

offobj = sset.Item(0).Offset(offdist(s))
offobj(0).Color = acGreen
s = s + 1
GoTo ss
Exit Sub
err:

Exit Sub

End Sub

Sub soffset2() '以总长进行偏移

On Error GoTo err
Dim offdist(58) As Variant
Dim s As Integer
Dim i As Integer
Dim ts As String
Dim points As Variant

Dim sset As AcadSelectionSet
For i = 0 To ThisDrawing.SelectionSets.Count - 1
ThisDrawing.SelectionSets.Item(i).Clear
ThisDrawing.SelectionSets.Item(i).Delete
Next

Set sset = ThisDrawing.SelectionSets.Add("offsetobj")
sset.SelectOnScreen
If sset.Item(0).ObjectName = "AcDbPolyline" Then

points = sset.Item(0).Coordinates


    If points(1) > points(3) Then
            ts = "请输入偏移距离:[正值向左,负值向右]"
   
            ElseIf points(1) < points(3) Then
            ts = "请输入偏移距离:[正值向右,负值向左]"
            ElseIf points(1) = points(3) And points(0) < points(2) Then
             ts = "请输入偏移距离:[正值向下,负值向上]"
             ElseIf points(1) = points(3) And points(0) > points(2) Then
             ts = "请输入偏移距离:[正值向上,负值向下]"
    End If
ElseIf sset.Item(0).ObjectName = "AcDb2dPolyline" Then
    points = sset.Item(0).Coordinates
    If points(1) > points(4) Then
            ts = "请输入偏移距离:[正值向左,负值向右]"
              
               ElseIf points(1) < points(4) Then
               ts = "请输入偏移距离:[正值向右,负值向左]"
                 ElseIf points(1) = points(4) And points(0) < points(3) Then
              
                    ts = "请输入偏移距离:[正值向下,负值向上]"
                       ElseIf points(1) = points(4) And points(0) > points(3) Then
                     ts = "请输入偏移距离:[正值向上,负值向下]"
    End If
    ElseIf sset.Item(0).ObjectName = "AcDbLine" Then
    spnt = sset.Item(0).StartPoint
    epnt = sset.Item(0).EndPoint
            If spnt(1) < epnt(2) Then
                ts = "请输入偏移距离:[正值向左,负值向右]"
                ElseIf spnt(1) > epnt(1) Then
                 ts = "请输入偏移距离:[正值向右,负值向左]"
                 ElseIf spnt(1) = epnt(1) And spnt(0) < epnt(0) Then
                  ts = "请输入偏移距离:[正值向上,负值向下]"
                  ElseIf spnt(1) = epnt(1) And spnt(0) > epnt(0) Then
                  ts = "请输入偏移距离:[正值向下,负值向上]"
            End If
End If

Dim offobj As Variant


s = 1
ss:

offdist(s) = ThisDrawing.Utility.GetReal(ts)


offdist(s) = offdist(s)

offobj = sset.Item(0).Offset(offdist(s))
offobj(0).Color = acGreen
s = s + 1
GoTo ss
Exit Sub
err:
Exit Sub

End Sub
 楼主| 发表于 2003-7-25 21:43:00 | 显示全部楼层
我们做表格就是画直线,然后偏移
发表于 2003-7-25 23:17:00 | 显示全部楼层
呵呵,那就简单了,我做了一个表格绘制程序,放在“编程申请”里,你去下载用吧!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-28 15:45 , Processed in 0.168775 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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