
! script name: featureitems.d/faceworkplane
! topic: Face item workplane

!A
!A NAME:
!A
!A	Face item workplane
!A
!A DESCRIPTION:
!A	
!A	This script sets the workplane based on the face item of
!A	a picked entity.
!A
!B INSTRUCTIONS:
!B
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: face item workplane ")

DIM Destination$[512]
DIM Answer$[512]
DIM Name$[512]
DIM Class_name$[512]
DIM Plane_class$[512]
DIM Face_name$[512]


DeActivateUndo

Class_name$="Planar Face Item"
Plane_class$="Face Plane Property"

Start:!

Pick_entity:!
Stat= SetInputFormat("n4","")
E1=PickEntity("PICK ENTITY")
IF ExitScript(Destination$) THEN Leave

Face_item= EntityItemByClass(E1,Class_name$)
IF NOT ValidGeometry(Face_item) THEN Start
Face_name$= UserDataStr(Face_item,"Name:")


Face_group= ItemGroup(Face_item)
G1= GrpByPropClass(Face_group,Plane_class$)
E1= GroupElement(G1,1)
Stat= SetWorkplane(E1)
Stat= DeleteEntity(G1)
Stat= DeleteEntity(Face_group)

GOTO Start

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