本帖最后由 作者 于 2009-5-23 20:33:34 编辑
目前就只缺那个没有实现,还是会提示错误。如果实现了就好。 全部代码如下: '连接AutoCAD Public Sub AutoCAD_Appliaction() On Error Resume Next Dim Thisdrawing As AcadDocument Set acadapp = GetObject(, "AutoCAD.Application.16") If Err Then Err.Clear Set acadapp = CreateObject("AutoCAD.Application.16") If Err Then MainForm.Visible = False MsgBox Err.Description MainForm.Visible = True Exit Sub End If Else If acadapp.Documents.Count >= 1 Then For i = acadapp.Documents.Count To 1 Step -1 Set Thisdrawing = acadapp.Documents.Item(i - 1) If Not acadapp.ActiveDocument.Saved Then If MsgBox("是否要保存以前打开的.dwg文件?", vbYesNo) = vbYes Then acadapp.ActiveDocument.Save Else acadapp.ActiveDocument.Close (False) End If End If Thisdrawing.Close Next End If End If Set Thisdrawing = Nothing acadapp.Visible = True acadapp.WindowState = acMax End Sub '打开图库 Public Sub Open_Gallery(Galleryname As String) On Error Resume Next Dim file As String file = App.Path & "\Gallery\" & Galleryname & ".dwg" If Dir(file) <> "" Then acadapp.Documents.Open file Else MsgBox ("文件" & Galleryname & "不存在") End If End Sub '建立选择集并遍历选择集中实体并复制移动实体 Public Sub copy_moveSset(selectname As String, jielength As Double, jienum As Integer, Layername As String) On Error Resume Next acadapp.SelectionSets(selectname).Delete Set ssetobj = acadapp.ActiveDocument.SelectionSets.Add(selectname) AppActivate acadapp.Caption '建立选择集,选择图层 Dim fType(0) As Integer Dim fData(0) As Variant fType(0) = 8 fData(0) = Layername Dim FilterType As Variant Dim FilterData As Variant FilterType = fType FilterData = fData ssetobj.Select acSelectionSetAll, , , fType, fData Dim entry As AcadEntity Dim coent As Variant Dim point1(0 To 2) As Double Dim point2(0 To 2) As Double For i = 1 To jienum point1(0) = 0# point1(1) = 0# point1(2) = 0# point2(0) = point1(0) + (i - 1) * jielength point2(1) = 0# point2(2) = 0# For Each entry In ssetobj Set coent = entry.Copy Call coent.Move(point1, point2) Next Next i ssetobj.Delete End Sub '返回包含于选择集中每一项目的变体数,参数:一选择集 Public Function ssArray(ss As AcadSelectionSet) Dim retVal() As AcadEntity, k As Long ReDim retVal(0 To ss.Count - 1) For k = 0 To ss.Count - 1 Set retVal(k) = ss.Item(k) Next ssArray = retVal End Function '建立选择集 Public Function CreateSelectionSet(Optional ByVal SSetName As String) As AcadSelectionSet On Error Resume Next '建立选择集 acadapp.ActiveDocument.SelectionSets(SSetName).Delete Set CreateSelectionSet = acadapp.ActiveDocument.SelectionSets.Add(SSetName) End Function '打开到一张图纸上 Public Sub CopyFromOuterdwg(CurDocname As String, NewDocname As String) ' 打开第一张图 Dim objCurDoc As AcadDocument Set objCurDoc = acadapp.Documents(App.Path & "\Gallery\" & CurDocname & ".dwg") ' 打开一个新图形 Dim objNewDoc As AcadDocument Set objNewDoc = acadapp.Documents(App.Path & "\Gallery\" & NewDocname & ".dwg") Set objNewDoc = acadapp.ActiveDocument ' 将外部图形的实体复制到当前图形 Set ssetobj = CreateSelectionSet ssetobj.Select acSelectionSetAll acadapp.ActiveDocument.CopyObjects ssArray(ssetobj), objCurDoc.ModelSpace objCurDoc.Regen acAllViewports ' 关闭打开的图形 objNewDoc.Close (False) End Sub Private Sub Command7_Click() AutoCAD_Appliaction Open_Gallery "预热带前段" copy_moveSset "NEW1", 232, Val(copy_move.yc_1.Text), "0" Open_Gallery "预热带中段" copy_moveSset "NEW1", 232, Val(copy_move.yc_2.Text), "0" Open_Gallery "预热带后段" copy_moveSset "NEW1", 232, Val(copy_move.yc_3.Text), "0" CopyFromOuter "预热带前段", "预热带中段" CopyFromOuter "预热带前段", "预热带后段" End Sub |