明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 882|回复: 1

VBA中编写块命令的问题

[复制链接]
发表于 2015-7-9 21:38:26 | 显示全部楼层 |阅读模式
在CAD中编程块,每次运行一次,在CAD中多增加一个图形,请大神看看程序。谢谢啦。
  1. Private Sub CommandButton1_Click()



  2. Dim PtPick As Variant
  3. UserForm1.hide
  4. PtPick = ThisDrawing.Utility.GetPoint(, "请在屏幕上选择起点:")
  5. TextBox1.Text = PtPick(0)
  6. TextBox2.Text = PtPick(1)
  7. UserForm1.Show


  8. Dim blkObj As AcadBlock
  9. Dim insPnt(0 To 2) As Double
  10.    
  11.     '设定图块对象的原点坐标
  12.     insPnt(0) = 0: insPnt(1) = 0: insPnt(2) = 0
  13.     '在Blocks集合中创建名为TestBlock1的块对象
  14.     Set blkObj = ThisDrawing.Blocks.Add(insPnt, "TestBlock1")
  15.    
  16.    
  17.    
  18.     '-------------------------------------------------------------


  19. Dim cirObj As AcadCircle
  20. Dim center(0 To 2) As Double
  21. Dim radius As Double


  22. center(0) = TextBox1.Text: center(1) = TextBox2.Text: center(2) = 0


  23. radius = 0


  24. radius = Val(TextBox3.Text)

  25.     Set cirObj = blkObj.AddCircle(center, radius)

  26.     cirObj.color = acRed
  27.    
  28.    
  29.     Dim lineObj As AcadLine
  30.     Dim sPnt(0 To 2) As Double, ePnt(0 To 2) As Double
  31.    
  32.     sPnt(0) = center(0): sPnt(1) = center(1): sPnt(2) = 0
  33.     ePnt(0) = center(0) + 60: ePnt(1) = center(1) + 80: ePnt(2) = 0
  34.    
  35.     '创建一条直线
  36.     Set lineObj = blkObj.AddLine(sPnt, ePnt)



  37. '-------------------------------------------------------------
  38.     '本段代码将把TestBlock1块对象插入到模型空间
  39.    
  40.     Dim blkRefObj As AcadBlockReference
  41.    
  42.    
  43.     Dim insertPnt(0 To 2) As Double
  44.    
  45.     '指定模型空间的插入点
  46.     insertPnt(0) = 120: insertPnt(1) = 100: insertPnt(2) = 0
  47.    
  48.     '插入图块
  49.     Set blkRefObj = ThisDrawing.ModelSpace.InsertBlock(insertPnt, "TestBlock1", 1#, 1#, 1#, 0#)
  50.    
  51.    
  52.     blkRefObj.Update



  53. End Sub
发表于 2015-7-14 07:33:05 | 显示全部楼层
你的问题是什么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 11:38 , Processed in 0.222676 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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