/* This script will help the user in creating a precise line with specific X Y Z angles and length. After creating the line shape the user can change the length of the last created line anytime, As long as the dialog is still opened. Script created by Miled Rizk e-mail: miledrizk@gmail.com YouTube Channel: http://www.youtube.com/c/MiledRizk */ macroscript ParametricLine ButtonText: "Parametric Line" category: "MiRi-Tools" ( try destroydialog lineparameters catch() rollout lineparameters "Parametric Line Parameters" ( local spl_shape = "" --This variable will hold the current line shape local current_shape = "" --This variable will be used as a temporary pointer to the current line shape in case the user cancelled the line creation after clicking the button, --and, at the same time, there is a created line already in the scene. In this case, the spl_shape variable will retake the current line shape from this variable. fn rotateline lshape x y z = --This function will rotate the line shape. It takes 3 arguments: the X, Y, and Z angles ( lshape.rotation.x_rotation = x lshape.rotation.y_rotation = y lshape.rotation.z_rotation = z )--end fn rotateline fn drawLineShape firstpt len = ( --This function will create the line shape. It takes two arguments: the picked point coordinates and the line length spl_shape = splineshape() addnewspline spl_shape addknot spl_shape 1 #corner #line firstpt addknot spl_shape 1 #corner #line (firstpt + [len, 0, 0]) spl_shape.pivot = firstpt spl_shape.wirecolor = color 255 0 0 updateshape spl_shape spl_shape.name = uniquename "Param_Line_" spl_shape )--end fn Drawlineshape Group "Line Creation" ( Button createline "Create Line" Tooltip: "Click To Place A Line" width: 170 height: 40 )--end creation group Group "Line Length" ( Spinner linelength "Length:" type: #WorldUnits range: [-9999.9999, 9999.9999, 1.0] Scale: 0.01 Tooltip: "Controls The length Of The Line Shape" )--end line length group Group "New Line Orietation" ( Spinner x_angle "X-Angle:" Type: #Float range: [-360.00, 360.00, 0.00] Scale: 0.01 Tooltip: "Defines The Initial X Angle Of The New Line Shape. It Doesn't Affect The Already Created Line" Spinner y_angle "Y-Angle:" Type: #Float range: [-360.00, 360.00, 0.00] Scale: 0.01 Tooltip: "Defines The Initial Y Angle Of The New Line Shape. It Doesn't Affect The Already Created Line" Spinner z_angle "Z-Angle:" Type: #Float range: [-360.00, 360.00, 0.00] Scale: 0.01 Tooltip: "Defines The Initial Z Angle Of The New Line Shape. It Doesn't Affect The Already Created Line" )--end new line orientation On createline pressed do ( current_shape = spl_shape spl_shape = "" picked_pt = pickpoint snap: #3D if picked_pt != #escape do ( if picked_pt != #rightclick then ( if picked_pt != undefined do ( spl_shape = "" Undo On ( spl_shape = drawLineShape picked_pt linelength.value rotateline spl_shape x_angle.value -y_angle.value z_angle.value select spl_shape )--end undo )--end if )--end if else ( spl_shape = current_shape )--end else )--end if )--end on createline On linelength changed new_val do ( if (isvalidnode spl_shape) and (spl_shape.ishidden == False) do ( if spl_shape.isselected do ( x = spl_shape.rotation.x_rotation y = spl_shape.rotation.y_rotation z = spl_shape.rotation.z_rotation Undo On ( deselect objects max create mode old_pivot = spl_shape.pivot delete spl_shape spl_shape = DrawLineShape old_pivot new_val rotateline spl_shape x y z select spl_shape )--end undo ) )--end if )--end on linelength )--end rollout createdialog lineparameters 230 213 )--end macroscript