I made this script in Maya a long time ago. It creates a curve (actually a straight line) that will go from the current camera to the selected locator (empty). I need the same thing in Blender but I have no idea on how to do this in Blender as the Blender commands are not the same as in Maya, obviously.
The steps are:
- get the location of the empty (A)
- get the location of the camera (B)
- create a curve from A to B
- set the origin at B
- scale the curve by 1000
- select the empty
Here’s the original code in Maya:
# Fires a curve from the camera to the selected object. By Robert Rioux. Inspired by NavKit by Laurent Taillefer. :-) import maya.cmds as cmds target = cmds.ls(sl=True) class rayProject(object): def __init__(self,*args): self.rayProjectWin = 'rayProject' if cmds.window(self.rayProjectWin, exists=True): cmds.deleteUI(self.rayProjectWin) self.buildWin() def buildWin(self,*args): self.rayProject = cmds.window(self.rayProjectWin, t="Ray Project", tlb = True, w=100, h=30, bgc= [0.4,0.4,0.4]) theRowLayout = cmds.rowColumnLayout(nc=1,columnWidth=(30,1), h=30) cmds.button(label="Fire!", width = 80, command = self.fire) cmds.setParent( theRowLayout ) cmds.showWindow(self.rayProjectWin) # Project the curve def fire(*args): target = cmds.ls(sl=True) if not target: cmds.error("Please select a locator") else: transform = maya.cmds.xform( target, q=True, ws=True, t=True ) pan = cmds.getPanel(wf=True) cam = cmds.modelPanel(pan, q=True, camera=True) transformCam = maya.cmds.xform( cam, q=True, ws=True, t=True ) cmds.curve (p=[(transformCam,transformCam,transformCam),(transform,transform,transform)], d=1) newCurve = cmds.ls(sl=True) cmds.xform (r=True, piv=(transformCam,transformCam,transformCam)) cmds.xform (s=(10,10,10)) cmds.select (target) rayProject()
Can anybody help me? Thanks.