
! script name: vmove.d/3drptmovemcont
! var_topic: 3D move multiple contours by reference points

!A
!A NAME:
!A
!A 	3D Reference	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows multiple contours to be moved.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOURS TO BE MOVED, Proceed: Pick one
!B 		of the elements to be moved.  The question will repeat until
!B 		"Proceed" is answered.  All elements picked will then be moved.
!B
!B 	REFERENCE POINT: Pick the point to be used as the reference for
!B 		the move.
!B
!B 	DESTINATION POINT: Pick the point to be used as the destination
!B 		for the move.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: 3d reference")

DIM Answer$[256]
DIM Destination$[256]
DIM Which$[16]
DIM Extras$[64]
DIM Contour$[256]
DIM Name$[256]
DIM Point1$[256]
DIM Point2$[256]
DEG


Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Start: !
ActivateUndo

stat= SetInputFormat("n4","")

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

LOOP
        stat= SetInputFormat("a1",",P,B,")
Pick_ent:Contour= PickGroupEnt("PICK CONTOURS TO BE MOVED"&Extras$,0,Answer$)
        IF ExitScript(Destination$) THEN Leave
        Stat=SetInputFormat("n4"," ")
        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(Contour) THEN
                IF NOT ValidDependency(Contour) THEN Pick_ent
		IF IsEntityDependent(Contour)= WsFalse THEN
                   stat= SetInputFormat("a99","")
                   Stat= GetValue("NOT A VARIATIONAL CONTOUR, Proceed ",Answer$)
                   IF ExitScript(Destination$) THEN Leave
                   GOTO Pick_ent
                END IF
                        N1= ElementGrpNum(Group,Contour)
                        IF NOT N1 THEN Stat=AddToGroup(Group,Contour)
                        Extras$=", Backup , Proceed "
                        Stat= SetSelectedFlag(Contour,WsTrue)
                        Stat= PlotEntity(Contour)
                END IF
        END IF

END LOOP

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

Ref_pt:P1=PickEntity("REFERENCE POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(P1) THEN Ref_pt
T1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(P1,Point1$)
Ps= ParameterReturnPt(P1,T1,Pick_return1)

Which$= "FIRST"

Dest_pt:!
Stat=SetLastPoint(Ps)
P2=PickEntity(Which$&"  DESTINATION POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(P2) THEN Dest_pt
T2= LastPickPara
Pick_return2= CurrPickReturn
Stat= EntityNameCheck(P2,Point2$)
Pe= ParameterReturnPt(P2,T2,Pick_return2)
Stat=SetLastPoint(Pe)

Stat= DeleteEntityList(Ps,Pe)

ActivateUndo
Stat= AdvanceUndoNumber("move contours")
Stat= AddGroupToUndo(WsUBModifyMode,Group,0,WsTrue)

Num_elements= GroupCount(Group)
Stat= GenerateVarName(WsVarRecordEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("MOVE: ref move multi contours")
Cgroup= CreateGroup("Picked Contours")
FOR I=1 TO Num_elements
RecordFunctionOff
        Contour= GroupElement(Group,I)
        Stat= EntityNameCheck(Contour,Contour$)
        IF ValidDependency(Contour) THEN
                RecordFunctionOn
                Stat= AddToGroup(Cgroup,Contour$)
                RecordFunctionOff
        END IF
NEXT I
RecordFunctionOn
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,T1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,T2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,T2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,T2,WsGeomCenter)
END SELECT
Move_vector= VectorTwoPts(Ps,Pe)
Trans=AngleTransform(Move_vector,0,0,0,WsWorkplaneVals)
Stat=TransGroupTrans(Cgroup,Trans,WsTrue,1)
RecordFunctionOff
Stat= SetSelectedFlag(Cgroup,WsFalse)
RecordFunctionOn
Stat= DeleteEntityList(Cgroup,Ps,Pe,Move_vector)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord


Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat= DeleteEntityList(Group,Ps,Pe,Move_vector)
GOTO Start

Leave: !
stat= SetInputFormat("n4","")
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat= DeleteEntityList(Group,Ps,Pe,Move_vector)

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

