明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1509|回复: 5

粗糙度标注-(McCad---2003-11-18编的程序)

[复制链接]
发表于 2007-11-22 13:50:00 | 显示全部楼层 |阅读模式
2003-11-18编的程序见http://bbs.mjtd.com/forum.php?mod=viewthread&tid=12844
在这个粘子中采用的是匿名块技术,随后McCad又改为属性块的生成方法和属性块插入后的属性修改。
本着学习态度,对下语句进一步分析。
     Set objBlock =    ThisDrawing.Blocks.Add(InsPnt, "*U")     
    ThisDrawing.Utility.PolarPoint(InsPnt, Radians(60), 12)
    Set objBlockRef =        ThisDrawing.ModelSpace.InsertBlock(InsertPoint, blkname, Factor, Factor, Factor, Angle)   
  1. Sub AddCCD()
  2. Dim pnt As Variant
  3. pnt =            ThisDrawing.Utility.GetPoint(, "插入点:")
  4. CreateCCD 0, pnt, Radians(150), 3.5, 1
  5. End Sub
  6.      
  7. ' 粗糙度符号标注函数
  8. ' Mode为粗糙度模式,0代表表面未加工,1代表表面加工
  9. ' InsertPoint为插入点位置
  10. ' Angle为插入的角度
  11. ' Value粗糙度值
  12. ' Factor为插入的比例因子
  13. Function CreateCCD(Mode As Integer, InsertPoint As Variant, Angle            As Double, Value            As String, Factor As Double)            As AcadBlockReference
  14.      Dim objBlock As            AcadBlock
  15.      Dim InsPnt(2)            As Double
  16.      InsPnt(0)            = 0: InsPnt(1)            = 0: InsPnt(2)            = 0
  17.      Set objBlock =            ThisDrawing.Blocks.Add(InsPnt, "*U")
  18.      Dim Pnt2 As Variant
  19.      Dim Pnt3 As Variant
  20.      Dim Pnt4 As Variant
  21.      Dim Pnt5 As Variant
  22.      Dim Pnt6 As Variant
  23.      Dim Pnt7 As Variant
  24.      Dim r As Variant
  25.      Pnt2 =            ThisDrawing.Utility.PolarPoint(InsPnt, Radians(60), 12)
  26.      Pnt3 =            ThisDrawing.Utility.PolarPoint(InsPnt, Radians(120), 6)
  27.      Pnt4 =            ThisDrawing.Utility.PolarPoint(Pnt3, 0, 6)
  28.      Pnt5 =            ThisDrawing.Utility.PolarPoint(InsPnt, Radians(90), 3 / Cos(Radians(30)))
  29.      Pnt6 =            ThisDrawing.Utility.PolarPoint(Pnt4, Radians(90), 0.7)
  30.      Pnt7 =            ThisDrawing.Utility.PolarPoint(Pnt4, Radians(90), 4.2)
  31.      r = 3 * Tan(Radians(30))
  32.      Dim objLine As            AcadLine
  33.      Dim objCircle As            AcadCircle
  34.      Set objLine = objBlock.AddLine(InsPnt, Pnt2)
  35.      objLine.color            = acByBlock
  36.      Set objLine = objBlock.AddLine(InsPnt, Pnt3)
  37.      objLine.color            = acByBlock
  38.      If            Mode            = 1 Then
  39.          Set objLine = objBlock.AddLine(Pnt3, Pnt4)
  40.          objLine.color            = acByBlock
  41.      ElseIf            Mode            = 0 Then
  42.          Set objCircle = objBlock.AddCircle(Pnt5, r)
  43.          objCircle.color            = acByBlock
  44.      End If
  45.      Dim objText As            AcadText
  46.      If            Angle > Radians(90)            And            Angle <= Radians(270)            Then
  47.          Set objText = objBlock.AddText(Value, Pnt6, 3.5)
  48.          objText.Alignment            = acAlignmentTopLeft
  49.          objText.Rotate InsPnt, Radians(180)
  50.          objText.Move InsPnt, Pnt6
  51.      Else
  52.          Set objText = objBlock.AddText(Value, Pnt6, 3.5)
  53.          objText.Alignment            = acAlignmentBottomRight
  54.          objText.Move InsPnt, Pnt6
  55.      End If
  56.      objText.color            = acByBlock
  57.      Dim blkname As            String
  58.      blkname = objBlock.Name
  59.      Dim objBlockRef As AcadBlockReference
  60.      Set objBlockRef =            ThisDrawing.ModelSpace.InsertBlock(InsertPoint, blkname, Factor, Factor, Factor, Angle)
  61.      Set CreateCCD = objBlockRef
  62. End Function
  63.      
  64. Public            Function PI()            As Double
  65.    PI = Atn(1)            * 4
  66. End Function
  67.      
  68. Private            Function Degrees(Radians As Double)            As Double
  69.    Degrees = Radians / PI * 180
  70. End Function
  71.      
  72. Private            Function Radians(Degrees As Double)            As Double
  73.    Radians = Degrees / 180 * PI
  74. End Function
 楼主| 发表于 2007-11-22 15:25:00 | 显示全部楼层

