
! script name: vinvert.d/2dinvertbox
! var_topic: 2D invert boxed group of entities

!A
!A NAME:
!A
!A 	Box: 2D Duplicate	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of entities or a single entity to be
!A      inverted and the option of the original being deleted.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick the view that elements are to be
!B 		inverted in.
!B
!B 	REFERENCE POINT: Pick the point to be used as the reference for the
!B 		invert.
!B
!B 	INVERSION ANGLE: Enter the angle about which the entities should be
!B 		inverted.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: 2d invert boxed group ")

DIM Answer$[256]
DIM Destination$[256]
DIM Element$[256]
DIM Name$[256]
DIM Center$[256]
DIM Angle_var$[256]
DEG


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

stat= SetInputFormat("n4","")

Group=CreateGroup("TEMP")


Vnum= LastPickView
Stat=PickBox(Group,Vnum,WsPickPen)
IF ExitScript(Destination$) THEN Leave

IF NOT ValidGeometry(Group) THEN
        GOTO Start
ELSE
        IF NOT GroupCount(Group) THEN Start
END IF

Ref_point:E2=PickEntity("REFERENCE POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E2) THEN Ref_point
T= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E2,Center$)
Pc= ParameterReturnPt(E2,T,Pick_return)

Angle_ques:Angle=InputAngle("INVERSION ANGLE")
IF ExitScript(Destination$) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
	IF NOT ValidDependency(L1) THEN Angle_ques
        No_angle_var=0
        Stat= EntityNameCheck(L1,Angle_var$)
END IF
Stat= DeleteEntity(Pc)

Num_elements= GroupCount(Group)
Stat= GenerateVarName(WsVarRecordEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("INVERT: 2d invert mult ent")
Stat= SetRecDelLastExec
Egroup= CreateGroup("Picked Entities")

FOR I=1 TO Num_elements
RecordFunctionOff
        E1= GroupElement(Group,I)
        Stat= EntityNameCheck(E1,Element$)
	IF ValidDependency(E1,WsFalse) THEN 
		RecordFunctionOn
        	Stat= AddToGroup(Egroup,Element$)
		RecordFunctionOff
	END IF
NEXT I
RecordFunctionOn
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
IF No_angle_var THEN
	V1= FreeParameter("Angle",Angle)
        T1=AngleTransform(Pc,90,0,V1,WsWorkplaneVals)
ELSE
        T1=AngleTransform(Pc,90,0,Angle_var$,WsWorkplaneVals)
END IF
T2=InvertInPlane(T1)
G1=TransformGroup(Egroup,T2,"TEMP1")
Stat= AutoNameGroup(G1,Name$)
ActivateUndo
Stat= AdvanceUndoNumber("invert")
Stat= AddGroupToUndo(WsUBCreateMode,G1,0,WsTrue)
Stat=DeleteEntityList(G1,Egroup,T2,Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= DeleteEntity(Group)

GOTO Start

Leave: !
stat= SetInputFormat("n4","")
Stat= DeleteEntityList(Pc,Group,G1)

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

