
! script name: 3dcpaths.d/colorvisible
! 3dtopic: color surfaces which are visible

!A
!A NAME:
!A
!A 	Color Visible
!A
!A DESCRIPTION:
!A
!A 	This script will color surfaces which are "visible" relative
!A 	to the direction line. The Direction line points toward 
!A 	the direction the part is being seen from, (away from the part).
!A
!A 	For example, to find the surfaces visible from the top, the 
!A 	direction line should point toward positive z.
!A
!A 	Points on each surface are checked to see if any other surface 
!A 	selected lies above the check points in z.
!A
!B INSTRUCTIONS:
!B
!B 	PICK DIRECTION LINE, Z+ : Pick the direction line.
!B
!C NOTE:
!C
!C 	This script is designed for use on iges files where both inside
!C 	and outside surfaces are included. Surfaces are selected if they
!C 	are "visible" relative to the workplane. This allows the user to
!C 	color or layer the surfaces relative to their visibility.
!C
!C 	This script does not split surfaces. A surface which is partially
!C 	hidden may or may not be selected.
!C
!C 	This script has the following operating characteristics:
!C
!C 	Vertical surfaces or surfaces close to vertical may or may not
!C 	be included.
!C
!C 	The default number of points tested on each surface is three.
!C 	Testing more points may be accomplished by changing the script
!C 	this is not recommended.
!C
!C 	The accuracy of the calculation is controlled by the
!C 	3D Cutting Tol variable.  Little will be gained by deviating from
!C 	the default tolerance except in the case of very small parts.
!C
!C 	Gaps or holes in the group of surfaces selected will allow incorrect
!C 	surfaces to be selected.
!C
!C 	Surfaces which are visible but have invisible portions 	may or may
!C 	not be selected.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: color visible surfaces ")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface_dir$[256]
DIM Name$[256]

DeActivateUndo
Highlight_color= 4
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Tol=NamedVarVal("3D Cutting Tol",Ws3DSystemVars,0.005)
Normal_len=NamedVarVal("3D Normal Length",Ws3DSystemVars,1.0)

Pen_color= CurrentColor
RaiseColorBox
Work=CurrentWorkplane
IF ValidGeometry(Work) THEN Active_workplane=1

Start:!

Part_group=CreateGroup("TEMPGROUP",WsSurfaceGroup)

Pick_loop:!
Stat=SetInputFormat("n4","")

Vnum= LastPickView
Stat=SetPickMask(WsPickSurfOnly)
Stat=PickBox(Part_group,Vnum,WsPickPen)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Part_group) THEN Pick_loop
LowerColorBox

Axis_line:!
Stat=SetPickMask(WsPickAll)
Stat=SetInputFormat("a1=",",Z,")
Stat=SetEqualsValue(0,"Z")
Axis_line=PickEntity("PICK DIRECTION LINE, Z+  ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "Z" THEN
	StdWorkplane
        Group= SurfVisibilityGrp(0,Part_group,Part_group,Tol)
        Stat=SetColor(Group)
        Stat= SetLineType(Group,Line_type)
ELSE
	IF NOT ValidGeometry(Axis_line) THEN Axis_line
	Etype= EntityType(Axis_line)
	IF Etype <> WsLineEnt THEN Axis_line
	StdWorkplane
	T= LastPickPara
	IF T <= 0.5 THEN
       		Axis_vector= LineVector(Axis_line)
	ELSE
        	P1= LineVector(Axis_line)
        	Axis_vector= ScaleVector(P1,-1)
        	Stat= DeleteEntity(P1)
	END IF
        Group= SurfVisibilityGrp(Axis_vector,Part_group,Part_group,Tol)
        Stat=SetColor(Group)
        Stat= SetLineType(Group,Line_type)

END IF
Stat= DeleteEntity(Axis_vector)
Stat= DeleteEntity(Part_group)
Stat= DeleteEntity(Group)

Leave:!
IF Active_workplane THEN
	Stat=SetWorkplane(Work)
ELSE
	StdWorkplane
END IF
Stat= SetCurrentColor(Pen_color)
LowerColorBox
Stat=SetPickMask(WsPickGeometry)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
