! script name: contrib/ascript/tsm.d/ rotateview
! topic: rotate a drawing view;
! Version_270423.a

!A
!A NAME:
!A
!A      Rotate Drawing View
!A
!A DESCRIPTION:
!A
!A      This script will rotate a drawing view about its location point
!A      at an angle.
!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 rotated or
!B              select P to pick the view. Warning picking may be
!B              difficult especially on an iges drawing.
!B
!B      ROTATE ANGLE:  Input the rotation angle (+ CCW, -CW ).
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: rotate drawing view ")

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



DeActivateUndo
Draw_loop:! 

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

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


Stat=SetInputFormat("n4","")
Angle=InputAngle("ROTATE ANGLE (+ CCW, -CW )")
IF (ExitScript(Destination$)) THEN Leave


Stat= RotateDrawingView(Drawing,View_num,Angle)
Stat= PlotDrawing(Drawing,1,WsFalse)

GOTO View_loop

Leave:!
LowerSelectBox
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
        LOAD "typecontrol"
ELSE
        LOAD Destination$
END IF
END
