
! script name: drawings.d/ chviewlayers
! topic: change drawing view visible layers

!A
!A NAME:
!A
!A 	Change Drawing View Visible Layers
!A
!A DESCRIPTION:
!A
!A 	This script changes the layers visible on a drawing view.
!A
!B INSTRUCTIONS:
!B
!B      DRAWING NAME: Enter the drawing name.
!B
!B      VIEW NUMBER, Pick  : Enter the view number or select P to pick a view.
!B
!B      LAYERS VISIBLE ON VIEW #: Enter the individual layers to be
!B              visible on this view or enter "A" for all layers.
!B
!C NOTE:
!C
!C      The layers specified here are for visibility purposes only.
!C      Only geometry with these layers will be drawn associated
!C      with this view.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: change view layers ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Layers$[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

Stat=SetInputFormat("a99",",A,N,",WsFalse)
Stat=GetValue("LAYERS VISIBLE ON VIEW #"&VAL$(View_num)&" , All ,",Layers$)
IF (ExitScript(Destination$)) THEN Leave
IF Layers$="CANCEL" THEN Leave
IF Layers$="A" OR Layers$="a" THEN Layers$=""
IF Layers$="All" OR Layers$="all" THEN Layers$=""
IF LEN(Layers$) THEN Layers$= ","&Layers$&","


Stat= ChDrwgViewLayers(Drawing,View_num,Layers$)
Stat= PlotDrawing(Drawing,1,WsFalse)
Stat= SetActiveDrawing(Drawing)


GOTO View_loop

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