Advertisement
Lucas_3D

Create Chevron Lines

Jan 17th, 2024 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. /*
  2. create_chevron_lines
  3. v1.00
  4. 240118
  5. should take top left of the bbox and bottom right corner and create a unit vector.
  6. the section moves along that unit vector from 1 coord to the other buy the chevron distance
  7. try make a series of dummys that occupy the point that the section will exist.
  8. v1.01
  9. 240119
  10. I changed from dealing with chevrons moving along a vector from top left to bottom right of the bbox
  11. Instead the section takes up the center point plus twice the diagonal bbox
  12. Then the section is moved in the objects local transform the chevron gap distance to acheive a regular gap
  13. v1.02
  14. 240920
  15. now works on multiple shapes and does more error checking.
  16. tries to be more optimal with the chevron padding.
  17. */
  18. (
  19. local chevron_gap = 3.0
  20. local chevron_angle = 0.0
  21.  
  22. fn clusterAttachShapes objArr _newName = --attaches and renames objects
  23. (
  24. local newName = (uniqueName (_newName+"-00"))
  25. j = 1
  26. count = objArr.count
  27. undo off
  28. (
  29. while objArr.count > 1 do
  30. (
  31. addandweld objArr[j] objArr[j+1] -1 --$Line001 $Line002 -1
  32. deleteItem objArr (j+1)
  33. j += 1
  34. if (j + 1) > objArr.count then j = 1
  35. )
  36. )
  37. objArr[1].name = newName
  38. select (getNodeByName newName)
  39. )
  40.  
  41. fn Knots_to_corner _spl =
  42. (
  43. for i = 1 to numKnots _spl do
  44. (
  45. setKnotType _spl 1 i #corner
  46. )
  47. updateShape _spl
  48. )
  49.  
  50. if (selection.count == 0) then
  51. (
  52. messagebox "You must select atleast 1 shape!"
  53. ) else
  54. (
  55. shapes_array = for i in selection where superclassof i == shape collect i
  56. for i in shapes_array do
  57. (
  58. max create mode
  59. convertTo i splineShape
  60. DisableSceneRedraw()
  61. if (numsplines i == 1) and (isClosed i 1) do with undo off
  62. (
  63. select i
  64. -- defining a shape to create chevrons within, this will use the selected spline in the future
  65. the_shape = i
  66. IsolateSelection.EnterIsolateSelectionMode()
  67.  
  68. -- make a poly version of the shape for use with the section tool
  69. the_shape_as_poly = copy the_shape
  70. addModifier the_shape_as_poly (Edit_Poly())
  71.  
  72. -- create the section
  73. the_section = section width:10 length:10
  74. -- take on the orientation of the shape
  75. the_section.transform = the_shape.transform
  76. --lay it down flat
  77. in coordsys local rotate the_section (angleaxis 90 [1,0,0])
  78. -- rotate it to the desired angle
  79. in coordsys local rotate the_section (angleaxis chevron_angle [0,1,0])
  80.  
  81. -- get the amount of required chevrons to be generated
  82. the_distance = (distance [the_shape.min.x, the_shape.max.y, 0] [the_shape.max.x, the_shape.min.y, 0])
  83. amount_of_chevrons = (the_distance * 1.5 / chevron_gap) as integer
  84.  
  85. -- set the first location of the section to create a chevron
  86. init_chevron_pos_obj = dummy pos:the_shape.center
  87. init_chevron_pos_obj.transform = the_shape.transform
  88. in coordsys local move init_chevron_pos_obj [0,the_distance,0]
  89. initial_chevron_position = init_chevron_pos_obj.pos
  90. delete init_chevron_pos_obj
  91.  
  92. -- create the chevron lines
  93. for i = 1 to amount_of_chevrons do
  94. (
  95. new_section = copy the_section
  96. new_section.pos = initial_chevron_position
  97. chevron_offset = chevron_gap * i as float
  98. in coordsys local move new_section ([0,0,chevron_offset])
  99. EnableSceneRedraw()
  100. max views redraw
  101. DisableSceneRedraw()
  102. new_chevron = convertToSplineShape new_section --SplineShape
  103. new_chevron.wireColor = color 253 152 0
  104. new_chevron.name = uniqueName "LM_temp_chevron-"
  105. )
  106. delete $Section*
  107. delete the_shape_as_poly
  108. clusterAttachShapes ($LM_temp_chevron* as array) "LM_chevron"
  109.  
  110. -- convert knots to corner type
  111. max modify mode
  112. subobjectLevel = 1
  113. actionMan.executeAction 0 "40021"
  114. weldSpline $ 0.001
  115. subobjectLevel = 0
  116. max create mode
  117. IsolateSelection.ExitIsolateSelectionMode()
  118. addModifier $ (Optimize_Spline reducedMinKnots:2 reduce_method:1)
  119. convertToSplineShape $
  120. $.pivot = $.center
  121.  
  122. gc lite:true
  123. )
  124. EnableSceneRedraw()
  125. )
  126. )
  127. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement