乐筑天下

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

[编程交流] 从Excel创建CAD绘图

[复制链接]

2

主题

2

帖子

0

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-15 08:00:13 | 显示全部楼层 |阅读模式
大家好,谢谢你们欢迎我,
我需要用Excel生成多个autoCAD图形。
我刚刚在youtube上找到了这段美丽的视频,满足了我最初的需求。
有没有人有类似的VBA代码或实际上拥有这段代码,可以极大地帮助我入门?
https://www.youtube.com/watch?v=ASxf-ujfJ4o&t=18秒
回复

使用道具 举报

4

主题

2143

帖子

2197

银币

限制会员

铜币
-24
发表于 2022-7-15 08:39:02 | 显示全部楼层
我已将您的线程移动到。NET、ObjectARX和VBA论坛。
回复

使用道具 举报

4

主题

2143

帖子

2197

银币

限制会员

铜币
-24
发表于 2022-7-15 08:50:13 | 显示全部楼层
它似乎是基于Excel的,您可能在Excel VBA网站上运气更好。
 
我收到一条关于他们在视频中链接的网页的警告,他们似乎也没有回应YouTube网站上的问题。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-15 09:02:45 | 显示全部楼层
也许从这个开始,它是在谷歌一次创建一个对象“行VBA excel autocad”等。
 
几天前有一个帖子也是关于这个的,我想它就在这里。
 
  1. Sub Opendwg()
  2.     Dim acadApp As Object
  3.     Dim acadDoc As Object
  4. 'Check if AutoCAD application is open. If is not opened create a new instance and make it visible.
  5.     On Error Resume Next
  6.     Set acadApp = GetObject(, "AutoCAD.Application")
  7.     If acadApp Is Nothing Then
  8.         Set acadApp = CreateObject("AutoCAD.Application")
  9.         acadApp.Visible = True
  10.     End If
  11.     'Check (again) if there is an AutoCAD object.
  12.     If acadApp Is Nothing Then
  13.         MsgBox "Sorry, it was impossible to start AutoCAD!", vbCritical, "AutoCAD Error"
  14.         Exit Sub
  15.     End If
  16.     On Error GoTo 0
  17.     'If there is no active drawing create a new one.
  18.     On Error Resume Next
  19.     Set acadDoc = acadApp.ActiveDocument
  20.     If acadDoc Is Nothing Then
  21.         Set acadDoc = acadApp.Documents.Add
  22.     End If
  23.     On Error GoTo 0
  24.   
  25.     'Check if the active space is paper space and change it to model space.
  26.     If acadDoc.ActiveSpace = 0 Then '0 = acPaperSpace in early binding
  27.         acadDoc.ActiveSpace = 1     '1 = acModelSpace in early binding
  28.     End If
  29. End Sub
  30. Public Sub addline(x1, y1, z1, x2, y2, z2)
  31.   
  32. ' Create the line in model space
  33.     Dim acadApp As Object
  34.     Dim acadDoc As Object
  35.     Set acadApp = GetObject(, "AutoCAD.Application")
  36.     Set acadDoc = acadApp.ActiveDocument
  37.     Dim startpoint(0 To 2) As Double
  38.     Dim endpoint(0 To 2) As Double
  39.     Dim lineobj As Object
  40.     startpoint(0) = x1: startpoint(1) = y1: startpoint(2) = z1
  41.     endpoint(0) = x2: endpoint(1) = y2: endpoint(2) = z2
  42.     Set lineobj = acadDoc.ModelSpace.addline(startpoint, endpoint)
  43.     acadApp.ZoomExtents
  44.    
  45.     End Sub
  46.     Public Sub addcirc(x1, y1, z1, rad)
  47.   
  48. ' Create the circle in model space
  49.     Dim acadApp As Object
  50.     Dim acadDoc As Object
  51.     Set acadApp = GetObject(, "AutoCAD.Application")
  52.     Set acadDoc = acadApp.ActiveDocument
  53.     Dim cenpoint(0 To 2) As Double
  54.    
  55.     Dim circobj As Object
  56.    cenpoint(0) = x1: cenpoint(1) = y1: cenpoint(2) = z1
  57.     Set circobj = acadDoc.ModelSpace.addcircle(cenpoint, rad)
  58.     acadApp.ZoomExtents
  59.    
  60.     End Sub
  61.    
  62.    
  63.     Sub addpoly(cords, col)
  64.    
  65.     Dim acadApp As Object
  66.     Dim acadDoc As Object
  67.     Set acadApp = GetObject(, "AutoCAD.Application")
  68.     Set acadDoc = acadApp.ActiveDocument
  69.     Dim oPline As Object
  70.    
  71. ' add pline to Modelspace
  72. Set oPline = acadDoc.ModelSpace.AddLightWeightPolyline(cords)
  73. oPline.Color = col
  74. End Sub
  75.    
  76.     Sub alan1()
  77.    
  78.    
  79. ' This example adds a line in model space
  80. ' Define the start and end points for the line
  81.    
  82.     px1 = 1
  83.     px2 = 5
  84.     py1 = 1
  85.     py2 = 5
  86.     pz1 = 0
  87.     pz2 = 0
  88.    
  89. Call addline(px1, py1, pz1, px2, py2, pz2)
  90. End Sub
  91. Sub alan2()
  92.     px1 = 1
  93.     py1 = 1
  94.     pz1 = 0
  95.     Radius = 8.5
  96. Call addcirc(px1, py1, pz1, Radius)
  97. End Sub
  98. Sub alan3()
  99. 'Dim coords(0 To n) As Double
  100. Dim coords(0 To 5) As Double
  101. coords(0) = -6: coords(1) = 1:
  102. coords(2) = 3: coords(3) = 5:
  103. coords(4) = 7.55: coords(5) = 6.25:
  104. col = 1
  105.    
  106. Call addpoly(coords, col)
  107. End Sub

 
 
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-1-31 12:57 , Processed in 0.212937 second(s), 71 queries .

© 2020-2025 乐筑天下

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