ScriptSpot

Forum topic · General Scripting

Create line between objects with controller

By titane357 · 2014-04-29

Description

Hello
I would like to simplify creation of a line between two picked object.
The created line is parented to the first picked object, add a look at targeted to the second picked object, and the line scale is linked to the distance between the two picked objects.
As usual I can do the beginning, but I can't do the end.... If anybody could help :-)

--------------------
obj1 = pickObject()
obj2 = pickObject rubberBand:obj1.pos

obj1n = obj1.name as string
obj2n = obj2.name as string

new_spline = splineShape ()
addNewSpline new_spline
addKnot new_spline 1 #corner #curve [0,0,0]
addKnot new_spline 1 #corner #curve [1,0,0]
updateshape new_spline

new_spline.pivot =[0,0,0]
new_spline.pos = obj1.pos
new_spline.parent = obj1

lookAtCon=lookAt_Constraint()
lookAtCon.appendTarget obj2 1
--lookAtCon.target_axisFlip=true
rotList=rotation_list()
new_spline.rotation.controller=rotList
rotList.available.controller=lookAtCon
new_spline.rotation.controller.LookAt_Constraint.controller.lookat_vector_length = 0

new_spline.scale.controller = scale_script ()
new_spline.scale.controller.script = "[1, distance " + obj1n + " " + obj2n + ",1]*2"

-------------------

Comments (5)

barigazy · 2014-04-29

Previous example shows method how to link knots at the center or two nodes.
The next example is similar but this time I used pivot position

delete objects
boxes = #( \
Box name:"B1" lengthsegs:1 widthsegs:1 heightsegs:1 length:10 width:10 height:10 pos:[50,0,0] wirecolor:red,
Box name:"B2" lengthsegs:1 widthsegs:1 heightsegs:1 length:10 width:10 height:10 pos:[-50,0,0] wirecolor:blue
)
new_spline = splineShape name:"Guide" wirecolor:yellow
addNewSpline new_spline
addKnot new_spline 1 #corner #curve boxes[1].center
addKnot new_spline 1 #corner #curve boxes[2].center
updateshape new_spline
animateVertex new_spline #all
knot1Ctrl = new_spline[4][8][2].track = point3_script()
knot1Ctrl.AddTarget "Box1pos" boxes[1][3][1].track
knot1Ctrl.script = "Box1pos"
knot2Ctrl = new_spline[4][8][5].track = point3_script()
knot2Ctrl.AddTarget "Box2pos" boxes[2][3][1].track
knot2Ctrl.script = "Box2pos"

titane357 · 2014-04-30

Thanks for help Barigazy, works fine.
I know that I have problem with array, now I know I have problems with controllers...
I finally succeed in what I wanted to do, with an object :
pick the first then the second "controller" then pick an object z up, 1 meter height.
-------------------------------------------
obj1 = pickObject()
obj2 = pickObject rubberBand:obj1.pos
new_spline = pickObject rubberBand:obj2.pos
new_spline.pos = [0,0,0]
obj1n = obj1.name
obj2n = obj2.name

new_spline.pivot =[0,0,0]
new_spline.pos = obj1.pos
new_spline.parent = obj1

lookAtCon=lookAt_Constraint()
lookAtCon.appendTarget obj2 1
lookAtCon.target_axis=2
--lookAtCon.target_axisFlip=true
rotList=rotation_list()
new_spline.rotation.controller=rotList
rotList.available.controller=lookAtCon
new_spline.rotation.controller.LookAt_Constraint.controller.lookat_vector_length = 0

new_spline.scale.controller = scale_script ()
xxx = "($"+ obj2n + ".pos - $" + obj1n + ".pos)"
new_spline.scale.controller.script = "[1,1,length " + xxx + "]"

barigazy · 2014-04-29

If you need explanation for the tracks take a look marked areas on image below

barigazy · 2014-04-29

Why don't you try something like this

delete objects
boxes = #( \
Box name:"B1" lengthsegs:1 widthsegs:1 heightsegs:1 length:10 width:10 height:10 pos:[50,0,0] wirecolor:red,
Box name:"B2" lengthsegs:1 widthsegs:1 heightsegs:1 length:10 width:10 height:10 pos:[-50,0,0] wirecolor:blue
)
new_spline = splineShape name:"Guide" wirecolor:yellow
addNewSpline new_spline
addKnot new_spline 1 #corner #curve boxes[1].center
addKnot new_spline 1 #corner #curve boxes[2].center
updateshape new_spline
animateVertex new_spline #all
knot1Ctrl = new_spline[4][8][2].track = point3_script()
knot1Ctrl.AddNode "Box1" boxes[1]
knot1Ctrl.script = "Box1.center"
knot2Ctrl = new_spline[4][8][5].track = point3_script()
knot2Ctrl.AddNode "Box2" boxes[2]
knot2Ctrl.script = "Box2.center"

spline vertex number

marcoslm · 2016-03-16

Hello,
I would like to know how to find the spline track information. On the image from Barigazy the spline1 vertex number [4][8][2] is showed on track view curve editor. But when I try to find this number, I don't what to do to show it.
Without this number I can't animate the vertices.
Any help?

Thank you

Marcos