明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1439|回复: 4

一个小小的问题深深的困扰着我。

[复制链接]
发表于 2011-12-14 21:27:48 | 显示全部楼层 |阅读模式
     最近闲来无事,想做一个产状的图标,打算用块的做,(用直接画的方式已经成功),
但是由于Set ObjBlock = ThisDrawing.Blocks.Add(InsertPt, "产状图块")   这句命令的存在,导致每调用一次命令,产状图标都自动增加一个,想在代码最后加入删除这个块,用objblock.delete但是程序又显示失败,请哪位高手帮忙解答下,我搜过论坛里的帖子,好像零星有人碰到这个问题,但我好像没能理解各位达人的意思,估计自己还是个编程菜鸟。以下是代码,能解答或者不能解答的本人都将感激不尽。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2011-12-14 21:32:02 | 显示全部楼层
  1. Option Explicit

  2. Private Sub CommandButton1_Click()
  3. Dim ObjBlock As AcadBlock
  4. Dim ObjLine As AcadLine
  5. Dim ObjLine1 As AcadLine
  6. Dim ObjLWPLine As AcadLWPolyline

  7. Dim InsertPt(0 To 2) As Double
  8. Dim PickPt As Variant
  9. Dim pt1(0 To 2) As Double
  10. Dim pt2(0 To 2) As Double
  11. Dim pt3(0 To 2) As Double
  12. Dim pt4(0 To 2) As Double
  13. Dim pt5(0 To 2) As Double
  14. Dim Points(0 To 3) As Double

  15. Dim x As Double
  16. Dim y As Double

  17. frmMain.Hide
  18. PickPt = ThisDrawing.Utility.GetPoint(, "获取第一点")
  19. x = PickPt(0): y = PickPt(1)
  20. InsertPt(0) = x: InsertPt(1) = y: InsertPt(2) = 0
  21. pt1(0) = x: pt1(1) = y: pt1(2) = 0
  22. pt2(0) = x + 4: pt2(1) = y: pt2(2) = 0
  23. pt3(0) = x: pt3(1) = y - 5: pt3(2) = 0
  24. pt4(0) = x: pt4(1) = y + 5: pt4(2) = 0
  25. pt5(0) = x + 6: pt5(1) = y: pt5(2) = 0
  26. Points(0) = x + 6: Points(1) = y
  27. Points(2) = x + 4: Points(3) = y

  28. Set ObjBlock = ThisDrawing.Blocks.Add(InsertPt, "产状图块")
  29. Set ObjLine = ObjBlock.AddLine(pt1, pt2)
  30. Set ObjLine1 = ObjBlock.AddLine(pt3, pt4)
  31. Set ObjLWPLine = ObjBlock.AddLightWeightPolyline(Points)
  32. ObjLWPLine.SetWidth 0, 0, 1.5
  33. ObjLine.Lineweight = acLnWt030
  34. ObjLine1.Lineweight = acLnWt030
  35. ObjLine.color = acRed
  36. ObjLine1.color = acRed
  37. ObjLWPLine.color = acRed

  38. Dim BlockInsertRef As AcadBlockReference
  39. Set BlockInsertRef = ThisDrawing.ModelSpace.InsertBlock(InsertPt, "产状图块", 1, 1, 1, 0)
  40. frmMain.Show
  41. End Sub
 楼主| 发表于 2011-12-14 21:33:01 | 显示全部楼层
产状程序是vb6.0中写的,下面的代码是在cad vba中写的。哪位高人帮小弟个忙解答下。
发表于 2012-1-18 20:03:42 | 显示全部楼层
制块之前,看块是否已存在
(遍历ThisDrawing.Blocks,看是否有块名相同的)
 楼主| 发表于 2012-1-29 21:20:05 | 显示全部楼层
liu_kunlun 发表于 2012-1-18 20:03
制块之前,看块是否已存在
(遍历ThisDrawing.Blocks,看是否有块名相同的)

谢谢,已经解决了,呵呵,就是假如一个判断语句或者遍历语句,看此块是否存在。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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