
! script name: drawings.d/ chdrawlayers
! topic: change associated drawing visible layers

!A
!A NAME:
!A
!A 	Change Associated Drawing Visible Layers
!A
!A DESCRIPTION:
!A
!A 	This script changes the visible layers associated to a drawing.
!A
!B INSTRUCTIONS:
!B
!B      DRAWING NAME: Enter the drawing name.
!B
!B      ASSOCIATED DRAWING LAYERS, All: Enter the individual layers to be
!B              visible on the drawing or enter "A" for all layers.
!B
!C NOTES:
!C
!C      The layers specified here are for visibility purposes only.
!C      Only geometry with these layers will be drawn associated
!C      with the drawing.
!C

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

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


DeActivateUndo
Draw_loop:! 
StdWorkplane

Drawing= ActiveDrawing
IF ValidGeometry(Drawing) THEN Drawing_layers

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


Drawing_layers:Stat=SetInputFormat("a99",",A,N,",WsFalse)
Stat=GetValue("ASSOCIATED DRAWING LAYERS, 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= SetDrawingLayers(Drawing,Layers$)
Stat= PlotDrawing(Drawing,1,WsFalse)
Stat= SetActiveDrawing(Drawing)

GOTO Leave

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