
! script name: drawings.d/ drwgviewonoff
! topic: turn drawing view on/off 

!A
!A NAME:
!A
!A 	View On/Off
!A
!A DESCRIPTION:
!A
!A 	Turn on/off 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
!B 		or select P to pick the view. Warning picking may be
!B 		difficult especially on an iges drawing.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: turn drawing view on/off ")

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= DrawingViewOff(Drawing,View_num)
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
