
! script name: drawings.d/ movedrwgview
! topic: move a drawing view

!A
!A NAME:
!A
!A 	Move View
!A
!A DESCRIPTION:
!A
!A 	This script moves a drawing view.
!A
!B INSTRUCTIONS:
!B
!B 	DRAWING NAME: Enter the name to be used for the drawing.
!B
!B      VIEW NUMBER, Pick: Either input the view to be turned on/off or select
!B                         P to pick the view. Warning picking may be difficult
!B                         especially on an iges drawing.
!B
!B 	INPUT X,Y: Enter the new X,Y location on the drawing.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: move view ")

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



DeActivateUndo
Draw_loop:! 
StdWorkplane

Drawing= ActiveDrawing
IF ValidGeometry(Drawing) THEN View_loop

Stat=UserSelectBox("DRAWINGS","selected drawing",WsDrawingSelect,WsDrawingSelect)
IF Stat=1 THEN Leave

Stat=SetInputFormat("a99","")
Stat=GetValue("DRAWING NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Leave
Name$=Answer$

LowerSelectBox
Drawing= FindNamedEntity(Name$)
IF ValidGeometry(Drawing) THEN
        StdWorkplane
        Stat= PlotDrawing(Drawing,1,WsTrue)
        Stat= SetActiveDrawing(Drawing)
ELSE
        StdWorkplane
        Stat= SetActiveDrawing
	GOTO Draw_loop
END IF
LowerSelectBox

View_loop:!
Nviews= NumberDrawingViews(drawing)
IF Nviews=0 THEN Leave
A$= "1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 "
IF Nviews< 15 THEN
        N1= 3*(Nviews-1)+1
        A$= A$[1,N1]
END IF

Stat= SetInputFormat("n0a1",",P,")
View_num=GetValue("VIEW NUMBER, Pick  "&A$,Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="P" THEN
	Stat= SetInputFormat("n4","")
	Pt=InputFreePoint("PICK WHICH VIEW")
	IF (ExitScript(Destination$)) THEN Leave
	IF NOT ValidGeometry(Pt) THEN View_loop

        View_num= FindClosestView(Drawing,Pt)
        Stat=DeleteEntity(Pt)
END IF
IF View_num< 1 THEN View_loop

Center= DrwgViewPosition(Drawing,View_num)

Stat=SetInputFormat("n4","")
Stat=SetXyzInput(WsXyzInput)
Stat=SetLastPoint(Center,WsXyzInput)
New_center=XyzInput("INPUT",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetLastPoint(New_center,WsXyzInput)

Stat= ChDrwgViewPos(Drawing,New_center,View_num)
Stat=DeleteEntity(Center)
Stat=DeleteEntity(New_center)
Stat= PlotDrawing(Drawing,1,WsFalse)
Stat= SetActiveDrawing(Drawing)


GOTO View_loop

Leave:!
LowerSelectBox
Stat= SetInputFormat("n4","")
Stat=DeleteEntity(Pt)
Stat=DeleteEntity(Center)
Stat=DeleteEntity(New_center)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
