
! script name: vpktransform.d/vpk3drotmove
! var_solids: 3d rotate and move a body

!A
!A NAME:
!A
!A 	3D Rotate Move Body VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will rotate a solid body about a reference point and
!A 	then move the body so that the reference point coincides 
!A 	with the destination point.
!A
!A
!B INSTRUCTIONS:
!B
!B 	PICK BODY TO BE MOVED: Pick the body.
!B 		May be wire, sheet or solid.
!B
!B 	X AXIS ROTATION: X axis rotation angle about reference point.
!B
!B 	Y AXIS ROTATION: Y axis rotation angle about reference point.
!B
!B 	Z AXIS ROTATION: Z axis rotation angle about reference point.
!B
!B 	REFERENCE POINT: Input the reference point for the transformation.
!B
!B 	DESTINATION POINT: Input the destination point.
!B
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: 3D rotate and Move a body")

DIM Destination$[256]
DIM Answer$[256]
DIM Body$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Xangle_var$[256]
DIM Yangle_var$[256]
DIM Zangle_var$[256]

ActivateUndo

Stat= GLPlotOn
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
Pick_body:!
Pkbody= WPKCurrentBody
IF NOT WPKIsEntity(Pkbody) THEN
        Stat=SetInputFormat("n4","")
	E1=WPKPickEntity("PICK BODY TO BE MOVED")
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT WPKIsEntity(E1) THEN Pick_body
        Pkbody= WPKParentBody(E1)
END IF
Stat= EntityNameCheck(Pkbody,Body$)


Stat=SetInputFormat("n4="," ")
Stat=SetEqualsValue(Xangle)
Xangle=GetValue("X AXIS ROTATION  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_xangle_var= LastVariableInput(Xangle_var$)

Stat=SetEqualsValue(Yangle)
Yangle=GetValue("Y AXIS ROTATION  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_yangle_var= LastVariableInput(Yangle_var$)

Stat=SetEqualsValue(Zangle)
Zangle=GetValue("Z AXIS ROTATION  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_zangle_var= LastVariableInput(Zangle_var$)

Pick_ref:Stat=SetInputFormat("n4=","")
Ps=XyzInput("REFERENCE POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ps) THEN Pick_ref
E1= LastPickEnt
Para1= LastPickPara
Pick_return1= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Ps)
        Stat= EntityNameCheck(E1,Point1$)
        Ps_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Point1$)
        Ps_created= WsFalse
END IF
Stat=SetLastPoint(Ps)

Dest_point:Stat=SetInputFormat("n4=","")
Pe=XyzInput("DESTINATION POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pe) THEN Dest_point
E2= LastPickEnt
Para2= LastPickPara
Pick_return2= CurrPickReturn
IF NOT ValidDependency(E2) THEN
        E2= CopyEntity(Pe)
        Stat= EntityNameCheck(E2,Point2$)
        Pe_created= WsTrue
ELSE
        Stat= EntityNameCheck(E2,Point2$)
        Pe_created= WsFalse
END IF
Stat=SetLastPoint(Pe)
Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)


WPKClearErrorFlag
RecordFunctionOn
Stat= RecordDescr("TRANSFORM: rotate move body")
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,Para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,Para2,WsGeomCenter)
END SELECT
IF No_xangle_var THEN
        V1= FreeParameter("X angle",Xangle)
ELSE
        V1= FreeParameter("X angle",Xangle_var$)
END IF
IF No_yangle_var THEN
        V2= FreeParameter("Y angle",Yangle)
ELSE
        V2= FreeParameter("Y angle",Yangle_var$)
END IF
IF No_zangle_var THEN
        V3= FreeParameter("Z angle",Zangle)
ELSE
        V3= FreeParameter("Z angle",Zangle_var$)
END IF
Trans1=AngleTransform(Ps,0,0,0,WsWorkplaneVals)
Trans2= InverseTrans(Trans1)
Trans3=AngleTransform(Pe,V1,V2,V3,WsWorkplaneVals)
Trans4= MultTransforms(Trans3,Trans2)
Stat=WPKTransformBody(Body$,Trans4)
Stat= DeleteEntityList(Ps,Pe,Trans1,Trans2,Trans3,Trans4)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("rotate move body")
IF Ps_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point1$)
IF Pe_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point2$)
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck
GOTO Pick_body



Leave:!
Stat= DeleteEntityList(Ps,Pe,Trans1,Trans2,Trans3,Trans4)
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
