
! script name: v3dtrim.d/fasttrimsurf
! var_topic: fast trim surface

!A
!A NAME:
!A
!A 	Fast Trim Surface	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will trim one surface to another intersecting surface.
!A 	The pick location on the surface will determine which part is saved.
!A 	This feature applies to 3D surfaces only.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE #1: Pick the surface that will be trimmed
!B 		to the other surface.  Remember, pick location is important.
!B
!B 	PICK BOUNDING SURFACE: Pick the surface to be used as the
!B 		reference for the trim.  This surface will not be trimmed.
!B
!C NOTES:
!C
!C 	If the surfaces intersect along an edge, use trim surface to surface
!C 	edge.
!C
!C 	Intersections will fail if the two surfaces are tangent or approach
!C 	tangency.
!C
!C 	If a trimming operation is unsuccessful, a fragment of a bad trim curve
!C 	may be attached to the surface.  The fragment may or may not show up
!C 	and do what was desired.  To avoid unwanted data accumulation after
!C 	an unsuccessful trimming operation, use Untrim Surface and start the
!C 	trimming procedure over.  The Resolve Trim Curves may or may not
!C 	accomplish the desired results, it depends on the location of the
!C 	fragments.
!C
!C 	The "3D Trimming Tol" should be left at its default value unless
!C 	problems occur.  If a problem is encountered, then go to a
!C 	smaller tolerance.  If small parts are the normal, then consider
!C 	changing the default tolerance.  The tolerance may be edited
!C 	temporarily by selecting the Variables option in the Settings menu.
!C 	The default tolerance may be changed permanently by selecting
!C 	the Constants option in the Settings menu.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: fast trim surface ")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface_dir$[80]
DIM Name1$[256]
DIM Name2$[256]
DIM Name$[256]

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


ActivateUndo
Tol=NamedVarVal("3D Trimming Tol",Ws3DSystemVars,0.005)
Start:!

Intersect2:!

Pick_surf1:!
Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n0","")
Surface1=PickEntity("PICK SURFACE #1",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Surface1) THEN Pick_surf1
Stat= EntityNameCheck(Surface1,Name1$)
UVpoint1=LastUVSurfPick(Surface1)
IF NOT ValidGeometry(UVpoint1) THEN Pick_surf1

Pick_surf2:!
Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n0","")
Surface2=PickEntity("PICK BOUNDING SURFACE ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Surface2) THEN Pick_surf2
Stat= EntityNameCheck(Surface2,Name2$)
UVpoint2=LastUVSurfPick(Surface2)
IF NOT ValidGeometry(UVpoint2) THEN Pick_surf2

Stat=SetPickMask(WsPickGeometry)
Uvalue1=XPointValue(UVpoint1)
Vvalue1=YPointValue(UVpoint1)
Uvalue2=XPointValue(UVpoint2)
Vvalue2=YPointValue(UVpoint2)
Stat=DeleteEntity(UVpoint1)
Stat=DeleteEntity(UVpoint2)

Trim1= 1
Trim2= 0

ActivateUndo
Stat= AdvanceUndoNumber("trim surfaces")
Stat= AddItemToUndo(WsUBModifyMode,Name1$)
Stat= AddItemToUndo(WsUBModifyMode,Name2$)

RecordFunctionOn
Stat= RecordDescr("TRIM: Two Surfaces")
UVpoint1= PointXYZ(Uvalue1,Vvalue1,0)
UVpoint2= PointXYZ(Uvalue2,Vvalue2,0)
V1= FreeParameter("Tolerance",Tol)
stat= FastTrimTwoSurfs(Name1$,UVpoint1,Trim1,Name2$,UVpoint2,Trim2,V1)
Stat=DeleteEntityList(UVpoint1,UVpoint2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Intersect2

Leave:!
stat= SetInputFormat("n4","")
Stat= SetPickMask(WsPickGeometry)
stat= DeleteEntity(UVpoint1)
stat= DeleteEntity(UVpoint2)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
