加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

[转载]AutoCAD VBA程序---批量插入块源代码

(2017-05-07 10:11:52)
标签:

转载

分类: CAD
Option Explicit
Private Sub cmdClear_Click()
  Me.lstFile.Clear
End Sub
Private Sub cmdDelete_Click()
    If lstFile.ListCount >= 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 As Integer
  Dim pntX(0 To 2) As Double
  With Me
    pntX(0) 0#: pntX(1) 0#: pntX(2) 0#
    If .lstFile.ListCount Then Exit Sub
    .pbInsert.Value 0
    .pbInsert.Max .lstFile.ListCount
    For 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 As Integer
    Dim As Integer
    Dim 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)
    1
    For To Len(comDlg.FileName)
        InStr(Z, comDlg.FileName, Chr(0))
        If Then Exit For
        ReDim Preserve fileNames(Y)
        fileNames(Y) mID(comDlg.FileName, Z, Z)
        1
        1
    Next i
    Dim count As Integer
    count lstFile.ListCount
    If Then
        If Not HasItem(fileNames(Y 1)) Then
            lstFile.AddItem fileNames(Y 1), count
        End If
    Else
        For To 1
            If StrComp(Right$(fileNames(0), 1), "") 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), 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 As Integer
    For To lstFile.ListCount 1
        If StrComp(lstFile.List(i), strDwgName, vbTextCompare) Then
            HasItem True
            Exit Function
        End If
    Next i

0

  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有