
! script name: trim.d/globalfillet
! topic: Sample - construct all trim corner fillets

!A
!A NAME:
!A
!A 	Global Fillet Routine
!A
!A DESCRIPTION:
!A
!A	This is a global function to do three types of fillets between two
!A	elements.  The types are based on how many of the elements will be
!A	trimmed. 
!A
!A~ image location - images/cornerfillet.jpg
!A	Both - The two elements picked will be trimmed to the ends of the arc.
!A	Single - The first element picked will be trimmed to the end of the
!A	         arc and the second element will not be trimmed.
!A	None- Both elements will remain as they are and the arc will be added.
!A
!A 	This script assumes that once the fillet radius has been defined.
!A	All subsequent radii will be the same until Radius is chosen.
!A
!B INSTRUCTIONS:
!B
!B 	FILLET RADIUS: Enter the radius of the arc that should be constructed
!B 		tangent to each element picked.
!B
!B	PICK FIRST ELEMENT. Single, Both, Chamfer: 
!B	PICK ELEMENT TO BE TRIMMED. None, Both, Chamfer:
!B	PICK ELEMENT TO BE TRIMMED. None, Single, Chamfer:
!B		Choose the first element tangent to the arc of the fillet.
!B		There are three options: Both - Trim both elements
!B		                       Single - Trim the first element picked
!B		                         None - Trim no elements
!B
!B	PICK SECOND ELEMENT: Pick the other element that should be tangent
!B		to the arc constructed.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: global fillet routine ")

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

DEG
ActivateUndo
Num_trims= 2
IF ARGC>=2 THEN Num_trims= VAL(ARGV(1))
Radius=NamedVarVal("fillet radius",WsSystemVars,0.25)
Ask_radius=NamedVarVal("ask fillet radius",WsSystemVars,0.0)

IF NOT Ask_radius THEN Ploop
Ask_radius:!
Stat= SetInputFormat("n4=","")
Radius=InputRadius("FILLET RADIUS")
IF (ExitScript(Destination$)) THEN Leave

Ploop:!
Stat=DynLabel("Radius:"&VAL$(Radius))
Stat= SetInputFormat("a1=",",N,R,B,S,")
SELECT Num_trims
CASE 0
Stat= SetEqualsValue(0,"B")
E1=PickEntity("PICK FIRST ELEMENT. Single, Both, Radius",Answer$)
CASE 1
Stat= SetEqualsValue(0,"B")
E1=PickEntity("PICK ELEMENT TO BE TRIMMED. None, Both, Radius",Answer$)
CASE 2
Stat= SetEqualsValue(0,"S")
E1=PickEntity("PICK ELEMENT TO BE TRIMMED. None, Single, Radius",Answer$)
END SELECT
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "R" THEN Ask_radius
IF Answer$= "B" OR Answer$= "S" OR Answer$= "N" THEN
	Num_trims= (Answer$="S")+2*(Answer$="B")
	GOTO Ploop
END IF
Para1=LastPickPara

Stat= SetInputFormat("n4","")
E2=PickEntity("PICK SECOND ELEMENT ")
IF (ExitScript(Destination$)) THEN Leave
Para2=LastPickPara

SELECT Num_trims
CASE 0
        trim_sw= WsTrimFillet
CASE 1
        trim_sw= WsTrimFirst
CASE 2
        trim_sw= WsTrimmed
END SELECT

ActivateUndo
Stat= AdvanceUndoNumber("fillet")
Stat= AddItemToUndo(WsUBModifyMode,E1)
Stat= AddItemToUndo(WsUBModifyMode,E2)

Radius= DynBufferValue(0,Radius)
C1= PickFillet(Radius,E1,Para1,E2,Para2,Trim_sw)

Stat= PlotEntity(E1)
Stat= PlotEntity(E2)
Stat= PlotEntity(C1)
Stat= AddItemToUndo(WsUBCreateMode,C1)
Stat= SetRadiusEquals(Radius)
Vrad=CreateVariable("fillet radius",WsSystemVars,Radius)
GOTO Ploop

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