
! script name: vmove.d/3drptmovemulti
! var_topic: 3d absolute move picked entities

!A
!A NAME:
!A
!A 	3D Reference	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A      This script allows picked entities to be moved
!A
!B INSTRUCTIONS:
!B
!B	PICK ELEMENTS TO BE MOVED: Pick the elements
!B 		to be moved.
!B
!B	REFERENCE POINT: Pick the point to be used
!B 		as the reference for the move.
!B
!B	DESTINATION POINT: Pick the point to be used
!B 		as the destination for the move.
!B
!# see also - points.d/xyzinput.hlp

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

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Element$[256]
DIM Extras$[256]
DEG


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

Start: !
ActivateUndo
Stat=SetPickMask(WsPickAll)
Active_workplane=0
Work=CurrentWorkplane
IF ValidGeometry(Work) THEN Active_workplane=1

stat= SetInputFormat("n4","")
Group=CreateGroup("TEMP")
Extras$= ""
LOOP
        stat= SetInputFormat("a1",",P,B,")
        E1= PickEntity("PICK ELEMENTS TO BE MOVED"&Extras$,Answer$)
        IF ExitScript(Destination$) THEN Leave
        Stat=SetInputFormat("n4"," ")
        EXIT IF Answer$= "P"
        IF Answer$="B" THEN
                Num1=GroupCount(Group)
                E1=GroupElement(Group,Num1)
                IF Num1 THEN Stat= RemoveFromGrp(Group,Num1)
                Stat= SetSelectedFlag(E1,WsFalse)
                Stat= PlotEntity(E1)
                IF Num1=1 THEN Extras$= ""
        ELSE
                IF ValidGeometry(E1) THEN
                        IF ValidGeometry(E1) THEN
                           IF IsEntityDependent(E1)= WsTrue THEN
                                IF ValidDependency(E1) THEN
                                   Stat=AppendToGroup(Group,E1)
                                   Stat= SetSelectedFlag(E1,WsTrue)
                                   Extras$=", Backup , Proceed "
                                END IF
                            END IF
                        END IF
                        Stat= PlotEntity(E1)
                END IF
        END IF

END LOOP
IF NOT ValidGeometry(Group) THEN Start


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

Dest_pt:P2=PickEntity("DESTINATION POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(P2) THEN Dest_pt
Para2= LastPickPara
Pick_return2= CurrPickReturn
Stat= EntityNameCheck(P2,Point2$)
Pdest= ParameterReturnPt(P2,Para2,Pick_return2)


Rotate_angle= 0

Make_record:!
Stat= EraseEntity(Group)
Stat= SetSelectedFlag(Group,WsFalse)

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

Num_elements= GroupCount(Group)
RecordFunctionOn
Stat= RecordDescr("MOVE: ref move entities")
Cgroup= CreateGroup("Picked Entities")
FOR I=1 TO Num_elements
RecordFunctionOff
        E1= GroupElement(Group,I)
        IF ValidGeometry(E1) THEN
              Stat= EntityNameCheck(E1,Element$)
              RecordFunctionOn
              Stat= AddToGroup(Cgroup,Element$)
              RecordFunctionOff
	END IF
NEXT I
RecordFunctionOn
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,Para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,Para2,WsGeomCenter)
END SELECT
Ps1= ProjectEntity(Ps,0.0)
Pe1= ProjectEntity(Pe,0.0)
Work= CurrentWorkplane
L1= WorkplaneAxisLine(Work,Ps1)
Stat=SetWorkplane(0)
Pm= VectorTwoPts(Ps1,Pe1)
Trans1=AngleTransform(Pm,0,0,0,WsWorkplaneVals)
V1= FreeParameter("Rotate angle",Rotate_angle)
Trans2= RotAboutAxisTrans(L1,V1)
Trans3=MultTransforms(Trans1,Trans2)
Stat=TransGroupTrans(Cgroup,Trans3,WsFalse,WsTrue)
Stat=Unlink(Cgroup)
Stat= DeleteEntityList(Cgroup,Pm,Ps,Pe,Ps1,Pe1,L1,Trans1,Trans2)
Stat=SetWorkplane(Work)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord


Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= PlotEntity(Group)
Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
Stat= DeleteEntityList(Group,Pm,Pref,Pdest,Axis_line)
IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF
Stat=SetPickMask(WsPickAll)
GOTO Start


Leave: !
Stat=SetPickMask(WsPickAll)
IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF

stat= SetInputFormat("n4","")
Stat= DeleteEntityList(Group,Pm,Pref,Pdest,Axis_line)

IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
