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

!A
!A NAME:
!A
!A 	Rotate Move Body  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will rotate a solid body about the reference point 
!A 	and then move it to the destination point.
!A
!B INSTRUCTIONS:
!B
!B 	PICK BODY TO BE ROTATED: Pick the body to be rotated.
!B
!B 	ROTATION ANGLE: Enter the rotation angle.
!B
!B 	REFERENCE POINT: Input the reference point.
!B
!B 	DESTINATION POINT: Input the destination point.
!B
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: rotate move a body")

DIM Destination$[256]
DIM Answer$[256]
DIM Body$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Angle_var$[256]

ActivateUndo
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

Stat= GLPlotOn
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(Angle)
Angle=InputAngle("ROTATION ANGLE")
IF ExitScript(Destination$) THEN Leave
No_angle_var= LastVariableInput(Angle_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_angle_var THEN
        V1= FreeParameter("Angle",Angle)
ELSE
        V1= FreeParameter("Angle",Angle_var$)
END IF
Trans1=AngleTransform(Ps,0,0,0,WsWorkplaneVals)
Trans2= InverseTrans(Trans1)
Trans3=AngleTransform(Pe,0,0,V1,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
