May 12, 2003
at 12:00 pm /
#10177
hi
This is a script that pretends to shift the rotation point of an object to a location specified by the average of the points selected before running the script.
It really just moves the group origin to that location, so if the object has been reoriented at any stage the script will shift it it a bit, so you’ll have to move it back. andnbsp;Maybe someone has done this better than me already.
Save your work. andnbsp;Don’t blame me. andnbsp;Code follows.
George
script starts
Language = VBScript
‘*********************************************************************************
‘ Purpose: select a rotation point on the object
‘ George Jenner. andnbsp;version 1 May 2003
‘ Select points on the object before running script
‘ Script moves the Group position to the average of the ‘selected point locations
‘ Group orientation is ignored – if object has already been ‘rotated it will be shifted
‘ though the rotation point will be selected OK. andnbsp;
‘*********************************************************************************
‘Option Explicit andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;’require variable declarations
Sub Main (3DCApp)
andnbsp; andnbsp;Dim Scene
andnbsp; andnbsp;Dim ActivePointCount
andnbsp; andnbsp;Dim Group
andnbsp; andnbsp;Dim Object
andnbsp; andnbsp;Dim gx,gy,gz andnbsp; ‘the group coordinates
andnbsp; andnbsp;Dim px,py,pz andnbsp; ‘the point coordinates of rotation point andnbsp; andnbsp;
andnbsp; andnbsp;Dim px1,py1,pz1 andnbsp;’ the coordinates of the object
andnbsp; andnbsp;Dim NumPoints andnbsp; ‘the number of points in the object
andnbsp; andnbsp;Dim Counter, ActiveCounter
andnbsp; andnbsp; andnbsp;’get the scene
andnbsp; andnbsp;Set Scene = 3DCApp.GetActiveScene
andnbsp; andnbsp;’get the active object count
andnbsp; andnbsp;ActivePointCount = Scene.GetActivePointCount
andnbsp; andnbsp;’only proceed if there is an active object
andnbsp; andnbsp;If ActivePointCount [ 1 Then
andnbsp; andnbsp; andnbsp; andnbsp;MsgBox andquot;Please select at least one point you git.andquot;
andnbsp; andnbsp;Else
andnbsp; andnbsp; andnbsp;GoForIt= msgbox (andquot;Warning- If you’ve rotated _ yourobject already it will be shiftedandquot;,VBOKCancel)
andnbsp; andnbsp; andnbsp;if GoForIt=1 then
andnbsp; andnbsp; andnbsp; ‘get the active object
andnbsp; andnbsp; andnbsp; andnbsp;Set Object = Scene.GetActiveObject(0)
andnbsp; andnbsp; andnbsp; andnbsp;Set Group = Object.GetParentGroup
andnbsp; andnbsp; andnbsp; andnbsp;Group.GetPosition nothing,gx,gy,gz
andnbsp; andnbsp; andnbsp; andnbsp;’why don’t we average the active points?
andnbsp; andnbsp; andnbsp; andnbsp;Avepx=0
andnbsp; andnbsp; andnbsp; andnbsp;Avepy=0
andnbsp; andnbsp; andnbsp; andnbsp;Avepz=0
andnbsp; andnbsp; andnbsp; andnbsp;for ActiveCount=0 to ActivePointCount-1
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;FPoint = Scene.GetActivePoint(ActiveCount)
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Object.GetPoint FPoint, px,py,pz
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Avepx=Avepx+px
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Avepy=Avepy+py
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Avepz=Avepz+pz
andnbsp; andnbsp; andnbsp; andnbsp;next
andnbsp; andnbsp; andnbsp; andnbsp;’used px etc later in script so make them the aveages
andnbsp; andnbsp; andnbsp; andnbsp;px=Avepx/ActivePointCount
andnbsp; andnbsp; andnbsp; andnbsp;py=Avepy/ActivePointCount
andnbsp; andnbsp; andnbsp; andnbsp;pz=Avepz/ActivePointCount
andnbsp; andnbsp; andnbsp; andnbsp;’now shift the objects points
andnbsp; andnbsp; andnbsp; andnbsp;NumPoints=Object.GetPointCount()
andnbsp; andnbsp; andnbsp;
andnbsp; andnbsp; andnbsp; andnbsp;’what do we have to do?
andnbsp; andnbsp; andnbsp; andnbsp;’ Group position becomes old point position
andnbsp; andnbsp; andnbsp; andnbsp;’ Point positions have to become andnbsp;Old Point minus New Group
andnbsp; andnbsp; andnbsp; andnbsp;’ So first go through all points – pxnew:=pxold-gxold
andnbsp; andnbsp; andnbsp; andnbsp;’ then change group – gxnew:=px
andnbsp; andnbsp; andnbsp; andnbsp;’First shift the group
andnbsp; andnbsp; andnbsp; Group.SetPosition Nothing,0,gx+px,gy+py,gz+pz andnbsp;
andnbsp; andnbsp; andnbsp; ‘And now the points to compensate andnbsp;
andnbsp; andnbsp; andnbsp; For Counter = 0 to NumPoints-1
andnbsp; andnbsp; andnbsp; andnbsp; Object.GetPoint Counter,px1,py1,pz1
andnbsp; andnbsp; andnbsp; andnbsp; ‘something weird happening with assignments – try ‘an intermediate
andnbsp; andnbsp; andnbsp; andnbsp; newx=px1-px
andnbsp; andnbsp; andnbsp; andnbsp; newy=py1-py
andnbsp; andnbsp; andnbsp; andnbsp; newz=pz1-pz
andnbsp; andnbsp; andnbsp; andnbsp; ‘ahh that’s better
andnbsp; andnbsp; andnbsp; andnbsp; Object.SetPoint Counter,newx, newy, newz
andnbsp; andnbsp; andnbsp; Next
andnbsp; andnbsp; andnbsp; Object.WriteScriptOperationLayer() andnbsp;
andnbsp; andnbsp;end if andnbsp;’they want to do it (GoForIt)
andnbsp; end if andnbsp; andnbsp;’point selected
End Sub
–script ends—