Box.bas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. Attribute VB_Name = "box"
  2. Public Function Simple_box_three()
  3. ActiveDocument.Unit = cdrMillimeter
  4. Dim sr As New ShapeRange, wing As New ShapeRange
  5. Dim sh As Shape
  6. l = 100: w = 50: h = 70: b = 15
  7. boxL = 2 * l + 2 * w + b: boxH = h
  8. l1x = w: l2x = w + l: l3x = 2 * w + l: l4x = 2 * (w + l)
  9. '// 绘制主体上下盖矩形
  10. Set mainRect = ActiveLayer.CreateRectangle(0, 0, boxL, boxH)
  11. Set topRect = ActiveLayer.CreateRectangle(0, 0, l, w)
  12. topRect.Move l1x, h
  13. Set bottomRect = ActiveLayer.CreateRectangle(0, 0, l, w)
  14. bottomRect.Move l3x, -w
  15. '// 绘制Box 圆角矩形插口
  16. Set top_RoundRect = ActiveLayer.CreateRectangle(0, 0, l, b, 50, 50)
  17. top_RoundRect.Move l1x, h + w
  18. Set bottom_RoundRect = ActiveLayer.CreateRectangle(0, 0, l, b, 0, 0, 50, 50)
  19. bottom_RoundRect.Move l3x, -w - b
  20. '// 绘制box 四个翅膀
  21. Set sh = DrawWing(ActiveLayer.CreateRectangle(0, 0, w, (w + b) / 2 - 2))
  22. wing.Add sh.Duplicate(0, h)
  23. wing.Add sh.Duplicate(l2x, h)
  24. wing.Add sh.Duplicate(0, -sh.SizeHeight)
  25. wing.Add sh.Duplicate(l2x, -sh.SizeHeight)
  26. wing(2).Flip cdrFlipHorizontal
  27. wing(3).Flip cdrFlipVertical
  28. wing(4).Rotate 180
  29. '// 添加到物件组,设置轮廓色 C100
  30. sr.Add mainRect: sr.Add topRect: sr.Add bottomRect
  31. sr.Add top_RoundRect: sr.Add bottom_RoundRect
  32. sr.AddRange wing: sh.Delete
  33. sr.SetOutlineProperties Color:=CreateCMYKColor(100, 0, 0, 0)
  34. '// 绘制尺寸刀痕线
  35. Set sl1 = DrawLine(l1x, 0, l1x, h)
  36. Set sl2 = DrawLine(l2x, 0, l2x, h)
  37. Set sl3 = DrawLine(l3x, 0, l3x, h)
  38. Set sl4 = DrawLine(l4x, 0, l4x, h)
  39. '// 盒子box 群组
  40. sr.Add sl1: sr.Add sl2: sr.Add sl3: sr.Add sl4
  41. sr.CreateSelection: sr.Group
  42. End Function
  43. '// 画一条线,设置轮廓色 M100
  44. Private Function DrawLine(X1, Y1, X2, Y2) As Shape
  45. Set DrawLine = ActiveLayer.CreateLineSegment(X1, Y1, X2, Y2)
  46. DrawLine.Outline.SetProperties Color:=CreateCMYKColor(0, 100, 0, 0)
  47. End Function
  48. Private Function DrawWing(s As Shape) As Shape
  49. Dim sp As SubPath, crv As Curve
  50. Dim x As Double, y As Double
  51. x = s.SizeWidth: y = s.SizeHeight
  52. s.Delete
  53. '// 绘制 Box 翅膀 Wing
  54. Set crv = Application.CreateCurve(ActiveDocument)
  55. Set sp = crv.CreateSubPath(0, 0)
  56. sp.AppendLineSegment 0, 4
  57. sp.AppendLineSegment 2, 6
  58. sp.AppendLineSegment 4, y - 2.5
  59. sp.AppendCurveSegment2 6.5, y, 4.1, y - 1.25, 5.1, y
  60. sp.AppendLineSegment x - 2, y
  61. sp.AppendLineSegment x - 2, 3
  62. sp.AppendLineSegment x, 0
  63. sp.Closed = True
  64. Set DrawWing = ActiveLayer.CreateCurve(crv)
  65. End Function
  66. Public Function Simple_box_one()
  67. ActiveDocument.Unit = cdrMillimeter
  68. l = 100: w = 50: h = 70: b = 15
  69. boxL = 2 * l + 2 * w + b
  70. boxH = h
  71. l1x = w
  72. l2x = w + l
  73. l3x = 2 * w + l
  74. l4x = 2 * (w + l)
  75. Set Rect = ActiveLayer.CreateRectangle(0, 0, boxL, boxH)
  76. Set sl1 = DrawLine(l1x, 0, l1x, h)
  77. Set sl2 = DrawLine(l2x, 0, l2x, h)
  78. Set sl3 = DrawLine(l3x, 0, l3x, h)
  79. Set sl4 = DrawLine(l4x, 0, l4x, h)
  80. End Function
  81. Public Function Simple_box_two()
  82. ActiveDocument.Unit = cdrMillimeter
  83. l = 100: w = 50: h = 70: b = 15
  84. boxL = 2 * l + 2 * w + b: boxH = h
  85. l1x = w: l2x = w + l: l3x = 2 * w + l: l4x = 2 * (w + l)
  86. Set mainRect = ActiveLayer.CreateRectangle(0, 0, boxL, boxH)
  87. Set topRect = ActiveLayer.CreateRectangle(0, 0, l, w)
  88. topRect.Move l1x, h
  89. Set bottomRect = ActiveLayer.CreateRectangle(0, 0, l, w)
  90. bottomRect.Move l3x, -w
  91. Set sl1 = DrawLine(l1x, 0, l1x, h)
  92. Set sl2 = DrawLine(l2x, 0, l2x, h)
  93. Set sl3 = DrawLine(l3x, 0, l3x, h)
  94. Set sl4 = DrawLine(l4x, 0, l4x, h)
  95. End Function
  96. Public Function Simple_3Deffect()
  97. Dim sr As ShapeRange ' 定义物件范围
  98. Set sr = ActiveSelectionRange ' 选择3个物件
  99. If sr.Count >= 3 Then
  100. ' // 先上下再左右排序
  101. sr.Sort " @shape1.Top * 100 - @shape1.Left > @shape2.Top * 100 - @shape2.Left"
  102. sr(1).Stretch 0.951, 0.525 ' 顶盖物件缩放修正和变形
  103. sr(1).Skew 41.7, 7#
  104. sr(2).Stretch 0.951, 0.937 ' 正面物件缩放修正和变形
  105. sr(2).Skew 0#, 7#
  106. sr(3).Stretch 0.468, 0.937 ' 侧面物件缩放修正和变形
  107. sr(3).Skew 0#, -45#
  108. End If
  109. End Function