title: MaxScript for picking an object name in 3ds Max
body: <p>Hello fellow Stack Overflow members! First of all, thanks for spending your time reading this question.</p>
  
  <p>I'm learning Maxscript so I can do some quick and sofisticated facial rig.
  My script is 99% done. The only problem is that right now the script has hard coded the name of the target object to be rigged ("MYOBJECT" in the code bellow). Instead of having to right down the name of the object in the MaxScript, I would like to create a function that will open a dialog window asking me to click in the target face abject, then after the user clicks in the target object, my code would do the job that it's already able to do, but using the selected object name instead of a hard coded name.</p>
  
  <p>My code is bellow. Thank you very much for your help!</p>
  
  <pre><code>/*
  Script wrote by RDlady: 
  This script was created following the example from
  Paul Neale's tutorial class: https://youtu.be/SKomaUCHAko
  Comments and little modifications added by RDlady.
  
  */
  
  struct facialBoneHelpers (
  
  targetNode=undefined,
  controlSize=10,
  
  fn makeControl hit= (
  
      --If the user clicks somewhere, do the code bellow
      if hit!=undefined do (
          print hit.pos
          print hit.dir
  
          --Creates the first helper, the root one (red)
          pt=point box:true cross:false axisTripod:true centerMarker:false size:(controlSize/2) wireColor:red name:(uniqueName "PT_ControlRoot)
          Zv=hit.Dir
          Yv=[0,0,1]
          Xv=normalize(cross Yv Zv)
          Yv=normalize(cross Zv Xv)
          pt.transform=matrix3 Xv Yv Zv hit.pos
  
          --Creates the second helper (green, bigger then the first), which will have the first one as parent
          pt2=point box:true cross:false axisTripod:true centerMarker:false size:(controlSize) wireColor:green name:(uniqueName "PT_ControlPos")
          pt2.transform=pt.transform
          pt2.parent=pt
  
          --Creates an outer circle connector (blue) that will have the second helper as parent
          cnt=circle radius:(controlSize) wireColor:blue name:(uniqueName "CNT_Face")
          cnt.transform=pt.transform
          cnt.parent=pt2
  
          --Converts the circle to a spline, and moves the gizmo out a little bit, so it can be handled more easily
          --First, creates a xForm modifier
          xf=xForm()
          --adds the created modifier to the circle connector
          addModifier cnt xf
          --defines the Z position of the gizmo of the modifier as the control size, moving it outside
          xf.gizmo.pos.z=controlSize
          --Finally converts the circle to a spline
          convertToSplineShape cnt
  
      )
  
  
  
  ),
  
  fun runTool= (
  
      tool mouseHit (
          on mousePoint clickNo do (
              if clickNo&gt;1 do (
  
                  r=(mapScreenToWorldRay mouse.pos)
                  hit=intersectRay targetNode r
                  makeControl hit
  
                  --Creates a mirror helper
                  if queryBox "Do tou want to make a mirror control" title:"Set mirror" do (
                      oppositePos = targetNode(ray(r.pos*[-1,1,1])(r.dir*[-1,1,1]))
                      hit=intersectRay oppositePos
                      makeControl hit
  
                  )
  
  
              )
  
  
          )
  
      )
      startTool mouseHit  
  )
  
  
  )
  facialBoneHelpers=facialBoneHelpers()
  facialBoneHelpers.targetNode=MYOBJECT
  facialBoneHelpers.runTool()
  </code></pre>