Gets the point at a specified angle and distance from a given point.

以基点为坐标,按极坐标角和定长获得另一点坐标。

RetVal = PolarPoint(Point, Angle, Distance)

ThisDrawing.Utility 取得文档的Utility 对象。

RetVal = object.AddLine(StartPoint, EndPoint)

对于直线、多义线、圆等实体,采用thisdrwing.modespace

对于promt,getpoint等采用thisdrawing.Uitility

Uitility和ModeSpace区别在什么????

 楼主| 发表于 2007-11-22 16:51:00 | 显示全部楼层
本帖最后由 作者 于 2007-11-22 19:15:00 编辑
  1. Sub ic()
  2.   On Error Resume Next
  3.   Dim pnt As Variant
  4.   pnt = ThisDrawing.Utility.GetPoint(, " 选择插入点:")
  5.   Dim angle As Double
  6.   angle = ThisDrawing.Utility.GetAngle(pnt, " 选择选择角度:")
  7.   Dim txt As String
  8.   txt = ThisDrawing.Utility.GetString(0, " 请输入粗糙度大小:")
  9.   Dim mode As Integer
  10.   mode = ThisDrawing.Utility.GetInteger(" 选择粗糙度样式[表面非加工0/表面加工1]<表面非加工>:")
  11.   If Err Then
  12.     mode = 0
  13.     Err.Clear
  14.   End If
  15.   CreateCCD1 mode, pnt, angle, txt, 1
  16. End Sub
  17. ' 粗糙度符号标注函数
  18. ' Mode为粗糙度模式,0代表表面未加工,1代表表面加工
  19. ' InsertPoint为插入点
  20. ' Angle为插入的角度
  21. ' Value粗糙度值
  22. ' Factor为插入的比例因子
  23. Function CreateCCD1(mode As Integer, InsertPoint As Variant, angle As Double, Value As String, Factor As Double) As AcadBlockReference
  24.   Dim objBlock As AcadBlock
  25.   Dim InsPnt(2) As Double
  26.   InsPnt(0) = 0: InsPnt(1) = 0: InsPnt(2) = 0
  27.   Dim BlkName As String
  28.   BlkName = "mc_ccd_" & mode
  29.   On Error Resume Next
  30.   Set objBlock = ThisDrawing.Blocks(BlkName)
  31.   If Err Then Err.Clear
  32.    Set objBlock = ThisDrawing.Blocks.Add(InsPnt, BlkName)
  33.   Dim Pnt2 As Variant
  34.   Dim Pnt3 As Variant
  35.   Dim Pnt4 As Variant
  36.   Dim Pnt5 As Variant
  37.   Dim Pnt6 As Variant
  38.   Dim r As Variant
  39.   Pnt2 = ThisDrawing.Utility.PolarPoint(InsPnt, Radians(60), 12)
  40.   Pnt3 = ThisDrawing.Utility.PolarPoint(InsPnt, Radians(120), 6)
  41.   Pnt4 = ThisDrawing.Utility.PolarPoint(Pnt3, 0, 6)
  42.   Pnt5 = ThisDrawing.Utility.PolarPoint(InsPnt, Radians(90), 3 / Cos(Radians(30)))
  43.   Pnt6 = ThisDrawing.Utility.PolarPoint(Pnt4, Radians(90), 0.7)
  44.   r = 3 * Tan(Radians(30))
  45.   Dim objLine As AcadLine
  46.   Dim objCircle As AcadCircle
  47.   Set objLine = objBlock.AddLine(InsPnt, Pnt2)
  48.   objLine.color = acByBlock
  49.   Set objLine = objBlock.AddLine(InsPnt, Pnt3)
  50.   objLine.color = acByBlock
  51.   If mode = 1 Then
  52.     Set objLine = objBlock.AddLine(Pnt3, Pnt4)
  53.     objLine.color = acByBlock
  54.   ElseIf mode = 0 Then
  55.     Set objCircle = objBlock.AddCircle(Pnt5, r)
  56.     objCircle.color = acByBlock
  57.   End If
  58.   Dim objAtt As AcadAttribute
  59.   Set objAtt = objBlock.AddAttribute(3.5, acAttributeModeNormal, "粗糙度值", Pnt6, "CCD", "")
  60.   objAtt.Alignment = acAlignmentBottomRight
  61.   objAtt.Move InsPnt, Pnt6
  62.   objAtt.color = acByBlock
  63. 'End If
  64.   Dim objBlockRef As AcadBlockReference
  65.   Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(InsertPoint, BlkName, Factor, Factor, Factor, angle)
  66.   Dim objAtts As Variant
  67.   objAtts = objBlockRef.GetAttributes
  68.   Dim objAttRef As AcadAttributeReference
  69.   Set objAttRef = objAtts(0)
  70.   objAttRef.textString = Value
  71.   If angle > Radians(90) And angle <= Radians(270) Then
  72.     objAttRef.Alignment = acAlignmentTopLeft
  73.     objAttRef.Rotate objAttRef.TextAlignmentPoint, Radians(0)
  74.   End If
  75. End Function
 楼主| 发表于 2007-11-22 16:52:00 | 显示全部楼层

