ScriptSpot

Forum topic · General Scripting

Dynamic Dimension example

By barigazy · 2013-01-26

Description

I want to share this little snippet about interactive dimensions using transform_script controller.
This is the initial phase of script and need more improvements.

To do list:
1. Direction of the tip arowws (cone primitives) need to be always parallel with
Line Shape.
2.In the code i commented helpers creations.
#1 "rotHelper" (big red point helper) will be used like Master parent for translation and rotation.
#2 "pos1Helper" and "pos2Helper" (blue one) will be control the size of Line Shape.

I'd appreciate any good advice for the future upgrade.


(
txt = text alignment:2 pos:[0,0,0] size:10 wirecolor:yellow
addModifier txt (Shell innerAmount:.05 outerAmount:.05)
spl = splineShape showFrozenInGray:off wirecolor:yellow isFrozen:on render_renderable:on \
render_displayRenderMesh:on thickness:.3 side:8 render_threshold:60
addNewSpline spl
addKnot spl 1 #corner #line [-50,0,0]
addKnot spl 1 #corner #line [50,0,0]
updateShape spl ; animatevertex spl #all
--rotHelper = point name:(uniquename "rotHelper") Box:on axistripod:off centermarker:off cross:off size:50 wirecolor:red
--pos1Helper = point name:(uniquename "pos1Helper") pos:[-55,0,0] Box:off axistripod:off centermarker:off cross:on size:15 wirecolor:blue
--pos2Helper = point name:(uniquename "pos2Helper") pos:[55,0,0] Box:off axistripod:off centermarker:off cross:on size:15 wirecolor:blue
cone1 = cone height:5 radius1:1 radius2:0 heightsegs:1 capsegs:1 sides:16 pos:[-50,0,0] dir:[-1,0,0] wirecolor:yellow --parent:pos1Helper
cone2 = instance cone1 ; cone2.pos = cone1.pos * -1 ; cone2.dir = cone1.dir * -1 ; cone2.wirecolor = cone1.wirecolor ; --cone2.parent = pos2Helper

--text transform
ctrlTM = txt.transform.controller = transform_script()
ctrlTM.addTarget "c1" cone1[3][1]
ctrlTM.addTarget "c2" cone2[3][1]
ctrlTM.addNode "mst" txt
ctrlTM.addConstant "ang" 270
ctrlTM.addConstant "offs" 3
txt = "tm = matrixfromnormal (normalize (c2 - c1))\n"
txt += "tm.row4 = (c2 + c1)/2\n"
txt += "mst.text = units.formatValue ((formattedPrint (distance c1 c2) format:\"0.2f\") as float)\n"
txt += "tm = preTranslate (prerotateY tm ang) [0,offs,0]"
ctrlTM.script = txt

--live verts position_list
p3sV1 = spl[4][8][2].track = point3_script()
p3sV1.addTarget "c1" cone1[3][1]
p3sV1.addNode "mst" spl
p3sV1.script = "c1 * inverse mst.transform"
p3sV2 = spl[4][8][5].track = point3_script()
p3sV2.addTarget "c2" cone2[3][1]
p3sV2.addNode "mst" spl
p3sV2.script = "c2 * inverse mst.transform"
)