乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 29|回复: 1

在Excel中起动AutoCAD

[复制链接]

120

主题

326

帖子

7

银币

中流砥柱

Rank: 25

铜币
806
发表于 2008-11-21 20:46:00 | 显示全部楼层 |阅读模式
在Excel中输入以下程序
Sub ls()
  Dim AppCAD As AcadApplication
  On Error Resume Next
  Set AppCAD = GetObject(, ".Application")
  If Err Then
    Debug.Print Err.Number
    Err.Clear
    Set AppCAD = CreateObject("AutoCAD.Application")
  End If
  AppCAD.Visible = True
  Dim objModelSpace As AcadModelSpace
  Dim objDocument As AcadDocument
  Set objModelSpace = AppCAD.ActiveDocument.ModelSpace
  Set objDocument = AppCAD.ActiveDocument
  
End Sub
  1. Sub lll()
  2.   Dim objRegion As Variant
  3.   Dim objCurve() As AcadEntity
  4.   With ConnectCad.ActiveDocument
  5.     ReDim objCurve(Range("A65366").End(xlUp).Row - 2) As AcadEntity
  6.     Debug.Print Range("A65366").End(xlUp).Row, .ModelSpace.Count - 1
  7.     For ii = 2 To Range("A65366").End(xlUp).Row
  8.       Set objCurve(ii - 2) = .HandleToObject(Cells(ii, 1))
  9.     Next ii
  10.     Dim regionObj As Variant
  11.     regionObj = .ModelSpace.AddRegion(objCurve)
  12.     ' Define the extrusion
  13.     Dim Height As Double
  14.     Dim taperAngle As Double
  15.     Height = 20
  16.     taperAngle = 0
  17.    
  18.     ' Create the solid
  19.     Dim SolidObj As Acad3DSolid
  20.     Set SolidObj = .ModelSpace.AddExtrudedSolid(regionObj(0), Height, taperAngle)
  21.     SolidObj.Color = 1
  22.    
  23.     ' Change the viewing direction of the viewport
  24.     Dim NewDirection(0 To 2) As Double
  25.     NewDirection(0) = -1: NewDirection(1) = -1: NewDirection(2) = 1
  26.     .ActiveViewport.Direction = NewDirection
  27.     .ActiveViewport = .ActiveViewport
  28.     ZoomExtents
  29.   End With
  30. End Sub
  1. Function ConnectCad() As AcadApplication
  2.   Dim App As AcadApplication
  3.   On Error Resume Next
  4.   Set App = GetObject(, "AutoCAD.Application")
  5.   If Err Then
  6.     Err.Clear
  7.     Set App = CreateObject("AutoCAD.Application")
  8.   End If
  9.   App.Visible = True
  10.   Set ConnectCad = App
  11. End Function
  12. Function GetCornerSelect(sSetName As String, fTypeVariant As Variant, fDataVariant As Variant) As AcadSelectionSet
  13.    ''
  14.    Dim sSet As AcadSelectionSet
  15.    ''
  16.    Dim fType() As Integer, fData() As Variant
  17.    ReDim fType(UBound(fTypeVariant) + 2) As Integer: ReDim fData(UBound(fDataVariant) + 2) As Variant
  18.    fType(0) = -4: fData(0) = ""
  19.    
  20.    Dim Pt1, Pt2
  21.    With ConnectCad.ActiveDocument
  22.      ''
  23.      On Error Resume Next
  24.      Set sSet = .SelectionSets.Item(sSetName)
  25.      sSet.Delete
  26.      Set sSet = .SelectionSets.Add(sSetName)
  27.      ''
  28.      Pt1 = .Utility.GetPoint(, "Select Forst Point")
  29.      Pt2 = .Utility.GetCorner(Pt1, "Select Corner Point")
  30.      sSet.Select acSelectionSetCrossing, Pt1, Pt2, fType, fData
  31.    End With
  32.    Set GetCornerSelect = sSet
  33. End Function
  34. Sub l()
  35.   Dim sSet As AcadSelectionSet
  36.   Dim fType() As Integer, fData() As Variant
  37.   nn = 0
  38.   ReDim fType(nn) As Integer: ReDim fData(nn) As Variant
  39.   fType(0) = 8: fData(0) = "0"
  40.   Set sSet = GetCornerSelect("testSset", fType, fData)
  41. End Sub
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
1
发表于 2008-11-24 21:39:00 | 显示全部楼层
感觉还不错 补充一下 得将excel的VBA编辑器中 工具-引用-AUTOCAD 类型库选中哦。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-3 17:35 , Processed in 0.882350 second(s), 57 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表