Sub ic()
  On Error Resume Next
  Dim pnt As Variant
  pnt = ThisDrawing.Utility.GetPoint(, " 选择插入点:")
  Dim angle As Double
  angle = ThisDrawing.Utility.GetAngle(pnt, " 选择选择角度:")
  Dim txt As String
  txt = ThisDrawing.Utility.GetString(0, " 请输入粗糙度大小:")
  Dim mode As Integer
  mode = ThisDrawing.Utility.GetInteger(" 选择粗糙度样式[表面非加工0/表面加工1]<表面非加工>:")
  If Err Then
    mode = 0
    Err.Clear
  End If
  CreateCCD1 mode, pnt, angle, txt, 1
End Sub

' 粗糙度符号标注函数
' Mode为粗糙度模式,0代表表面未加工,1代表表面加工
' InsertPoint为插入点
' Angle为插入的角度
' Value粗糙度值
' Factor为插入的比例因子
Function CreateCCD1(mode As Integer, InsertPoint As Variant, angle As Double, Value As String, Factor As Double) As AcadBlockReference


  Dim objBlock As AcadBlock
  Dim InsPnt(2) As Double
  InsPnt(0) = 0: InsPnt(1) = 0: InsPnt(2) = 0
  Dim BlkName As String
  BlkName = "mc_ccd_" & mode
  On Error Resume Next
  Set objBlock = ThisDrawing.Blocks(BlkName)
  If Err Then Err.Clear
   Set objBlock = ThisDrawing.Blocks.Add(InsPnt, BlkName)
  Dim Pnt2 As Variant
  Dim Pnt3 As Variant
  Dim Pnt4 As Variant
  Dim Pnt5 As Variant
  Dim Pnt6 As Variant
  Dim r As Variant
  Pnt2 = ThisDrawing.Utility.PolarPoint(InsPnt, Radians(60), 12)
  Pnt3 = ThisDrawing.Utility.PolarPoint(InsPnt, Radians(120), 6)
  Pnt4 = ThisDrawing.Utility.PolarPoint(Pnt3, 0, 6)
  Pnt5 = ThisDrawing.Utility.PolarPoint(InsPnt, Radians(90), 3 / Cos(Radians(30)))
  Pnt6 = ThisDrawing.Utility.PolarPoint(Pnt4, Radians(90), 0.7)
  r = 3 * Tan(Radians(30))
  Dim objLine As AcadLine
  Dim objCircle As AcadCircle
  Set objLine = objBlock.AddLine(InsPnt, Pnt2)
  objLine.color = acByBlock
  Set objLine = objBlock.AddLine(InsPnt, Pnt3)
  objLine.color = acByBlock
  If mode = 1 Then
    Set objLine = objBlock.AddLine(Pnt3, Pnt4)
    objLine.color = acByBlock
  ElseIf mode = 0 Then
    Set objCircle = objBlock.AddCircle(Pnt5, r)
    objCircle.color = acByBlock
  End If
  Dim objAtt As AcadAttribute
  Set objAtt = objBlock.AddAttribute(3.5, acAttributeModeNormal, "粗糙度值", Pnt6, "CCD", "")
  objAtt.Alignment = acAlignmentBottomRight
  objAtt.Move InsPnt, Pnt6
  objAtt.color = acByBlock
'End If
  Dim objBlockRef As AcadBlockReference
  Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(InsertPoint, BlkName, Factor, Factor, Factor, angle)
  Dim objAtts As Variant
  objAtts = objBlockRef.GetAttributes
  Dim objAttRef As AcadAttributeReference
  Set objAttRef = objAtts(0)
  objAttRef.textString = Value
  If angle > Radians(90) And angle <= Radians(270) Then
    objAttRef.Alignment = acAlignmentTopLeft
    objAttRef.Rotate objAttRef.TextAlignmentPoint, Radians(0)
  End If
End Function

发表于 2007-11-23 22:12:00 | 显示全部楼层

呵呵,四年前的程序都被你抓出来。

现在想想看,这个程序应该也是对VBA及AutoCAD应用的一个比较好的例子了,因为使用了各种比较少用的技术来完成。

 楼主| 发表于 2007-11-28 08:49:00 | 显示全部楼层
mccad发表于2007-11-23 22:12:00呵呵,四年前的程序都被你抓出来。现在想想看,这个程序应该也是对VBA及AutoCAD应用的一个比较好的例子了,因为使用了各种比较少用的技术来完成。

你这个程序相当实用性,我现在认真吸取你编程的思路。

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

本版积分规则

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

GMT+8, 2024-11-26 12:52 , Processed in 0.190315 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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