Thanks everyone! :)

On Mon, Jul 9, 2012 at 5:08 PM, jo benayoun <[email protected]> wrote:

> for completeness...
> -- Jo
>
>
> def get_bbox_pos(obj):
>     pos = [0, 0, 0]
>     res = Application.GetBBox(obj)
>     xmin, ymin, zmin, xmax, ymax, zmax = res
>     x = (xmin + xmax) * 0.5
>     y = (ymin + ymax) * 0.5
>     z = (zmin + zmax) * 0.5
>     return (x, y, z)
>
>
> def marker_at_center(comp):
>     pos = get_bbox_pos(comp)
>
>     parent = comp.SubComponent.Parent3DObject
>     basename = parent.Name
>     if len(basename) > 3 and basename[3] == "_":
>         basename = basename[4:]
>
>     nil =parent.Model.AddNull("MARKER_" + basename)
>     kine = nil.Kinematics.Global
>     kine.posx = pos[0]
>     kine.posy = pos[1]
>     kine.posz = pos[2]
>
>     nil.shadow_icon = 4
>     nil.shadow_scaleX = 0.5
>     nil.shadow_scaleY = 0.5
>     nil.shadow_scaleZ = 0.5
>
>     return None
>
>
> def do_it():
>     selection = Application.Selection
>     if selection.Count > 0:
>         comp = selection(0)
>         marker_at_center(comp)
>     return None
>
>
> do_it()
>
>
>
>
> 2012/7/9 Vincent Ullmann <[email protected]>
>
>> For the Center i did a little Script some time ago....
>> Sadly it only works when the Object got no Transformations on it.
>> Also these RotationStuff may be incorrect
>>
>> To get a BoundingBox, you could try to modify this, so that it keeps the
>> lowest/highest X/Y/Z-Component and Outputs them
>> (See the CustomICE-Node-Example "Get BoundingBox", thats exactly the
>> thing i would do in jScript to get a BoundingBox)
>>
>>
>>
>> // Get Selection
>>
>> var oSel = selection(0);
>>
>> var oSelCtr = Sel_Center(oSel);
>>  var vVecX = oSelCtr[0];
>>  var vVecY = oSelCtr[1];
>> var vVecZ = oSelCtr[2];
>>  var vRotX = oSelCtr[3];
>> var vRotY = oSelCtr[4];
>>  var vRotZ = oSelCtr[5];
>>
>>
>> //
>> ------------------------------------------------------------------------
>> // Get Selection Center
>>
>> function Sel_Center(oSel)
>> {
>> var vAllVerts = 0;
>>  var vPosX = 0; var vPosY = 0; var vPosZ = 0;
>>  var vNrmX = 0; var vNrmY = 0; var vNrmZ = 0;
>>
>> var oSelType = oSel.Type;
>> switch (oSelType)
>> {
>>  // If Poly or Edge
>> case "polySubComponent":
>> case "edgeSubComponent":
>>  var vSubCompCount = oSel.SubComponent.ComponentCollection.Count;
>> for (i=0; i<vSubCompCount; i++)
>>  {
>> var vVertCount =
>> oSel.SubComponent.ComponentCollection.Item(i).Vertices.Count;
>>  for (j=0; j<vVertCount; j++)
>> {
>> var vAllVerts = vAllVerts + 1;
>>  var vPosX = vPosX +
>> oSel.SubComponent.ComponentCollection.Item(i).Vertices(j).Position.x;
>>  var vPosY = vPosY +
>> oSel.SubComponent.ComponentCollection.Item(i).Vertices(j).Position.y;
>>  var vPosZ = vPosZ +
>> oSel.SubComponent.ComponentCollection.Item(i).Vertices(j).Position.z;
>>  var vNrmX = vNrmX +
>> oSel.SubComponent.ComponentCollection.Item(i).Vertices(j).Normal.x;
>>  var vNrmY = vNrmY +
>> oSel.SubComponent.ComponentCollection.Item(i).Vertices(j).Normal.y;
>>  var vNrmZ = vNrmZ +
>> oSel.SubComponent.ComponentCollection.Item(i).Vertices(j).Normal.z;
>>  } // for j End
>> } // for i End
>> break; // Case End
>>
>> // If Vertex
>> case "pntSubComponent":
>> var vAllVerts = oSel.SubComponent.ComponentCollection.Count;
>>  for (i=0; i<vAllVerts; i++)
>> {
>> var vPosX = vPosX +
>> oSel.SubComponent.ComponentCollection.Item(i).Position.x;
>>  var vPosY = vPosY +
>> oSel.SubComponent.ComponentCollection.Item(i).Position.y;
>>  var vPosZ = vPosZ +
>> oSel.SubComponent.ComponentCollection.Item(i).Position.z;
>>  var vNrmX = vNrmX +
>> oSel.SubComponent.ComponentCollection.Item(i).Normal.x;
>>  var vNrmY = vNrmY +
>> oSel.SubComponent.ComponentCollection.Item(i).Normal.y;
>>  var vNrmZ = vNrmZ +
>> oSel.SubComponent.ComponentCollection.Item(i).Normal.z;
>>  } // for i End
>> break;
>>  //If Selection =/= Poly/Vertex/Edge
>> default:
>> var vAllVerts = 1;
>>  } //Switch End
>>
>> //Convert Normal-Direction to Rotation
>>  var vecWorldX = XSIMath.CreateVector3(); vecWorldX.Set (1,0,0);
>>  var vecWorldY = XSIMath.CreateVector3(); vecWorldY.Set (0,1,0);
>>  var vecWorldZ = XSIMath.CreateVector3(); vecWorldZ.Set (0,0,1);
>>
>> var vecNrmX = XSIMath.CreateVector3(); vecNrmX.Set ( vNrmX/vAllVerts,
>> vNrmY/vAllVerts, vNrmZ/vAllVerts);
>>  var vecNrmY = XSIMath.CreateVector3(); vecNrmY.Set ( 0, vNrmY/vAllVerts,
>> vNrmZ/vAllVerts);
>>  var vecNrmZ = XSIMath.CreateVector3(); vecNrmZ.Set ( 0, 0,
>> vNrmZ/vAllVerts);
>>  var vRotX = vecNrmX.Dot (vecWorldX);
>>  var vRotY = vecNrmY.Dot (vecWorldY);
>>  var vRotZ = vecNrmZ.Dot (vecWorldZ);
>>
>> LogMessage ("Position: X: " + vPosX/vAllVerts + " / Y: " +
>> vPosY/vAllVerts + " / Z: " + vPosZ/vAllVerts);
>>  LogMessage ("Rotation: X: " + vRotX + " / Y: " + vRotY + " / Z: " +
>> vRotZ);
>> return [vPosX/vAllVerts, vPosY/vAllVerts, vPosZ/vAllVerts, vRotX, vRotY,
>> vRotZ]
>> }
>> //
>> ------------------------------------------------------------------------
>>
>
>

Reply via email to