
! script name: vpktransform.d/vpkinvertcopy
! var_solids: invert a copy of a body  

!A
!A NAME:
!A
!A 	Invert Copy Body  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script inverts a copy of a body about a line at an angle without
!A 	making a copy.
!A
!B INSTRUCTIONS:
!B
!B 	PICK BODY TO BE INVERTED: Pick the body.
!B
!B 	REFERENCE POINT: Input the reference point.
!B
!B 	INVERSION ANGLE: Enter the angle of the line
!B 		through the reference point for the inversion.
!B
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: Invert a body")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Body$[256]
DIM Point$[256]
DIM Angle_var$[256]

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


Stat= GLPlotOn
Pick_body:!
Pkbody= WPKCurrentBody
IF NOT WPKIsEntity(Pkbody) THEN
        Stat=SetInputFormat("n4","")
	E1=WPKPickEntity("PICK BODY TO BE INVERTED")
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT WPKIsEntity(E1) THEN Pick_body
        Pkbody= WPKParentBody(E1)
END IF
Stat= EntityNameCheck(Pkbody,Body$)

Pick_ref:Stat=SetInputFormat("n4=","")
Pc=XyzInput("REFERENCE POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN Pick_ref
E1= LastPickEnt
Pick_para= LastPickPara
Pick_return= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Pc)
        Stat= EntityNameCheck(E1,Point$)
        Pc_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Point$)
        Pc_created= WsFalse
END IF
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)

stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Angle)
Angle=InputAngle("INVERSION ANGLE")
IF ExitScript(Destination$) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)

WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("TRANSFORM: invert copy body")
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Point$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Point$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Point$,Pick_para,WsGeomCenter)
END SELECT
IF No_angle_var THEN
        V1= FreeParameter("Angle",Angle)
ELSE
        V1= FreeParameter("Angle",Angle_var$)
END IF
Trans1=AngleTransform(Pc,90,0,V1,WsWorkplaneVals)
Trans2=InvertInPlane(Trans1)
E1=WPKTransCopyBody(Body$,Trans2)
Stat= WPKNameBody(E1,Name$)
Stat= WPKSetBodyParent(E1)
Stat= DeleteEntityList(Pc,Trans1,Trans2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("invert copy body")
IF Pc_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point$)
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck
GOTO Pick_body

Leave:!
Stat= DeleteEntityList(Pc,Trans1,Trans2)
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
