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

!A
!A NAME:
!A
!A 	2D 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: Enter the X,Y coordinates of the point
!B 		to be used as the reference for the rotate.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	ROTATION ANGLE: Enter the angular amount the entities should be
!B 		rotated.
!B
!# see also - points.d/xyzinput.hlp

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

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

Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Start: !
ActivateUndo

Group=CreateGroup("TEMP")
Extras$= ""

LOOP
        stat= SetInputFormat("a1",",P,B,")
        C1=PickGroupEnt("PICK GROUP TO BE ROTATED"&Extras$,0,Answer$)
        IF ExitScript(Destination$) THEN Leave
        EXIT IF Answer$= "P"
        IF Answer$="B" THEN
                Num1=GroupCount(Group)
                C1=GroupElement(Group,Num1)
                IF Num1 THEN Stat= RemoveFromGrp(Group,Num1)
		Stat= SetSelectedFlag(C1,WsFalse)
                Stat= PlotEntity(C1)
                IF Num1=1 THEN Extras$= ""
        ELSE
                IF ValidGeometry(C1) THEN
                        N1= ElementGrpNum(Group,C1)
                        IF NOT N1 THEN
                                Stat=AddToGroup(Group,C1)
                        END IF
                        Extras$=", Backup , Proceed "
			Stat= SetSelectedFlag(C1,WsTrue)
                	Stat= PlotEntity(C1)
                END IF
        END IF

END LOOP

stat= SetInputFormat("n4","")

IF NOT ValidGeometry(Group) THEN
        GOTO Start
END IF
IF NOT GroupCount(Group) THEN 
	Stat= DeleteEntity(Group)
	GOTO Start
END IF


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

Stat=SetInputFormat("n4="," ")
Stat=SetEqualsValue(Angle)
Angle=InputAngle("ROTATION ANGLE")
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Stat= AdvanceUndoNumber("rotate")
Stat= SetSelectedFlag(Group,WsFalse)
Num1= GroupCount(Group)
FOR J= 1 TO Num1
        C1= GroupElement(Group,J)
	Stat= EraseEntity(C1)
	Stat= AddGroupToUndo(WsUBModifyMode,C1,1,WsTrue)
	Rot_trans= PlaneRotateTrans(Pt,Angle)
        Stat=TransGroupTrans(C1,Rot_trans)
NEXT J
Stat= DeleteEntity(Pt,WsTrue)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)

GOTO Start

Leave: !
stat= SetInputFormat("n4","")
Stat= DeleteEntity(Pt)
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)

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