
! script name: vpkattributes.d/vpklayerbody
! var_solids: assign layer to a solid body

!A
!A NAME:
!A
!A 	Layer Body  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a solid body to be assigned a layer. 
!A	Both faces and edges within the body are assigned the same layer.
!A
!B INSTRUCTIONS:
!B
!B 	PICK BODY TO BE LAYERED: Pick the body.
!B
!B NOTES:
!B 
!B	Show by layer will show only bodies on the selected layers. 
!B	Faces and edges may now be placed on layers. The standard show
!B	by layer will not separate faces and edges from a body.
!B
!# see also - htdocs/help.d/parasolids.htm


stat=ChangeLabelStr("ScriptNameStatus","Function: color solid body ")

DIM Destination$[256]
DIM Answer$[256]
DIM Body$[256]

ActivateUndo
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

Layer=CurrentLayer

Ask_layer=1
IF ARGC> 1 THEN Ask_layer=0

IF Ask_layer THEN
        Stat=SetInputFormat("n0=","")
        Stat= SetEqualsValue(Layer)
        Layer=InputLayer("LAYER NUMBER ")
        IF (ExitScript(Destination$)) THEN Leave
        Stat= SetCurrentLayer(Layer)
END IF

Stat= GLPlotOn
Pick_loop:!
Stat=SetInputFormat("n4","")
Layer=CurrentLayer

E1=WPKPickEntity("PICK BODY TO BE ASSIGNED LAYER  "&VAL$(Layer))
IF (ExitScript(Destination$)) THEN Leave

Pkbody= WPKParentBody(E1)
Stat= EntityNameCheck(Pkbody,Body$)
Layer=CurrentLayer

WPKClearErrorFlag
RecordFunctionOn
Stat= RecordDescr("BODY: layer")
V1= FreeParameter("Layer",Layer)
Stat= WPKLayerEntity(Body$,V1)
PlotOn
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord


Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("layer body")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck
GOTO Pick_loop

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