
! script name: rotate.d/3drotateshiftcont
! 3dtopic: 3D rotate and shift group of entities

!A
!A NAME:
!A
!A 	3D Rotate Shift Group
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of entities or a single entity to be
!A 	rotated and shifted 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
!B 	NUMBER OF TIMES: Enter the number of times the rotation process
!B 		should be repeated.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: 3d rotate 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

Xmove=GetValue("X INCREMENT ")
IF ExitScript(Destination$) THEN Leave

Ymove=GetValue("Y INCREMENT ")
IF ExitScript(Destination$) THEN Leave

Zmove=GetValue("Z INCREMENT ")
IF ExitScript(Destination$) THEN Leave


Stat=SetEqualsValue(1)
Stat=SetInputFormat("n0=","")
Number=GetValue("NUMBER OF TIMES",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Number=0 THEN Start

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")

X1= XpointValue(Pt)
Y1= YpointValue(Pt)
Z1= ZpointValue(Pt)

T4=T2
FOR I=1 TO Number
	Pt2=PointXYZ(X1+I*Xmove,Y1+I*Ymove,Z1+I*Zmove)
	T3=AngleTransform(Pt2,0,0,0,WsWorkplaneVals)
	stat=DeleteEntity(Pt2)

	T5=MultTransforms(T4,T1)
	T6=MultTransforms(T3,T5)
	PlotOff
	C2= CopyGroup(C1)
	PlotOn
	Stat=TransGroupTrans(C2,T6,0,1)
	Stat=AutoNumber(C2)
	Stat=DeleteEntity(T5)
	T7=MultTransforms(T2,T4)
	IF I>1 THEN Stat=DeleteEntity(T4)
	T4=T7
	Stat= AddGroupToUndo(WsUBCreateMode,C2,1,WsTrue)
NEXT I

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

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 ValidGeometry(Group) THEN Stat= DeleteEntity(Group)
IF ValidGeometry(G1) THEN Stat= DeleteEntity(G1)


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