
! script name: rotate.d/3drotdelcont
! 3dtopic: 3D rotate group of entities and delete original

!A
!A NAME:
!A
!A 	3D Rotate and Delete Group
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of entities or a single entity to be
!A 	rotated and the option of the original being deleted.
!A
!B INSTRUCTIONS:
!B
!B 	PICK GROUP TO BE ROTATED: Pick an element on the group to be rotated.
!B
!B 	REFERENCE POINT ABS X,Y,Z: Enter the X,Y,Z coordinates of the point
!B 		to be used as the reference for the rotate.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B	X AXIS ROTATION: Angular amount around the X Axis
!B
!B	Y AXIS ROTATION: Angular amount around the Y Axis
!B
!B	Z AXIS ROTATION: Angular amount around the Z Axis
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: 3d rotate and delete group ")

DIM Answer$[256]
DIM Destination$[256]
DEG

Start: !
ActivateUndo

stat= SetInputFormat("n4","")

C1=PickGroupEnt("PICK GROUP TO BE ROTATED")
IF ExitScript(Destination$) THEN Leave

IF NOT ValidGeometry(C1) THEN Start
Stat=Highlight(C1,WsPickPen,WsDirArrowOff)

Pt=XyzInput("REFERENCE POINT ",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

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

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

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

X=-XPointValue(Pt)
Y=-YPointValue(Pt)
Z=-ZPointValue(Pt)

Pr=PointXYZ(X,Y,Z)
Pz=PointXYZ(0,0,0)
T1=AngleTransform(Pr,0,0,0,WsWorkplaneVals)
T2=AngleTransform(Pz,Xangle,Yangle,Zangle,WsWorkplaneVals)
T3=AngleTransform(Pt,0,0,0,WsWorkplaneVals)

ActivateUndo
Stat= AdvanceUndoNumber("rotate")
Stat= AddGroupToUndo(WsUBModifyMode,C1,1,WsTrue)

T4=MultTransforms(T2,T1)
T5=MultTransforms(T3,T4)
Stat= EraseEntity(C1)
Stat=TransGroupTrans(C1,T5,0,1)

IF ValidGeometry(Pt) THEN Stat= DeleteEntity(Pt,WsTrue)
IF ValidGeometry(Pr) THEN Stat= DeleteEntity(Pr)
IF ValidGeometry(Pz) THEN Stat= DeleteEntity(Pz)

PlotAll
GOTO Start

Leave: !
stat= SetInputFormat("n4","")
IF ValidGeometry(Pt) THEN Stat= DeleteEntity(Pt)
IF ValidGeometry(Pr) THEN Stat= DeleteEntity(Pr)
IF ValidGeometry(Pz) THEN Stat= DeleteEntity(Pz)

IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
