lines.bas 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Attribute VB_Name = "lines"
  2. '// 代码写到这里吧,视频结束
  3. Sub start()
  4. LinesForm.Show 0
  5. End Sub
  6. Public Function Nodes_DrawLines()
  7. On Error GoTo ErrorHandler
  8. API.BeginOpt
  9. Dim sr As ShapeRange, sr_tmp As New ShapeRange, sr_lines As New ShapeRange
  10. Dim s As Shape, sh As Shape
  11. Dim nr As NodeRange
  12. Set sr = ActiveSelectionRange
  13. If sr.Count = 0 Then Exit Function
  14. For Each sh In sr
  15. Set nr = sh.Curve.Selection
  16. If nr.Count > 0 Then
  17. For Each n In nr
  18. Set s = ActiveLayer.CreateEllipse2(n.PositionX, n.PositionY, 0.5, 0.5)
  19. sr_tmp.Add s
  20. Next n
  21. End If
  22. Next sh
  23. '// 没有选择节点的情况,使用物件中心划线
  24. If sr_tmp.Count < 2 And sr.Count > 1 Then
  25. Set Line = DrawLine(sr(1), sr(2))
  26. sr_lines.Add Line
  27. End If
  28. sr_tmp.Sort "@shape1.left < @shape2.left"
  29. '// 使用 Count 遍历 shaperange 这种情况方便点
  30. For i = 1 To sr_tmp.Count - 1
  31. Set Line = DrawLine(sr_tmp(i), sr_tmp(i + 1))
  32. sr_lines.Add Line
  33. Next
  34. sr_tmp.Delete
  35. sr_lines.CreateSelection
  36. ErrorHandler:
  37. API.EndOpt
  38. End Function
  39. Public Function Draw_Multiple_Lines(hv As cdrAlignType)
  40. On Error GoTo ErrorHandler
  41. API.BeginOpt
  42. Dim sr As ShapeRange, sr_lines As New ShapeRange
  43. Set sr = ActiveSelectionRange
  44. If sr.Count < 2 Then Exit Function
  45. If hv = cdrAlignVCenter Then
  46. '// 从左到右排序
  47. sr.Sort "@shape1.left < @shape2.left"
  48. ElseIf hv = cdrAlignHCenter Then
  49. '// 从上到下排序
  50. sr.Sort "@shape1.top < @shape2.top"
  51. End If
  52. For i = 1 To sr.Count - 1 Step 2
  53. Set Line = DrawLine(sr(i), sr(i + 1))
  54. sr_lines.Add Line
  55. Next
  56. sr_lines.CreateSelection
  57. ErrorHandler:
  58. API.EndOpt
  59. End Function
  60. Public Function FirtLineTool()
  61. Dim sr As ShapeRange
  62. Set sr = ActiveSelectionRange
  63. If sr.Count > 1 Then
  64. Set Line = DrawLine(sr(1), sr(2))
  65. End If
  66. End Function
  67. Private Function DrawLine(ByVal s1 As Shape, ByVal s2 As Shape) As Shape
  68. '// 创建线段方法在图层上的指定位置创建由单个线段组成的曲线。
  69. Set DrawLine = ActiveLayer.CreateLineSegment(s1.CenterX, s1.CenterY, s2.CenterX, s2.CenterY)
  70. End Function
  71. Sub Test()
  72. ActiveDocument.Unit = cdrMillimeter
  73. Set Rect = ActiveLayer.CreateRectangle(0, 0, 30, 30)
  74. Set ell = ActiveLayer.CreateEllipse2(50, 50, 10, 10)
  75. Set Line = DrawLine(Rect, ell)
  76. End Sub