
! script name: datatable.d/boxcopy
! topic: copy table elements

!A
!A NAME:
!A
!A 	Copy Entries
!A
!A DESCRIPTION:
!A
!A 	Copy table elements in a box.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ORIGIN TABLE: Pick the source table.
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick window view for selection.
!B
!B 	PICK DESTINATION ENTRY: This is the starting point for the copy's
!B 		destination.	
!B
!B NOTES:
!B
!B 	The origin table and the destination table may be the same.
!B 	In this case the copied data must not overlap.
!B
!B 	Make sure the selection box is contained within the
!B 	table. Selecting outside the table will cancel the
!B 	command.
!B
!B 	When tables are used in variational design the variational
!B 	attachments are not copied.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: Box copy entries ")

DIM Answer$[256]
DIM A$[256]
DIM Destination$[256]
DEG

ActivateUndo
Highlight_pen=2
Start:!

Element_loop:!
N1= DataTableCount
IF N1=0 THEN Leave
IF N1 > 1 THEN
Pick_table:stat= SetInputFormat("n4","")
        Table1=PickEntity("PICK ORIGIN TABLE")
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT  ValidGeometry(Table1) THEN Pick_table
ELSE
        Table1= DataTableByNumber(1)
        IF NOT  ValidGeometry(Table1) THEN Pick_table
END IF


Pick_loop:!
Vnum= LastPickView
L1=WorkplaneBox(Vnum)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(L1) THEN Pick_loop

Len1= LineLength(L1)
IF Len1< 0.0001 THEN
        Stat= DeleteEntity(L1)
        GOTO Start
END IF

Pt1= ParameterPt(L1,0.0)
T1= ParameterInTable(Table1,Pt1)
Stat= DeleteEntity(Pt1)
IF T1 <= 0 THEN Pick_loop
R1=TableParaRow(Table1,T1)
C1=TableParaColumn(Table1,T1)

Pt2= ParameterPt(L1,1.0)
T2= ParameterInTable(Table1,Pt2)
Stat= DeleteEntity(Pt2)
Stat= DeleteEntity(L1)
IF T2 <= 0 THEN Pick_loop
R2=TableParaRow(Table1,T2)
C2=TableParaColumn(Table1,T2)
Stat= DeleteEntity(Pt1)
Stat= DeleteEntity(Pt2)
Stat= DeleteEntity(L1)

Stat= PlotDataTable(Table1,R1,C1,R2,C2,Highlight_pen)


Pick_dest:!
stat= SetInputFormat("n4","")
Table2=PickEntity("PICK DESTINATION ENTRY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Table2) THEN Pick_dest
T1= LastPickPara

R3=TableParaRow(Table2,T1)
C3=TableParaColumn(Table2,T1)

ActivateUndo
Stat= AdvanceUndoNumber("copy entries")
Stat= AddItemToUndo(WsUBModifyMode,Table2)

Stat= EraseEntity(Table2)
Stat= CopyTableRows(Table1,Table2,R1,C1,R2,C2,R3,C3)
Stat= PlotEntity(Table2)
Stat= PlotDataTable(Table1,R1,C1,R2,C2,0)

GOTO Start

Leave:!
Stat= DeleteEntity(Pt1)
Stat= DeleteEntity(Pt2)
Stat= DeleteEntity(L1)
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
