设为首页收藏本站

嘻皮客娱乐学习网

 找回密码
 中文注册
搜索
打印 上一主题 下一主题
开启左侧

AutoCAD VBA程序---批量插入块源代码

[复制链接]
跳转到指定楼层
楼主
发表于 2014-8-27 13:26:14 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Option Explicit

Private Sub cmdClear_Click()

  Me.lstFile.Clear

End Sub

Private Sub cmdDelete_Click()

    If lstFile.ListCount >= 1 Then

        If lstFile.ListIndex = -1 Then

            MsgBox "请选择列表中的图形名称!", vbExclamation, Me.Caption

            Exit Sub

        End If

        lstFile.RemoveItem (lstFile.ListIndex)

    End If

End Sub

Private Sub cmdInsert_Click()

  Dim i As Integer

  Dim pntX(0 To 2) As Double

  With Me

    pntX(0) = 0#: pntX(1) = 0#: pntX(2) = 0#

    If .lstFile.ListCount = 0 Then Exit Sub

    .pbInsert.Value = 0

    .pbInsert.Max = .lstFile.ListCount

    For i = 0 To .lstFile.ListCount - 1

        .lstFile.ListIndex = i

        ThisDrawing.Application.ActiveDocument.ModelSpace.InsertBlock pntX, .lstFile.List(i), 1, 1, 1, 0

        .pbInsert.Value = .pbInsert.Value + 1

    Next i

    MsgBox "批量插入块完毕。", vbInformation, .Caption

    Unload Me

  End With

End Sub

Private Sub cmdOpen_Click()

    Dim i As Integer

    Dim Y As Integer

    Dim Z As Integer

    Dim fileNames() As String

    On Error GoTo errHandle

    With comDlg

        .CancelError = True

        .MaxFileSize = 32767

        .Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks

        .DialogTitle = "选择图形文件"

        .filter = "图形文件(*.dwg)|*.dwg"

        .FileName = ""

        .ShowOpen

    End With

    comDlg.FileName = comDlg.FileName & Chr(0)

    Z = 1

    For i = 1 To Len(comDlg.FileName)

        i = InStr(Z, comDlg.FileName, Chr(0))

        If i = 0 Then Exit For

        ReDim Preserve fileNames(Y)

        fileNames(Y) = mID(comDlg.FileName, Z, i - Z)

        Z = i + 1

        Y = Y + 1

    Next i

    Dim count As Integer

    count = lstFile.ListCount

    If Y = 1 Then

        If Not HasItem(fileNames(Y - 1)) Then

            lstFile.AddItem fileNames(Y - 1), count

        End If

    Else

        For i = 1 To Y - 1

            If StrComp(Right$(fileNames(0), 1), "\") = 0 Then

                fileNames(i) = fileNames(0) & fileNames(i)

            Else

                fileNames(i) = fileNames(0) & "\" & fileNames(i)

            End If

            

            If Not HasItem(fileNames(i)) Then

                lstFile.AddItem fileNames(i), i - 1 + count

            End If

        Next i

    End If

errHandle:

End Sub

Private Sub lstFile_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

  On Error Resume Next

  MsgBox lstFile.List(lstFile.ListIndex), vbInformation, Me.Caption

End Sub

Private Function HasItem(ByVal strDwgName As String) As Boolean

    HasItem = False

    Dim i As Integer

    For i = 0 To lstFile.ListCount - 1

        If StrComp(lstFile.List(i), strDwgName, vbTextCompare) = 0 Then

            HasItem = True

            Exit Function

        End If

    Next i
回复

使用道具 举报

小黑屋|手机版|嘻皮客网 ( 京ICP备10218169号|京公网安备11010802013797  

GMT+8, 2024-6-4 09:48 , Processed in 0.166506 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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