
! script name: vinvert.d/2dinvertent
! var_topic: 2D invert single entity

!A
!A NAME:
!A
!A 	Single Element: 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 	PICK ELEMENT TO BE INVERTED: Pick the element to be inverted.
!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

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

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","")
E1= PickEntity("PICK ELEMENT TO BE INVERTED",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Start
Stat= EntityNameCheck(E1,Element$)

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)


Etype= EntityType(E1)
Stat= GenerateVarName(Etype,Name$)
RecordFunctionOn
Stat= RecordDescr("INVERT: 2d invert ent")
Stat= SetRecDelLastExec
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)
E2=TransformEntity(Element$,T2)
Stat= NameEntity(E2,Name$)
Stat= DeleteEntityList(Pc,T1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("invert entity")
Stat= AddItemToUndo(WsUBCreateMode,E2)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start

Leave: !
stat= SetInputFormat("n4","")
Stat= DeleteEntity(Pc)

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

